Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Legend

2021-08-XX v.1.16.0
------------------
* Pseudo Comment Usage: Multiple Inline Entries (#494)
* Prefer Pragmas to Pseudo Comments: Multiple Pseudo Comments (#489)
* Y_CHECK_MESSAGE_EASY_TO_FIND dump (#492)
* Chain Declaration for Complex Structures (#488)
Expand Down
95 changes: 52 additions & 43 deletions src/checks/y_check_pseudo_comment_usage.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ CLASS y_check_pseudo_comment_usage DEFINITION PUBLIC INHERITING FROM y_check_bas
METHODS constructor.

PROTECTED SECTION.
METHODS inspect_structures REDEFINITION.
METHODS execute_check REDEFINITION.
METHODS inspect_tokens REDEFINITION.

PRIVATE SECTION.
CLASS-DATA pseudo_comments LIKE TABLE OF settings-pseudo_comment.
DATA pseudo_comment_counter TYPE i.
TYPES ty_pseudo_comments LIKE SORTED TABLE OF settings-pseudo_comment WITH NON-UNIQUE KEY table_line.
TYPES ty_string_table TYPE TABLE OF string.

METHODS get_pseudo_comments RETURNING VALUE(result) LIKE pseudo_comments.
METHODS count_pseudo_comments IMPORTING token TYPE stokesx.
METHODS check_result.
CLASS-DATA relevant_pseudo_comments TYPE ty_pseudo_comments.

DATA counter TYPE i.

METHODS get_relevant_pseudo_comments RETURNING VALUE(result) TYPE ty_pseudo_comments.

METHODS get_count IMPORTING pseudo_comments TYPE ty_string_table
RETURNING VALUE(result) TYPE i.

METHODS create_check IMPORTING name TYPE tadir-obj_name
RETURNING VALUE(result) TYPE REF TO y_check_base.
Expand Down Expand Up @@ -45,41 +50,69 @@ CLASS y_check_pseudo_comment_usage IMPLEMENTATION.
ENDMETHOD.


METHOD inspect_structures.
pseudo_comment_counter = 0.
METHOD execute_check.
CLEAR counter.

IF pseudo_comments IS INITIAL.
pseudo_comments = get_pseudo_comments( ).
super->execute_check( ).

IF counter = 0.
RETURN.
ENDIF.

super->inspect_structures( ).
DATA(statement) = ref_scan->statements[ 1 ].

check_result( ).
DATA(check_configuration) = detect_check_configuration( statement ).

raise_error( statement_level = statement-level
statement_index = statement-from
statement_from = statement-from
check_configuration = check_configuration
parameter_01 = |{ counter }| ).
ENDMETHOD.


METHOD inspect_tokens.
LOOP AT ref_scan->tokens ASSIGNING FIELD-SYMBOL(<token>)
LOOP AT ref_scan->tokens INTO token_wa
FROM statement-from TO statement-to
WHERE type = 'C'
OR type = 'P'.
count_pseudo_comments( <token> ).
WHERE type = scan_token_type-comment
AND str CS '#EC '.
REPLACE ALL OCCURRENCES OF `"#EC` IN token_wa-str WITH '#EC'.
REPLACE ALL OCCURRENCES OF `#EC ` IN token_wa-str WITH '#EC'.
SPLIT token_wa-str AT space INTO TABLE DATA(pseudo_comments).
counter = counter + get_count( pseudo_comments ).
ENDLOOP.
ENDMETHOD.


METHOD get_count.
IF relevant_pseudo_comments IS INITIAL.
relevant_pseudo_comments = get_relevant_pseudo_comments( ).
ENDIF.

LOOP AT pseudo_comments INTO DATA(pseudo_comment)
WHERE table_line CS '#EC'.
REPLACE ALL OCCURRENCES OF '#EC' IN pseudo_comment WITH ''.
IF line_exists( relevant_pseudo_comments[ table_line = pseudo_comment ] ).
result = result + 1.
ENDIF.
ENDLOOP.
ENDMETHOD.


METHOD get_pseudo_comments.
METHOD get_relevant_pseudo_comments.
LOOP AT y_profile_manager=>get_checks_from_db( ) ASSIGNING FIELD-SYMBOL(<check>)
WHERE object = 'CLAS'.
DATA(check) = create_check( <check>-obj_name ).
IF check->settings-ignore_pseudo_comments = abap_true.
CONTINUE.
ENDIF.
IF check->settings-pseudo_comment IS NOT INITIAL.
APPEND check->settings-pseudo_comment TO result.
REPLACE ALL OCCURRENCES OF `"#EC ` IN check->settings-pseudo_comment WITH ''.
INSERT check->settings-pseudo_comment INTO TABLE result.
ENDIF.
IF check->settings-alternative_pseudo_comment IS NOT INITIAL.
APPEND check->settings-alternative_pseudo_comment TO result.
REPLACE ALL OCCURRENCES OF `"#EC ` IN check->settings-alternative_pseudo_comment WITH ''.
INSERT check->settings-alternative_pseudo_comment INTO TABLE result.
ENDIF.
ENDLOOP.
ENDMETHOD.
Expand All @@ -90,28 +123,4 @@ CLASS y_check_pseudo_comment_usage IMPLEMENTATION.
ENDMETHOD.


METHOD count_pseudo_comments.
LOOP AT pseudo_comments ASSIGNING FIELD-SYMBOL(<pseudo_comment>).
IF token-str CS <pseudo_comment>.
pseudo_comment_counter = pseudo_comment_counter + 1.
ENDIF.
ENDLOOP.
ENDMETHOD.


METHOD check_result.
CHECK pseudo_comment_counter > 0.

DATA(statement) = ref_scan->statements[ 1 ].

DATA(check_configuration) = detect_check_configuration( statement ).

raise_error( statement_level = statement-level
statement_index = statement-from
statement_from = statement-from
check_configuration = check_configuration
parameter_01 = |{ pseudo_comment_counter }| ).
ENDMETHOD.


ENDCLASS.
44 changes: 44 additions & 0 deletions src/checks/y_check_pseudo_comment_usage.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ CLASS ltc_pseudo_comment IMPLEMENTATION.
ENDCLASS.



CLASS ltc_pragma DEFINITION INHERITING FROM ltc_pseudo_comment FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PROTECTED SECTION.
METHODS get_code_without_issue REDEFINITION.
Expand All @@ -59,6 +60,7 @@ CLASS ltc_pragma IMPLEMENTATION.
ENDCLASS.



CLASS ltc_alternative_pseudo_comment DEFINITION INHERITING FROM ltc_pseudo_comment FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PROTECTED SECTION.
METHODS get_code_with_issue REDEFINITION.
Expand All @@ -77,3 +79,45 @@ CLASS ltc_alternative_pseudo_comment IMPLEMENTATION.
ENDMETHOD.

ENDCLASS.



CLASS ltc_multiple_pseudo_comments DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PROTECTED SECTION.
METHODS get_cut REDEFINITION.
METHODS get_code_with_issue REDEFINITION.
METHODS get_code_without_issue REDEFINITION.
METHODS get_code_with_exemption REDEFINITION.
ENDCLASS.

CLASS ltc_multiple_pseudo_comments IMPLEMENTATION.

METHOD get_cut.
result ?= NEW y_check_pseudo_comment_usage( ).
ENDMETHOD.

METHOD get_code_with_issue.
result = VALUE #(
( 'REPORT y_example. ' )
( ' START-OF-SELECTION. ' )
( ' TRY. ' )
( ' CATCH cx_sy_arg_out_of_domain. "#EC EMPTY_CATCH #EC NO_HANDLER' )
( ' ENDTRY. ' )
).
ENDMETHOD.

METHOD get_code_without_issue.
result = VALUE #(
( 'REPORT y_example. ' )
( ' START-OF-SELECTION. ' )
( ' TRY. ' )
( ' CATCH cx_sy_arg_out_of_domain. "#EC NEEDED ' )
( ' ENDTRY. ' )
).
ENDMETHOD.

METHOD get_code_with_exemption.
result = VALUE #( ).
ENDMETHOD.

ENDCLASS.