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

CHECK_PREFER_IS_NOT: Exempt predicative method calls #599

Merged
17 changes: 14 additions & 3 deletions src/checks/y_check_prefer_is_not.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ CLASS y_check_prefer_is_not DEFINITION PUBLIC INHERITING FROM y_check_base CREAT
PROTECTED SECTION.
METHODS inspect_tokens REDEFINITION.

METHODS is_standard_function IMPORTING token TYPE stokesx
METHODS is_standard_function IMPORTING token TYPE stokesx
RETURNING VALUE(result) TYPE abap_bool.

METHODS is_predicative_method IMPORTING token TYPE stokesx
RETURNING VALUE(result) TYPE abap_bool.

ENDCLASS.


Expand Down Expand Up @@ -50,13 +53,18 @@ CLASS y_check_prefer_is_not IMPLEMENTATION.
ENDTRY.

TRY.
IF is_standard_function( ref_scan->tokens[ position + 2 ] ) = abap_true.
IF is_standard_function( ref_scan->tokens[ position + 2 ] ).
CONTINUE.
ENDIF.

IF is_predicative_method( ref_scan->tokens[ position + 2 ] ).
CONTINUE.
ENDIF.
CATCH cx_sy_itab_line_not_found.
CONTINUE.
ENDTRY.


DATA(check_configuration) = detect_check_configuration( statement ).

raise_error( statement_level = statement-level
Expand All @@ -74,5 +82,8 @@ CLASS y_check_prefer_is_not IMPLEMENTATION.
OR token-str CP 'MATCHES*' ).
ENDMETHOD.

METHOD is_predicative_method.
result = xsdbool( token-str CP '*(' ).
ENDMETHOD.
bjoern-jueliger-sap marked this conversation as resolved.
Show resolved Hide resolved

ENDCLASS.
ENDCLASS.
29 changes: 29 additions & 0 deletions src/checks/y_check_prefer_is_not.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,32 @@ CLASS ltc_contains_any_of IMPLEMENTATION.
ENDMETHOD.

ENDCLASS.

CLASS ltc_predicative_method DEFINITION INHERITING FROM ltc_not_value FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PROTECTED SECTION.
METHODS get_code_without_issue REDEFINITION.
ENDCLASS.

CLASS ltc_predicative_method IMPLEMENTATION.

METHOD get_code_without_issue.
result = VALUE #(
( 'REPORT y_example. ' )
( ' CLASS y_example_class DEFINITION. ' )
( ' PUBLIC SECTION. ' )
( ' METHODS is_active RETURNING VALUE(result) TYPE abap_bool. ' )
( ' ENDCLASS. ' )
( ' CLASS y_example_class IMPLEMENTATION. ' )
( ' METHOD is_active. ' )
( ' ENDMETHOD. ' )
( ' ENDCLASS. ' )
( ' START-OF-SELECTION. ' )
( ' DATA(count) = 0. ' )
( ' DATA(object) = NEW y_example_class( ). ' )
( ' IF NOT object->is_active( ).' )
( ' count = 1. ' )
( ' ENDIF. ' )
).
ENDMETHOD.

ENDCLASS.
Loading