Skip to content

Commit 6ba1cb6

Browse files
lucasborinLucas Borin
andauthored
Pseudo Comment Usage: Multiple Inline Entries (#496)
* fixes #494 * changelog Co-authored-by: Lucas Borin <5233413+lucasborin@users.noreply.github.co>
1 parent 5079483 commit 6ba1cb6

File tree

3 files changed

+97
-43
lines changed

3 files changed

+97
-43
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Legend
1818

1919
2021-08-XX v.1.16.0
2020
------------------
21+
* Pseudo Comment Usage: Multiple Inline Entries (#494)
2122
* Prefer Pragmas to Pseudo Comments: Multiple Pseudo Comments (#489)
2223
* Y_CHECK_MESSAGE_EASY_TO_FIND dump (#492)
2324
* Chain Declaration for Complex Structures (#488)

src/checks/y_check_pseudo_comment_usage.clas.abap

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ CLASS y_check_pseudo_comment_usage DEFINITION PUBLIC INHERITING FROM y_check_bas
33
METHODS constructor.
44

55
PROTECTED SECTION.
6-
METHODS inspect_structures REDEFINITION.
6+
METHODS execute_check REDEFINITION.
77
METHODS inspect_tokens REDEFINITION.
88

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

13-
METHODS get_pseudo_comments RETURNING VALUE(result) LIKE pseudo_comments.
14-
METHODS count_pseudo_comments IMPORTING token TYPE stokesx.
15-
METHODS check_result.
13+
CLASS-DATA relevant_pseudo_comments TYPE ty_pseudo_comments.
14+
15+
DATA counter TYPE i.
16+
17+
METHODS get_relevant_pseudo_comments RETURNING VALUE(result) TYPE ty_pseudo_comments.
18+
19+
METHODS get_count IMPORTING pseudo_comments TYPE ty_string_table
20+
RETURNING VALUE(result) TYPE i.
1621

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

4752

48-
METHOD inspect_structures.
49-
pseudo_comment_counter = 0.
53+
METHOD execute_check.
54+
CLEAR counter.
5055

51-
IF pseudo_comments IS INITIAL.
52-
pseudo_comments = get_pseudo_comments( ).
56+
super->execute_check( ).
57+
58+
IF counter = 0.
59+
RETURN.
5360
ENDIF.
5461

55-
super->inspect_structures( ).
62+
DATA(statement) = ref_scan->statements[ 1 ].
5663

57-
check_result( ).
64+
DATA(check_configuration) = detect_check_configuration( statement ).
65+
66+
raise_error( statement_level = statement-level
67+
statement_index = statement-from
68+
statement_from = statement-from
69+
check_configuration = check_configuration
70+
parameter_01 = |{ counter }| ).
5871
ENDMETHOD.
5972

6073

6174
METHOD inspect_tokens.
62-
LOOP AT ref_scan->tokens ASSIGNING FIELD-SYMBOL(<token>)
75+
LOOP AT ref_scan->tokens INTO token_wa
6376
FROM statement-from TO statement-to
64-
WHERE type = 'C'
65-
OR type = 'P'.
66-
count_pseudo_comments( <token> ).
77+
WHERE type = scan_token_type-comment
78+
AND str CS '#EC '.
79+
REPLACE ALL OCCURRENCES OF `"#EC` IN token_wa-str WITH '#EC'.
80+
REPLACE ALL OCCURRENCES OF `#EC ` IN token_wa-str WITH '#EC'.
81+
SPLIT token_wa-str AT space INTO TABLE DATA(pseudo_comments).
82+
counter = counter + get_count( pseudo_comments ).
83+
ENDLOOP.
84+
ENDMETHOD.
85+
86+
87+
METHOD get_count.
88+
IF relevant_pseudo_comments IS INITIAL.
89+
relevant_pseudo_comments = get_relevant_pseudo_comments( ).
90+
ENDIF.
91+
92+
LOOP AT pseudo_comments INTO DATA(pseudo_comment)
93+
WHERE table_line CS '#EC'.
94+
REPLACE ALL OCCURRENCES OF '#EC' IN pseudo_comment WITH ''.
95+
IF line_exists( relevant_pseudo_comments[ table_line = pseudo_comment ] ).
96+
result = result + 1.
97+
ENDIF.
6798
ENDLOOP.
6899
ENDMETHOD.
69100

70101

71-
METHOD get_pseudo_comments.
102+
METHOD get_relevant_pseudo_comments.
72103
LOOP AT y_profile_manager=>get_checks_from_db( ) ASSIGNING FIELD-SYMBOL(<check>)
73104
WHERE object = 'CLAS'.
74105
DATA(check) = create_check( <check>-obj_name ).
75106
IF check->settings-ignore_pseudo_comments = abap_true.
76107
CONTINUE.
77108
ENDIF.
78109
IF check->settings-pseudo_comment IS NOT INITIAL.
79-
APPEND check->settings-pseudo_comment TO result.
110+
REPLACE ALL OCCURRENCES OF `"#EC ` IN check->settings-pseudo_comment WITH ''.
111+
INSERT check->settings-pseudo_comment INTO TABLE result.
80112
ENDIF.
81113
IF check->settings-alternative_pseudo_comment IS NOT INITIAL.
82-
APPEND check->settings-alternative_pseudo_comment TO result.
114+
REPLACE ALL OCCURRENCES OF `"#EC ` IN check->settings-alternative_pseudo_comment WITH ''.
115+
INSERT check->settings-alternative_pseudo_comment INTO TABLE result.
83116
ENDIF.
84117
ENDLOOP.
85118
ENDMETHOD.
@@ -90,28 +123,4 @@ CLASS y_check_pseudo_comment_usage IMPLEMENTATION.
90123
ENDMETHOD.
91124

92125

93-
METHOD count_pseudo_comments.
94-
LOOP AT pseudo_comments ASSIGNING FIELD-SYMBOL(<pseudo_comment>).
95-
IF token-str CS <pseudo_comment>.
96-
pseudo_comment_counter = pseudo_comment_counter + 1.
97-
ENDIF.
98-
ENDLOOP.
99-
ENDMETHOD.
100-
101-
102-
METHOD check_result.
103-
CHECK pseudo_comment_counter > 0.
104-
105-
DATA(statement) = ref_scan->statements[ 1 ].
106-
107-
DATA(check_configuration) = detect_check_configuration( statement ).
108-
109-
raise_error( statement_level = statement-level
110-
statement_index = statement-from
111-
statement_from = statement-from
112-
check_configuration = check_configuration
113-
parameter_01 = |{ pseudo_comment_counter }| ).
114-
ENDMETHOD.
115-
116-
117126
ENDCLASS.

src/checks/y_check_pseudo_comment_usage.clas.testclasses.abap

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ CLASS ltc_pseudo_comment IMPLEMENTATION.
3939
ENDCLASS.
4040

4141

42+
4243
CLASS ltc_pragma DEFINITION INHERITING FROM ltc_pseudo_comment FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
4344
PROTECTED SECTION.
4445
METHODS get_code_without_issue REDEFINITION.
@@ -59,6 +60,7 @@ CLASS ltc_pragma IMPLEMENTATION.
5960
ENDCLASS.
6061

6162

63+
6264
CLASS ltc_alternative_pseudo_comment DEFINITION INHERITING FROM ltc_pseudo_comment FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
6365
PROTECTED SECTION.
6466
METHODS get_code_with_issue REDEFINITION.
@@ -77,3 +79,45 @@ CLASS ltc_alternative_pseudo_comment IMPLEMENTATION.
7779
ENDMETHOD.
7880

7981
ENDCLASS.
82+
83+
84+
85+
CLASS ltc_multiple_pseudo_comments DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
86+
PROTECTED SECTION.
87+
METHODS get_cut REDEFINITION.
88+
METHODS get_code_with_issue REDEFINITION.
89+
METHODS get_code_without_issue REDEFINITION.
90+
METHODS get_code_with_exemption REDEFINITION.
91+
ENDCLASS.
92+
93+
CLASS ltc_multiple_pseudo_comments IMPLEMENTATION.
94+
95+
METHOD get_cut.
96+
result ?= NEW y_check_pseudo_comment_usage( ).
97+
ENDMETHOD.
98+
99+
METHOD get_code_with_issue.
100+
result = VALUE #(
101+
( 'REPORT y_example. ' )
102+
( ' START-OF-SELECTION. ' )
103+
( ' TRY. ' )
104+
( ' CATCH cx_sy_arg_out_of_domain. "#EC EMPTY_CATCH #EC NO_HANDLER' )
105+
( ' ENDTRY. ' )
106+
).
107+
ENDMETHOD.
108+
109+
METHOD get_code_without_issue.
110+
result = VALUE #(
111+
( 'REPORT y_example. ' )
112+
( ' START-OF-SELECTION. ' )
113+
( ' TRY. ' )
114+
( ' CATCH cx_sy_arg_out_of_domain. "#EC NEEDED ' )
115+
( ' ENDTRY. ' )
116+
).
117+
ENDMETHOD.
118+
119+
METHOD get_code_with_exemption.
120+
result = VALUE #( ).
121+
ENDMETHOD.
122+
123+
ENDCLASS.

0 commit comments

Comments
 (0)