Skip to content

Adding spaces before/after string literals- everywhere #143

Closed

Description

@csopaki

Hello Colleagues,

I use the ABAP Cleaner daily, and set the automatic adding of spaces between character literals and parentheses.
There are though some other places, where it might be very handy to add spaces around the character literals:

  • declarative statements (e.g. in class header - DATA, TYPES, ...)
  • value assignments (standalone or in VALUE #(...) statement, if you have multiple fields within the parentheses.

Code snippet:

CLASS myClass DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
  PROTECTED SECTION.
  PRIVATE SECTION.
    METHODS: myMethod.

    CONSTANTS: myconstant TYPE string VALUE'xyz'. " <<<=== declaration
ENDCLASS.


CLASS myClass IMPLEMENTATION.
  METHOD mymethod.    
    DATA mytext TYPE string VALUE'cde'. "<<<=== declaration

    DATA: somevariable TYPE string,
          BEGIN OF somedata,
            text   TYPE string,
            number TYPE i,
          END OF somedata,
          sometexts TYPE STANDARD TABLE OF string.

    somedata = VALUE #( text ='hsdfsd' number = 10 ). " <<<=== string literal in VALUE statement
    somevariable ='abc'. " <<<=== standalone string literal
  ENDMETHOD.

ENDCLASS.

Thanks a lot in advance, nice work you do with the tool, I like it very much!

Activity

  1. jmgrassau commented on Oct 13, 2023

    @jmgrassau
    Member

    Hi Csopaki,

    thanks, great idea! Actually I think the cleanup rule "Standardize spaces next to parentheses" should be renamed to "Put spaces around string literals", because most of it is really about string literals, and the option "Remove multiple spaces from empty parentheses" could easily be handled by the rule "Remove needless spaces".

    Based on your examples, here are all cases that I found – they create warnings and even some red color in ADT, but are no syntax errors:

    image

    So you could say, you always want spaces around string literals, except before the three operators : , . and except in cases where introducing a space would lead to a syntax error:

        " dynamic method calls 
        CALL METHOD lo_instance->('METHOD_NAME').
        CALL METHOD ('CLASS_NAME')=>('METHOD_NAME').
    
        " dynamic targets of component selectors
        ls_struc-('COMPONENT_NAME') = 1.
        lr_data_ref->('COMPONENT_NAME') = 1.
    
        " typed literals in ABAP SQL
        UPDATE demo_ddic_types
          SET int1 = int1`255`,
              int2 = int2`32767`,
              int4 = int4`2147483647`,
          WHERE id = char`Y`.

    Hope I didn't miss anything?

    Kind regards,
    Jörg-Michael

  2. self-assigned this
    on Oct 31, 2023
  3. jmgrassau commented on Nov 1, 2023

    @jmgrassau
    Member

    Hi Csopaki,

    thanks a lot for opening this issue! I just released version 1.10.0 with the following changes:

    • the option "Remove multiple spaces from empty parentheses" was moved to the cleanup rule "Remove needless spaces" (where it is activated if it was activated before)
    • the cleanup rule "Standardize spaces next to parentheses" was renamed to "Put spaces around string literals", because that's what it now focuses on
    • the following three options (highlighted in green) were added:
      image

    Adding to the existing options, this now also cares for cases like these – some of which are marked as erroneous with red text color in ADT and create ATC findings, but could nevertheless be compiled:
    image

    Kind regards,
    Jörg-Michael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions