diff --git a/changelog.txt b/changelog.txt index b614facb..2363736d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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) diff --git a/docs/checks/empty_catch.md b/docs/checks/empty_catch.md index f6315383..33be338d 100644 --- a/docs/checks/empty_catch.md +++ b/docs/checks/empty_catch.md @@ -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. +``` diff --git a/src/checks/y_check_empty_catches.clas.abap b/src/checks/y_check_empty_catches.clas.abap index 9bb87337..1aeb521a 100644 --- a/src/checks/y_check_empty_catches.clas.abap +++ b/src/checks/y_check_empty_catches.clas.abap @@ -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|. diff --git a/src/checks/y_check_empty_catches.clas.testclasses.abap b/src/checks/y_check_empty_catches.clas.testclasses.abap index 79f90f9d..847e0d55 100644 --- a/src/checks/y_check_empty_catches.clas.testclasses.abap +++ b/src/checks/y_check_empty_catches.clas.testclasses.abap @@ -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. ' ) diff --git a/src/checks/y_check_pseudo_comment_usage.clas.abap b/src/checks/y_check_pseudo_comment_usage.clas.abap index b8658f30..860cb0b4 100644 --- a/src/checks/y_check_pseudo_comment_usage.clas.abap +++ b/src/checks/y_check_pseudo_comment_usage.clas.abap @@ -72,9 +72,15 @@ CLASS y_check_pseudo_comment_usage IMPLEMENTATION. LOOP AT y_profile_manager=>get_checks_from_db( ) ASSIGNING FIELD-SYMBOL() WHERE object = 'CLAS'. DATA(check) = create_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. diff --git a/src/checks/y_check_pseudo_comment_usage.clas.testclasses.abap b/src/checks/y_check_pseudo_comment_usage.clas.testclasses.abap index db839473..5dc3c5f5 100644 --- a/src/checks/y_check_pseudo_comment_usage.clas.testclasses.abap +++ b/src/checks/y_check_pseudo_comment_usage.clas.testclasses.abap @@ -1,4 +1,4 @@ -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. @@ -6,7 +6,7 @@ CLASS local_test_class DEFINITION INHERITING FROM y_unit_test_base FOR TESTING R 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( ). @@ -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. @@ -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. diff --git a/src/foundation/y_check_base.clas.abap b/src/foundation/y_check_base.clas.abap index 06ea76cc..372a1448 100644 --- a/src/foundation/y_check_base.clas.abap +++ b/src/foundation/y_check_base.clas.abap @@ -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, @@ -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, @@ -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. @@ -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. @@ -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. diff --git a/src/foundation/y_message_registration.clas.abap b/src/foundation/y_message_registration.clas.abap deleted file mode 100644 index 35f2f5cb..00000000 --- a/src/foundation/y_message_registration.clas.abap +++ /dev/null @@ -1,39 +0,0 @@ -CLASS y_message_registration DEFINITION - PUBLIC - CREATE PUBLIC . - - PUBLIC SECTION. - CLASS-METHODS add_message - IMPORTING - !check_name TYPE csequence - !text TYPE itex132 - !pseudo_comment TYPE sci_pcom OPTIONAL - CHANGING - !messages TYPE scimessages . -protected section. -private section. -ENDCLASS. - - - -CLASS Y_MESSAGE_REGISTRATION IMPLEMENTATION. - - - METHOD add_message. - INSERT VALUE #( test = check_name - code = y_check_base=>c_code-error - kind = cl_ci_test_root=>c_error - text = text - pcom = pseudo_comment+5 ) INTO TABLE messages[]. - INSERT VALUE #( test = check_name - code = y_check_base=>c_code-warning - kind = cl_ci_test_root=>c_warning - text = text - pcom = pseudo_comment+5 ) INTO TABLE messages[]. - INSERT VALUE #( test = check_name - code = y_check_base=>c_code-notification - kind = cl_ci_test_root=>c_note - text = text - pcom = pseudo_comment+5 ) INTO TABLE messages[]. - ENDMETHOD. -ENDCLASS. diff --git a/src/foundation/y_message_registration.clas.xml b/src/foundation/y_message_registration.clas.xml deleted file mode 100644 index 61fc273d..00000000 --- a/src/foundation/y_message_registration.clas.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - Y_MESSAGE_REGISTRATION - E - Message Registration - 1 - X - X - X - - - -