Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: DATA declarations not aligned if HASHED|SORTED TABLE with compound key #129

@stockbal

Description

@stockbal

Hi,

I have an issue that DATA declarations that contain TABLE declarations with compound keys are not aligned correctly.

Unformatted Code

        data action_name                  TYPE string.
    DATA      tags_dac         TYPE REF TO zcl_abaptags_tags_dac.
    DATA new_tag_map            TYPE HASHED TABLE OF ty_tag_map WITH UNIQUE KEY tag_name owner.
            DATA tagged_objects       TYPE zabaptags_tagged_object_t.
        DATA tagged_objects_db        TYPE            zif_abaptags_ty_global=>ty_db_tagged_objects.

Rule Config for Align Declarations

    {
      "ruleID": "ALIGN_DECLARATIONS",
      "isActive": true,
      "settingCount": 10,
      "settings": {
        "CondenseInnerSpaces": "1",
        "AlignNonChainsAction": "2",
        "FillPercentageToJustifyOwnColumn": "20",
        "ExecuteOnClassDefinitionSections": "1",
        "StructureAlignStyle": "1",
        "AlignChainAction": "1",
        "AlignAcrossEmptyLines": "1",
        "AlignStructureAction": "1",
        "MaxLineLength": "130",
        "AlignAcrossCommentLines": "1"
      }
    }

Expectation

    DATA action_name TYPE string.
    DATA tags_dac TYPE REF TO zcl_abaptags_tags_dac.
    DATA new_tag_map TYPE HASHED TABLE OF ty_tag_map WITH UNIQUE KEY tag_name owner.
    DATA tagged_objects TYPE zabaptags_tagged_object_t.
    DATA tagged_objects_db TYPE zif_abaptags_ty_global=>ty_db_tagged_objects.

Actual Result

    DATA action_name                  TYPE string.
    DATA      tags_dac         TYPE REF TO zcl_abaptags_tags_dac.
    DATA new_tag_map            TYPE HASHED TABLE OF ty_tag_map WITH UNIQUE KEY tag_name owner.
    DATA tagged_objects       TYPE zabaptags_tagged_object_t.
    DATA tagged_objects_db        TYPE            zif_abaptags_ty_global=>ty_db_tagged_objects.

Conclusion

So, its not that nothing is done by ABAP cleaner, but the result is not satisfactory. However if I remove one key component from the table declaration line, or if I comment/remove the table declaration line, then I would get the expected result as seen above.

I traced the problem to the following code block:

while (typeEnd != null && !typeEnd.isAnyKeyword("LENGTH", "DECIMALS", "VALUE", "READ-ONLY") && !typeEnd.textEqualsAny(".", ",")) {
// do not align table declarations with "WITH ... KEY ..." sections, because they usually should not be put on a single line;
// however, do accept the short cases of "WITH EMPTY KEY" and "WITH [UNIQUE | NON-UNIQUE] DEFAULT KEY" and "WITH [UNIQUE | NON-UNIQUE] KEY comp1"
if (typeEnd.isKeyword("WITH")
&& !typeEnd.matchesOnSiblings(true, "WITH", "EMPTY", "KEY")
&& !typeEnd.matchesOnSiblings(true, "WITH", TokenSearch.makeOptional("UNIQUE|NON-UNIQUE"), "DEFAULT", "KEY")
&& !typeEnd.matchesOnSiblings(true, "WITH", TokenSearch.makeOptional("UNIQUE|NON-UNIQUE"), "KEY", TokenSearch.ANY_IDENTIFIER, ",|.")) {
return null;
}
typeEnd = typeEnd.getNextSibling();
}

Kind regards,
Ludwig

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions