Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alignment differences in pretty printer versus abap cleaner #9

Closed
fabianlupa opened this issue May 18, 2023 · 3 comments
Closed

Alignment differences in pretty printer versus abap cleaner #9

fabianlupa opened this issue May 18, 2023 · 3 comments
Assignees
Labels
bug Something isn't working new option

Comments

@fabianlupa
Copy link

Hi,

are you supposed to disable alignments by pretty printer if you use abap cleaner? They correct each other for me in the default settings. Or maybe the pretty printer was adjusted in a higher release so they are the same there?

Pretty Printer:

CLASS zabc_fs_method_enum DEFINITION
  PUBLIC
  FINAL
  CREATE PRIVATE.

  PUBLIC SECTION.
    TYPES instances TYPE SORTED TABLE OF REF TO zabc_fs_method_enum WITH UNIQUE KEY table_line.

    CLASS-DATA:
      file_exists            TYPE REF TO zabc_fs_method_enum READ-ONLY,
      read_file_bin          TYPE REF TO zabc_fs_method_enum READ-ONLY,
      read_file_text         TYPE REF TO zabc_fs_method_enum READ-ONLY,
      write_file_bin         TYPE REF TO zabc_fs_method_enum READ-ONLY,
      get_directory_contents TYPE REF TO zabc_fs_method_enum READ-ONLY,
      create_directory       TYPE REF TO zabc_fs_method_enum READ-ONLY,
      delete_directory       TYPE REF TO zabc_fs_method_enum READ-ONLY,
      get_default_codepage   TYPE REF TO zabc_fs_method_enum READ-ONLY,
      get_separator          TYPE REF TO zabc_fs_method_enum READ-ONLY,
      get_connection_info    TYPE REF TO zabc_fs_method_enum READ-ONLY,
      BEGIN OF partial_reader READ-ONLY,
        read_file_to_buffer_bin  TYPE REF TO zabc_fs_method_enum,
        read_file_to_buffer_text TYPE REF TO zabc_fs_method_enum,
      END OF partial_reader,
      BEGIN OF partial_writer READ-ONLY,
        write_buffer_to_file_bin  TYPE REF TO zabc_fs_method_enum,
        write_buffer_to_file_text TYPE REF TO zabc_fs_method_enum,
      END OF partial_writer.

    DATA value TYPE abap_methname READ-ONLY.

    CLASS-METHODS class_constructor.
    CLASS-METHODS get_instances RETURNING VALUE(result) TYPE instances.

  PROTECTED SECTION.
  PRIVATE SECTION.
    CLASS-DATA:
      enum_instances TYPE instances.
    METHODS:
      constructor IMPORTING method_name TYPE abap_methname.
ENDCLASS.

ABAP Cleaner

CLASS zabc_fs_method_enum DEFINITION
  PUBLIC
  FINAL
  CREATE PRIVATE.

  PUBLIC SECTION.
    TYPES instances TYPE SORTED TABLE OF REF TO zabc_fs_method_enum WITH UNIQUE KEY table_line.

    CLASS-DATA:
      file_exists                 TYPE REF TO zabc_fs_method_enum READ-ONLY,
      read_file_bin               TYPE REF TO zabc_fs_method_enum READ-ONLY,
      read_file_text              TYPE REF TO zabc_fs_method_enum READ-ONLY,
      write_file_bin              TYPE REF TO zabc_fs_method_enum READ-ONLY,
      get_directory_contents      TYPE REF TO zabc_fs_method_enum READ-ONLY,
      create_directory            TYPE REF TO zabc_fs_method_enum READ-ONLY,
      delete_directory            TYPE REF TO zabc_fs_method_enum READ-ONLY,
      get_default_codepage        TYPE REF TO zabc_fs_method_enum READ-ONLY,
      get_separator               TYPE REF TO zabc_fs_method_enum READ-ONLY,
      get_connection_info         TYPE REF TO zabc_fs_method_enum READ-ONLY,
      BEGIN OF partial_reader READ-ONLY,
        read_file_to_buffer_bin   TYPE REF TO zabc_fs_method_enum,
        read_file_to_buffer_text  TYPE REF TO zabc_fs_method_enum,
      END OF partial_reader,
      BEGIN OF partial_writer READ-ONLY,
        write_buffer_to_file_bin  TYPE REF TO zabc_fs_method_enum,
        write_buffer_to_file_text TYPE REF TO zabc_fs_method_enum,
      END OF partial_writer.

    DATA value TYPE abap_methname READ-ONLY.

    CLASS-METHODS class_constructor.
    CLASS-METHODS get_instances RETURNING VALUE(result) TYPE instances.

  PROTECTED SECTION.
  PRIVATE SECTION.
    CLASS-DATA:
      enum_instances TYPE instances.
    METHODS:
      constructor IMPORTING method_name TYPE abap_methname.
ENDCLASS.
jmgrassau added a commit to jmgrassau/abap-cleaner that referenced this issue May 21, 2023
@jmgrassau
Copy link
Member

Hi Fabian,

thanks for reporting this issue – this should be fixed in the next release (version 1.2), meaning that alignment of "normal" variables (in your example, FILE_EXISTS, READ_FILE_BIN, …, GET_CONNECTION_INFO) will be independent from alignment of structures.

In case of nested structures, I actually added a new option to the "Align declarations" rule:

image

As you will see in the example for this rule, this will produce

a) align outer structure with inner
image

b) align outer structure independently (like Pretty Printer)
image

c) align each section independently
image

Option b) would be the new default to avoid inconsistencies with what Pretty Printer does.

However, generally speaking, ABAP cleaner pretty much covers the current scope of Pretty Printer (or rather, ABAP Formatter), so my typical sequence of shortcuts has actually changed from "Shift+F1 – Ctrl+F2 – Ctlr+F3" into "Ctrl+4 – Ctrl+F2 – Ctlr+F3", meaning that I hardly use the Pretty Printer anymore (in fact, Ctrl+4 was selected as a shortcut to make this a convenient sequence).

In a few cases, ABAP cleaner even intentionally deviates from Pretty Printer behavior, esp. in the "Indent lines" rule: Since comments are supposed to refer to the code below (not above) them, IMHO, ABAP cleaner alignment is better in cases such as:

image

Kind regards,
Jörg-Michael

@fabianlupa
Copy link
Author

Thanks for the response and the details! I agree I am much more content with the formatting done by ABAP Cleaner, especially since ABAP Formatter is dependent on the backend release and offers very little customization. I'll try retraining my muscle memory ;)

@ConjuringCoffee
Copy link
Contributor

If you want to avoid retraining your muscle memory, you can just change the key bindings in the Eclipse properties 😉

Properties > General > Keys

@jmgrassau jmgrassau self-assigned this Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new option
Projects
None yet
Development

No branches or pull requests

3 participants