Skip to content

Latest commit

 

History

History
132 lines (105 loc) · 4.78 KB

AlignMethodsDeclarationRule.md

File metadata and controls

132 lines (105 loc) · 4.78 KB

<-- previous rule | overview | next rule -->

Align METHODS declarations

Aligns METHODS and CLASS-METHODS declarations.

Options

  • Continue line after [CLASS-]METHODS [keep as is]
  • Continue line after method name [keep as is]
  • Continue line after IMPORTING etc. [always]
  • Fill ratio to justify own column for DEFAULT / OPTIONAL [40] %
  • Handling of (potential) one-liners [keep existing]
  • Align consecutive declarations [one-liners]
  • Align across empty lines
  • Align across comment lines
  • Separate multi-line declarations with empty lines

Examples

CLASS cl_any_class DEFINITION FINAL.
  PUBLIC SECTION.
    CLASS-METHODS any_method
      IMPORTING
        !iv_any_param TYPE i OPTIONAL
        !iv_other_param TYPE string DEFAULT 'abc'
      EXPORTING
        !ev_any_result TYPE i
        !ev_other_result TYPE string
      RAISING
        !cx_any_exception.

    METHODS other_method IMPORTING !iv_any_param TYPE i OPTIONAL
                                   !iv_other_param TYPE string DEFAULT 'abc'
                         EXPORTING !ev_any_result TYPE i
                                   !ev_other_result TYPE string
                         RAISING !cx_any_exception.

    METHODS set_value IMPORTING !iv_new_value TYPE i.
    METHODS get_current_value RETURNING VALUE(rv_result) TYPE i.
    METHODS get_previous_value RETURNING VALUE(rv_result) TYPE i.
    METHODS third_method_with_long_name IMPORTING iv_any_param_with_long_name TYPE i
                         EXPORTING ev_any_result TYPE i
                         CHANGING ets_any_table_with_long_name TYPE ty_ts_table
                         RAISING cx_any_exception.

    METHODS get_max_value
      RETURNING
        VALUE(rv_result) TYPE i.

    METHODS:
      any_chained_method
        IMPORTING
          !iv_any_param TYPE i OPTIONAL
          !iv_other_param TYPE string DEFAULT 'abc'
        RAISING
          !cx_any_exception,
      other_chained_method
        IMPORTING
          !it_source_table TYPE ty_tt_any OPTIONAL
          !iv_name TYPE string
        CHANGING
          !cts_result_table TYPE ty_ts_any.

    METHODS: set_value_chained IMPORTING !iv_new_value TYPE i,
      get_current_value_chained RETURNING VALUE(rv_result) TYPE i,
      get_previous_value_chained RETURNING VALUE(rv_result) TYPE i,
      get_max_value_chained
        RETURNING
          VALUE(rv_result) TYPE i.
ENDCLASS.

Resulting code:

CLASS cl_any_class DEFINITION FINAL.
  PUBLIC SECTION.
    CLASS-METHODS any_method
      IMPORTING !iv_any_param    TYPE i      OPTIONAL
                !iv_other_param  TYPE string DEFAULT 'abc'
      EXPORTING !ev_any_result   TYPE i
                !ev_other_result TYPE string
      RAISING   !cx_any_exception.

    METHODS other_method IMPORTING !iv_any_param    TYPE i      OPTIONAL
                                   !iv_other_param  TYPE string DEFAULT 'abc'
                         EXPORTING !ev_any_result   TYPE i
                                   !ev_other_result TYPE string
                         RAISING   !cx_any_exception.

    METHODS set_value          IMPORTING !iv_new_value    TYPE i.
    METHODS get_current_value  RETURNING VALUE(rv_result) TYPE i.
    METHODS get_previous_value RETURNING VALUE(rv_result) TYPE i.

    METHODS third_method_with_long_name IMPORTING iv_any_param_with_long_name  TYPE i
                                        EXPORTING ev_any_result                TYPE i
                                        CHANGING  ets_any_table_with_long_name TYPE ty_ts_table
                                        RAISING   cx_any_exception.

    METHODS get_max_value
      RETURNING VALUE(rv_result) TYPE i.

    METHODS:
      any_chained_method
        IMPORTING !iv_any_param   TYPE i      OPTIONAL
                  !iv_other_param TYPE string DEFAULT 'abc'
        RAISING   !cx_any_exception,

      other_chained_method
        IMPORTING !it_source_table  TYPE ty_tt_any OPTIONAL
                  !iv_name          TYPE string
        CHANGING  !cts_result_table TYPE ty_ts_any.

    METHODS: set_value_chained          IMPORTING !iv_new_value    TYPE i,
             get_current_value_chained  RETURNING VALUE(rv_result) TYPE i,
             get_previous_value_chained RETURNING VALUE(rv_result) TYPE i,

      get_max_value_chained
        RETURNING VALUE(rv_result) TYPE i.
ENDCLASS.

Related code