abap-cleaner
abap-cleaner copied to clipboard
"Align parameters and components": Consistent line breaks in nested VALUEs
This is a follow-up to #53.
Here's an example:
CLASS lcl_example DEFINITION CREATE PUBLIC.
PUBLIC SECTION.
PROTECTED SECTION.
PRIVATE SECTION.
DATA:
BEGIN OF variable,
field_1 TYPE bapiret2,
field_2 TYPE bapiret2,
field_3 TYPE bapiret2,
field_4 TYPE bapiret2,
field_5 TYPE bapiret2,
END OF variable.
METHODS example.
ENDCLASS.
CLASS lcl_example IMPLEMENTATION.
METHOD example.
variable = VALUE #( field_1 = VALUE #(
number = '001'
message_v1 = '1'
message = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1' )
field_2 = VALUE #( number = '002'
message_v1 = '2'
message = '2' )
field_3 = VALUE #(
number = '003'
message_v1 = '3'
message = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa3' )
field_4 = VALUE #( number = '004'
message_v4 = '4'
message = '4' )
field_5 = VALUE #(
number = '005'
message_v4 = '5'
message = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa5' ) ).
ENDMETHOD.
ENDCLASS.
Everything works as designed: The constructor expression for field_2
starts on the same line because the content in message
is short enough. I'd like to see an option to keep the style of line-breaks consistent. If it there is a line-break for one of the fields, then there should be a line-break for all of the fields. Here's what I would expect:
METHOD example.
variable = VALUE #( field_1 = VALUE #(
number = '001'
message_v1 = '1'
message = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1' )
field_2 = VALUE #(
number = '002'
message_v1 = '2'
message = '2' )
field_3 = VALUE #(
number = '003'
message_v1 = '3'
message = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa3' )
field_4 = VALUE #(
number = '004'
message_v4 = '4'
message = '4' )
field_5 = VALUE #(
number = '005'
message_v4 = '5'
message = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa5' ) ).
ENDMETHOD.
This might fall in the same category of this example from Jörg-Michael in #53:
P.S.: A non-ideal (but nevertheless correct) result is e.g. produced at maximum 86, where the additional ")." of the second inner VALUE constructor makes the difference:
rs_result = VALUE #( comp_1 = VALUE #( num = '001' text = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1' ) comp_2 = VALUE #( num = '002' text = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2' ) ).
Hi ConjuringCoffee,
hm, will have to think about this a bit. I surely agree in this example that the uniform solution looks better, but frequently, the length of such inner VALUE statements can be quite different, so you could certainly find examples where it would be a pity to introduce line breaks everywhere just for the sake of one overlength instance.
So (once again with ABAP cleaner) the question would be: Exactly why would a human being introduce line breaks everywhere in this case, but not in other cases, what exactly is the difference between the cases, and could we teach this difference to a machine (with reasonable effort)? …
Kind regards, Jörg-Michael
Let's take another example:
rs_result = VALUE #(
comp_1 = VALUE #( some_field = '0a01'
something = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1' )
comp_2 = VALUE #(
example = 'b'
very_long_field = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2' ) ).
This example feels much better than the other one even though it is not uniform. I think that's because comp_1
and comp_2
have different field names (and therefore describe different entities). In my previous examples that felt "wrong" they had the same data type.
Of course, in most cases the data type is not defined in the same code document, so the ABAP cleaner has no access to that information. Maybe it could check for similarity of the fields to decide what to do instead?