Skip to content

Commit 6a00533

Browse files
lucasborinLucas Borin
andauthored
Alternative Pseudo Comment (#486)
* saving progress * saving progress * saving progress * alternative pseudo * fixing 7.40 compatibility * 7.40 compatibility * revert checksum * adjusting pseudo comment usage * adding unit tests * Missing space between string or character literal and parentheses * new pseudo comment * changelog * alt_pcom in ut * Update empty_catch.md Co-authored-by: Lucas Borin <5233413+lucasborin@users.noreply.github.co>
1 parent 2cb16bc commit 6a00533

9 files changed

+121
-108
lines changed

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Legend
1818

1919
2021-08-XX v.1.16.0
2020
------------------
21+
* Empty Catch Alternative Pseudo Comment (#337)
22+
+ Alternative Pseudo Comment (#486)
2123
* line_exists does not support the operator IN (#484)
2224
* Empty Catch: Test Double Framework (#483)
2325
* Y_CHECK_FORM: Screen Events (#454)

docs/checks/empty_catch.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,28 @@ Fill the `CATCH` block with an exception handling.
1212

1313
### What to do in case of exception?
1414

15-
In exceptional cases, you can suppress this finding by using the pseudo comment `"#EC EMPTY_CATCH` which should to be placed after the opening statement of the empty `CATCH`:
15+
In exceptional cases, you can suppress this finding by using the pseudo comment `"#EC EMPTY_CATCH` or `"#EC NO_HANDLER` which should to be placed after the opening statement of the empty `CATCH`:
1616

1717
```abap
1818
TRY.
1919
"some code
2020
CATCH cx_error. "#EC EMPTY_CATCH
2121
ENDTRY.
22+
```
2223

24+
```abap
2325
CATCH SYSTEM-EXCEPTIONS. "#EC EMPTY_CATCH
2426
ENDCATCH.
2527
```
28+
29+
```abap
30+
TRY.
31+
"some code
32+
CATCH cx_error. "#EC NO_HANDLER
33+
ENDTRY.
34+
```
35+
36+
```abap
37+
CATCH SYSTEM-EXCEPTIONS. "#EC NO_HANDLER
38+
ENDCATCH.
39+
```

src/checks/y_check_empty_catches.clas.abap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ CLASS y_check_empty_catches IMPLEMENTATION.
1919
METHOD constructor.
2020
super->constructor( ).
2121

22-
settings-pseudo_comment = '"#EC EMPTY_CATCH' ##NO_TEXT.
22+
settings-pseudo_comment = '"#EC EMPTY_CATCH'.
23+
settings-alternative_pseudo_comment = '"#EC NO_HANDLER'.
2324
settings-disable_threshold_selection = abap_true.
2425
settings-threshold = 0.
2526
settings-documentation = |{ c_docs_path-checks }empty-catch.md|.

src/checks/y_check_empty_catches.clas.testclasses.abap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ CLASS ltc_system_based IMPLEMENTATION.
138138

139139
( ' CLASS classname IMPLEMENTATION. ' )
140140
( ' METHOD system_based. ' )
141-
( ' CATCH SYSTEM-EXCEPTIONS OTHERS = 1. "#EC EMPTY_CATCH ' )
141+
( ' CATCH SYSTEM-EXCEPTIONS OTHERS = 1. "#EC NO_HANDLER ' )
142142
( ' ENDCATCH. ' )
143143
( ' ENDMETHOD. ' )
144144
( ' ENDCLASS. ' )

src/checks/y_check_pseudo_comment_usage.clas.abap

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ CLASS y_check_pseudo_comment_usage IMPLEMENTATION.
7272
LOOP AT y_profile_manager=>get_checks_from_db( ) ASSIGNING FIELD-SYMBOL(<check>)
7373
WHERE object = 'CLAS'.
7474
DATA(check) = create_check( <check>-obj_name ).
75-
IF check->settings-ignore_pseudo_comments = abap_false.
75+
IF check->settings-ignore_pseudo_comments = abap_true.
76+
CONTINUE.
77+
ENDIF.
78+
IF check->settings-pseudo_comment IS NOT INITIAL.
7679
APPEND check->settings-pseudo_comment TO result.
7780
ENDIF.
81+
IF check->settings-alternative_pseudo_comment IS NOT INITIAL.
82+
APPEND check->settings-alternative_pseudo_comment TO result.
83+
ENDIF.
7884
ENDLOOP.
7985
ENDMETHOD.
8086

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
CLASS local_test_class DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
1+
CLASS ltc_pseudo_comment DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
22
PROTECTED SECTION.
33
METHODS get_cut REDEFINITION.
44
METHODS get_code_with_issue REDEFINITION.
55
METHODS get_code_without_issue REDEFINITION.
66
METHODS get_code_with_exemption REDEFINITION.
77
ENDCLASS.
88

9-
CLASS local_test_class IMPLEMENTATION.
9+
CLASS ltc_pseudo_comment IMPLEMENTATION.
1010

1111
METHOD get_cut.
1212
result ?= NEW y_check_pseudo_comment_usage( ).
@@ -15,38 +15,20 @@ CLASS local_test_class IMPLEMENTATION.
1515
METHOD get_code_with_issue.
1616
result = VALUE #(
1717
( 'REPORT y_example. ' )
18-
( ' CLASS y_example_class DEFINITION. "#EC NMBR_INTERFACES ' )
19-
( ' PUBLIC SECTION. ' )
20-
( ' INTERFACES if_abap_c_reader. ' )
21-
( ' INTERFACES if_abap_reader. ' )
22-
( ' INTERFACES: ' )
23-
( ' if_abap_c_writer, ' )
24-
( ' if_abap_writer. ' )
25-
( ' PROTECTED SECTION. ' )
26-
( ' PRIVATE SECTION. ' )
27-
( ' ENDCLASS. ' )
28-
29-
( ' CLASS y_example_class IMPLEMENTATION. ' )
30-
( ' ENDCLASS. ' )
18+
( ' START-OF-SELECTION. ' )
19+
( ' TRY. ' )
20+
( ' CATCH cx_sy_arg_out_of_domain. "#EC EMPTY_CATCH' )
21+
( ' ENDTRY. ' )
3122
).
3223
ENDMETHOD.
3324

3425
METHOD get_code_without_issue.
3526
result = VALUE #(
3627
( 'REPORT y_example. ' )
37-
( ' CLASS y_example_class DEFINITION. ' )
38-
( ' PUBLIC SECTION. ' )
39-
( ' INTERFACES if_abap_c_reader. ' )
40-
( ' INTERFACES if_abap_reader. ' )
41-
( ' INTERFACES: ' )
42-
( ' if_abap_c_writer, ' )
43-
( ' if_abap_writer. ' )
44-
( ' PROTECTED SECTION. ' )
45-
( ' PRIVATE SECTION. ' )
46-
( ' ENDCLASS. ' )
47-
48-
( ' CLASS y_example_class IMPLEMENTATION. ' )
49-
( ' ENDCLASS. ' )
28+
( ' START-OF-SELECTION. ' )
29+
( ' TRY. ' )
30+
( ' CATCH cx_sy_arg_out_of_domain. ' )
31+
( ' ENDTRY. ' )
5032
).
5133
ENDMETHOD.
5234

@@ -55,3 +37,43 @@ CLASS local_test_class IMPLEMENTATION.
5537
ENDMETHOD.
5638

5739
ENDCLASS.
40+
41+
42+
CLASS ltc_pragma DEFINITION INHERITING FROM ltc_pseudo_comment FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
43+
PROTECTED SECTION.
44+
METHODS get_code_without_issue REDEFINITION.
45+
ENDCLASS.
46+
47+
CLASS ltc_pragma IMPLEMENTATION.
48+
49+
METHOD get_code_without_issue.
50+
result = VALUE #(
51+
( 'REPORT y_example. ' )
52+
( ' START-OF-SELECTION. ' )
53+
( ' TRY. ' )
54+
( ' CATCH cx_sy_arg_out_of_domain ##NO_HANDLER. ' )
55+
( ' ENDTRY. ' )
56+
).
57+
ENDMETHOD.
58+
59+
ENDCLASS.
60+
61+
62+
CLASS ltc_alternative_pseudo_comment DEFINITION INHERITING FROM ltc_pseudo_comment FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
63+
PROTECTED SECTION.
64+
METHODS get_code_with_issue REDEFINITION.
65+
ENDCLASS.
66+
67+
CLASS ltc_alternative_pseudo_comment IMPLEMENTATION.
68+
69+
METHOD get_code_with_issue.
70+
result = VALUE #(
71+
( 'REPORT y_example. ' )
72+
( ' START-OF-SELECTION. ' )
73+
( ' TRY. ' )
74+
( ' CATCH cx_sy_arg_out_of_domain. "#EC NO_HANDLER' )
75+
( ' ENDTRY. ' )
76+
).
77+
ENDMETHOD.
78+
79+
ENDCLASS.

src/foundation/y_check_base.clas.abap

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ CLASS y_check_base DEFINITION PUBLIC ABSTRACT
55
y_unit_test_coverage.
66

77
PUBLIC SECTION.
8-
CONSTANTS: BEGIN OF c_code,
9-
error TYPE sci_errc VALUE '100',
10-
warning TYPE sci_errc VALUE '101',
11-
notification TYPE sci_errc VALUE '102',
12-
END OF c_code.
13-
14-
CONSTANTS c_code_not_maintained TYPE sci_errc VALUE '106' ##NO_TEXT.
8+
CONSTANTS: BEGIN OF message_code,
9+
error TYPE sci_errc VALUE '100',
10+
warning TYPE sci_errc VALUE '101',
11+
notification TYPE sci_errc VALUE '102',
12+
not_maintained TYPE sci_errc VALUE '106',
13+
END OF message_code.
1514

1615
CONSTANTS: BEGIN OF c_docs_path,
1716
main TYPE string VALUE 'https://github.com/SAP/code-pal-for-abap/blob/master/docs/' ##NO_TEXT,
@@ -20,6 +19,7 @@ CLASS y_check_base DEFINITION PUBLIC ABSTRACT
2019

2120
DATA: BEGIN OF settings READ-ONLY,
2221
pseudo_comment TYPE sci_pcom,
22+
alternative_pseudo_comment TYPE sci_pcom,
2323
disable_on_prodcode_selection TYPE abap_bool,
2424
disable_on_testcode_selection TYPE abap_bool,
2525
disable_threshold_selection TYPE abap_bool,
@@ -170,9 +170,9 @@ CLASS Y_CHECK_BASE IMPLEMENTATION.
170170
relevant_structure_types = VALUE #( ( scan_struc_type-event ) ).
171171

172172
INSERT VALUE #( test = myname
173-
code = c_code_not_maintained
174-
kind = cl_ci_test_root=>c_note
175-
text = TEXT-106 ) INTO TABLE scimessages[].
173+
code = message_code-not_maintained
174+
kind = c_note
175+
text = TEXT-106 ) INTO TABLE scimessages.
176176
ENDMETHOD.
177177

178178

@@ -302,13 +302,13 @@ CLASS Y_CHECK_BASE IMPLEMENTATION.
302302
METHOD get_code.
303303
CASE message_prio.
304304
WHEN c_error.
305-
result = c_code-error.
305+
result = message_code-error.
306306
WHEN c_warning.
307-
result = c_code-warning.
307+
result = message_code-warning.
308308
WHEN c_note.
309-
result = c_code-notification.
309+
result = message_code-notification.
310310
WHEN OTHERS.
311-
result = c_code_not_maintained.
311+
result = message_code-not_maintained.
312312
ENDCASE.
313313
ENDMETHOD.
314314

@@ -529,13 +529,36 @@ CLASS Y_CHECK_BASE IMPLEMENTATION.
529529

530530

531531
METHOD set_check_message.
532-
y_message_registration=>add_message(
533-
EXPORTING
534-
check_name = myname
535-
text = message
536-
pseudo_comment = settings-pseudo_comment
537-
CHANGING
538-
messages = scimessages ).
532+
DATA(pseudo_comment) = COND #( WHEN settings-pseudo_comment IS NOT INITIAL
533+
THEN settings-pseudo_comment+5 ).
534+
535+
DATA(alternative_pseudo_comment) = COND #( WHEN settings-alternative_pseudo_comment IS NOT INITIAL
536+
THEN settings-alternative_pseudo_comment+5 ).
537+
538+
DATA(error) = VALUE scimessage( kind = c_error
539+
code = get_code( c_error )
540+
test = myname
541+
text = message
542+
pcom = pseudo_comment
543+
pcom_alt = alternative_pseudo_comment ).
544+
545+
DATA(warning) = VALUE scimessage( kind = c_warning
546+
code = get_code( c_warning )
547+
test = myname
548+
text = message
549+
pcom = pseudo_comment
550+
pcom_alt = alternative_pseudo_comment ).
551+
552+
DATA(notification) = VALUE scimessage( kind = c_note
553+
code = get_code( c_note )
554+
test = myname
555+
text = message
556+
pcom = pseudo_comment
557+
pcom_alt = alternative_pseudo_comment ).
558+
559+
INSERT error INTO TABLE scimessages.
560+
INSERT warning INTO TABLE scimessages.
561+
INSERT notification INTO TABLE scimessages.
539562
ENDMETHOD.
540563

541564

src/foundation/y_message_registration.clas.abap

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/foundation/y_message_registration.clas.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)