<-- previous rule | overview | next rule -->
Removes the self-reference me->.
Note that for attributes, me-> cannot be removed if ABAP cleaner cannot 'see' the method signature (e.g. for inherited or interface methods), because a parameter could have the same name.
This rule is part of the essential profile, as it is explicitly demanded by the Clean ABAP Styleguide.
- Clean ABAP Styleguide: Omit the self-reference me when calling an instance attribute or method
- Code Pal for ABAP: Self-Reference
- (no options available for this rule)
CLASS any_class DEFINITION.
PUBLIC SECTION.
METHODS remove_self_reference_me
EXPORTING ev_result TYPE x
ev_count TYPE y
ets_result TYPE z.
METHODS signature_out_of_sight REDEFINITION.
PRIVATE SECTION.
" DATA ...
ENDCLASS.
CLASS any_class IMPLEMENTATION.
METHOD remove_self_reference_me.
me->any_method( a = 5
b = 'abc' ).
ev_result = me->mv_value.
ev_count += me->get_count( ).
ets_result = VALUE #( ( line_id = 1 price = me->mv_price_1 )
( line_id = 2 price = me->create_price( iv_currency = me->get_currency( )
iv_amount = me->mv_amount ) ) ).
ENDMETHOD.
METHOD signature_out_of_sight.
" 'amount' and 'price' could be IMPORTING parameters, so me-> must NOT be removed
me->amount = me->price + 1.
ENDMETHOD.
ENDCLASS.
Resulting code:
CLASS any_class DEFINITION.
PUBLIC SECTION.
METHODS remove_self_reference_me
EXPORTING ev_result TYPE x
ev_count TYPE y
ets_result TYPE z.
METHODS signature_out_of_sight REDEFINITION.
PRIVATE SECTION.
" DATA ...
ENDCLASS.
CLASS any_class IMPLEMENTATION.
METHOD remove_self_reference_me.
any_method( a = 5
b = 'abc' ).
ev_result = mv_value.
ev_count += get_count( ).
ets_result = VALUE #( ( line_id = 1 price = mv_price_1 )
( line_id = 2 price = create_price( iv_currency = get_currency( )
iv_amount = mv_amount ) ) ).
ENDMETHOD.
METHOD signature_out_of_sight.
" 'amount' and 'price' could be IMPORTING parameters, so me-> must NOT be removed
me->amount = me->price + 1.
ENDMETHOD.
ENDCLASS.