Skip to content

Alternative Pseudo Comment #486

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

Merged
merged 14 commits into from
Oct 18, 2021
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
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Legend

2021-08-XX v.1.16.0
------------------
* Empty Catch Alternative Pseudo Comment (#337)
+ Alternative Pseudo Comment (#486)
* line_exists does not support the operator IN (#484)
* Empty Catch: Test Double Framework (#483)
* Y_CHECK_FORM: Screen Events (#454)
Expand Down
16 changes: 15 additions & 1 deletion docs/checks/empty_catch.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,28 @@ Fill the `CATCH` block with an exception handling.

### What to do in case of exception?

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`:
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`:

```abap
TRY.
"some code
CATCH cx_error. "#EC EMPTY_CATCH
ENDTRY.
```

```abap
CATCH SYSTEM-EXCEPTIONS. "#EC EMPTY_CATCH
ENDCATCH.
```

```abap
TRY.
"some code
CATCH cx_error. "#EC NO_HANDLER
ENDTRY.
```

```abap
CATCH SYSTEM-EXCEPTIONS. "#EC NO_HANDLER
ENDCATCH.
```
3 changes: 2 additions & 1 deletion src/checks/y_check_empty_catches.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ CLASS y_check_empty_catches IMPLEMENTATION.
METHOD constructor.
super->constructor( ).

settings-pseudo_comment = '"#EC EMPTY_CATCH' ##NO_TEXT.
settings-pseudo_comment = '"#EC EMPTY_CATCH'.
settings-alternative_pseudo_comment = '"#EC NO_HANDLER'.
settings-disable_threshold_selection = abap_true.
settings-threshold = 0.
settings-documentation = |{ c_docs_path-checks }empty-catch.md|.
Expand Down
2 changes: 1 addition & 1 deletion src/checks/y_check_empty_catches.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ CLASS ltc_system_based IMPLEMENTATION.

( ' CLASS classname IMPLEMENTATION. ' )
( ' METHOD system_based. ' )
( ' CATCH SYSTEM-EXCEPTIONS OTHERS = 1. "#EC EMPTY_CATCH ' )
( ' CATCH SYSTEM-EXCEPTIONS OTHERS = 1. "#EC NO_HANDLER ' )
( ' ENDCATCH. ' )
( ' ENDMETHOD. ' )
( ' ENDCLASS. ' )
Expand Down
8 changes: 7 additions & 1 deletion src/checks/y_check_pseudo_comment_usage.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ CLASS y_check_pseudo_comment_usage IMPLEMENTATION.
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_false.
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.
ENDIF.
IF check->settings-alternative_pseudo_comment IS NOT INITIAL.
APPEND check->settings-alternative_pseudo_comment TO result.
ENDIF.
ENDLOOP.
ENDMETHOD.

Expand Down
78 changes: 50 additions & 28 deletions src/checks/y_check_pseudo_comment_usage.clas.testclasses.abap
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
CLASS local_test_class DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
CLASS ltc_pseudo_comment 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 local_test_class IMPLEMENTATION.
CLASS ltc_pseudo_comment IMPLEMENTATION.

METHOD get_cut.
result ?= NEW y_check_pseudo_comment_usage( ).
Expand All @@ -15,38 +15,20 @@ CLASS local_test_class IMPLEMENTATION.
METHOD get_code_with_issue.
result = VALUE #(
( 'REPORT y_example. ' )
( ' CLASS y_example_class DEFINITION. "#EC NMBR_INTERFACES ' )
( ' PUBLIC SECTION. ' )
( ' INTERFACES if_abap_c_reader. ' )
( ' INTERFACES if_abap_reader. ' )
( ' INTERFACES: ' )
( ' if_abap_c_writer, ' )
( ' if_abap_writer. ' )
( ' PROTECTED SECTION. ' )
( ' PRIVATE SECTION. ' )
( ' ENDCLASS. ' )

( ' CLASS y_example_class IMPLEMENTATION. ' )
( ' ENDCLASS. ' )
( ' START-OF-SELECTION. ' )
( ' TRY. ' )
( ' CATCH cx_sy_arg_out_of_domain. "#EC EMPTY_CATCH' )
( ' ENDTRY. ' )
).
ENDMETHOD.

METHOD get_code_without_issue.
result = VALUE #(
( 'REPORT y_example. ' )
( ' CLASS y_example_class DEFINITION. ' )
( ' PUBLIC SECTION. ' )
( ' INTERFACES if_abap_c_reader. ' )
( ' INTERFACES if_abap_reader. ' )
( ' INTERFACES: ' )
( ' if_abap_c_writer, ' )
( ' if_abap_writer. ' )
( ' PROTECTED SECTION. ' )
( ' PRIVATE SECTION. ' )
( ' ENDCLASS. ' )

( ' CLASS y_example_class IMPLEMENTATION. ' )
( ' ENDCLASS. ' )
( ' START-OF-SELECTION. ' )
( ' TRY. ' )
( ' CATCH cx_sy_arg_out_of_domain. ' )
( ' ENDTRY. ' )
).
ENDMETHOD.

Expand All @@ -55,3 +37,43 @@ CLASS local_test_class IMPLEMENTATION.
ENDMETHOD.

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.
ENDCLASS.

CLASS ltc_pragma IMPLEMENTATION.

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

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.
ENDCLASS.

CLASS ltc_alternative_pseudo_comment IMPLEMENTATION.

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

ENDCLASS.
65 changes: 44 additions & 21 deletions src/foundation/y_check_base.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ CLASS y_check_base DEFINITION PUBLIC ABSTRACT
y_unit_test_coverage.

PUBLIC SECTION.
CONSTANTS: BEGIN OF c_code,
error TYPE sci_errc VALUE '100',
warning TYPE sci_errc VALUE '101',
notification TYPE sci_errc VALUE '102',
END OF c_code.

CONSTANTS c_code_not_maintained TYPE sci_errc VALUE '106' ##NO_TEXT.
CONSTANTS: BEGIN OF message_code,
error TYPE sci_errc VALUE '100',
warning TYPE sci_errc VALUE '101',
notification TYPE sci_errc VALUE '102',
not_maintained TYPE sci_errc VALUE '106',
END OF message_code.

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

DATA: BEGIN OF settings READ-ONLY,
pseudo_comment TYPE sci_pcom,
alternative_pseudo_comment TYPE sci_pcom,
disable_on_prodcode_selection TYPE abap_bool,
disable_on_testcode_selection TYPE abap_bool,
disable_threshold_selection TYPE abap_bool,
Expand Down Expand Up @@ -170,9 +170,9 @@ CLASS Y_CHECK_BASE IMPLEMENTATION.
relevant_structure_types = VALUE #( ( scan_struc_type-event ) ).

INSERT VALUE #( test = myname
code = c_code_not_maintained
kind = cl_ci_test_root=>c_note
text = TEXT-106 ) INTO TABLE scimessages[].
code = message_code-not_maintained
kind = c_note
text = TEXT-106 ) INTO TABLE scimessages.
ENDMETHOD.


Expand Down Expand Up @@ -302,13 +302,13 @@ CLASS Y_CHECK_BASE IMPLEMENTATION.
METHOD get_code.
CASE message_prio.
WHEN c_error.
result = c_code-error.
result = message_code-error.
WHEN c_warning.
result = c_code-warning.
result = message_code-warning.
WHEN c_note.
result = c_code-notification.
result = message_code-notification.
WHEN OTHERS.
result = c_code_not_maintained.
result = message_code-not_maintained.
ENDCASE.
ENDMETHOD.

Expand Down Expand Up @@ -529,13 +529,36 @@ CLASS Y_CHECK_BASE IMPLEMENTATION.


METHOD set_check_message.
y_message_registration=>add_message(
EXPORTING
check_name = myname
text = message
pseudo_comment = settings-pseudo_comment
CHANGING
messages = scimessages ).
DATA(pseudo_comment) = COND #( WHEN settings-pseudo_comment IS NOT INITIAL
THEN settings-pseudo_comment+5 ).

DATA(alternative_pseudo_comment) = COND #( WHEN settings-alternative_pseudo_comment IS NOT INITIAL
THEN settings-alternative_pseudo_comment+5 ).

DATA(error) = VALUE scimessage( kind = c_error
code = get_code( c_error )
test = myname
text = message
pcom = pseudo_comment
pcom_alt = alternative_pseudo_comment ).

DATA(warning) = VALUE scimessage( kind = c_warning
code = get_code( c_warning )
test = myname
text = message
pcom = pseudo_comment
pcom_alt = alternative_pseudo_comment ).

DATA(notification) = VALUE scimessage( kind = c_note
code = get_code( c_note )
test = myname
text = message
pcom = pseudo_comment
pcom_alt = alternative_pseudo_comment ).

INSERT error INTO TABLE scimessages.
INSERT warning INTO TABLE scimessages.
INSERT notification INTO TABLE scimessages.
ENDMETHOD.


Expand Down
39 changes: 0 additions & 39 deletions src/foundation/y_message_registration.clas.abap

This file was deleted.

16 changes: 0 additions & 16 deletions src/foundation/y_message_registration.clas.xml

This file was deleted.