|
| 1 | +CLASS y_check_check_in_loop DEFINITION PUBLIC INHERITING FROM y_check_base CREATE PUBLIC . |
| 2 | + PUBLIC SECTION. |
| 3 | + METHODS constructor . |
| 4 | + |
| 5 | + PROTECTED SECTION. |
| 6 | + METHODS execute_check REDEFINITION. |
| 7 | + METHODS inspect_tokens REDEFINITION. |
| 8 | + |
| 9 | + PRIVATE SECTION. |
| 10 | + METHODS get_back_statement IMPORTING structure TYPE sstruc |
| 11 | + RETURNING VALUE(result) TYPE sstmnt. |
| 12 | + |
| 13 | +ENDCLASS. |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +CLASS y_check_check_in_loop IMPLEMENTATION. |
| 18 | + |
| 19 | + |
| 20 | + METHOD constructor. |
| 21 | + super->constructor( ). |
| 22 | + |
| 23 | + settings-pseudo_comment = '"#EC CHECK_IN_LOOP' ##NO_TEXT. |
| 24 | + settings-disable_threshold_selection = abap_true. |
| 25 | + settings-threshold = 0. |
| 26 | + settings-documentation = |{ c_docs_path-checks }check-in-loop.md|. |
| 27 | + |
| 28 | + set_check_message( 'Use an IF statement in combination with CONTINUE instead CHECK!' ). |
| 29 | + ENDMETHOD. |
| 30 | + |
| 31 | + |
| 32 | + METHOD execute_check. |
| 33 | + LOOP AT ref_scan_manager->get_structures( ) ASSIGNING FIELD-SYMBOL(<structure>) |
| 34 | + WHERE stmnt_type EQ scan_struc_stmnt_type-check. |
| 35 | + |
| 36 | + is_testcode = test_code_detector->is_testcode( <structure> ). |
| 37 | + |
| 38 | + TRY. |
| 39 | + DATA(check_configuration) = check_configurations[ apply_on_testcode = abap_true ]. |
| 40 | + CATCH cx_sy_itab_line_not_found. |
| 41 | + IF is_testcode EQ abap_true. |
| 42 | + CONTINUE. |
| 43 | + ENDIF. |
| 44 | + ENDTRY. |
| 45 | + |
| 46 | + DATA(index) = <structure>-stmnt_from. |
| 47 | + |
| 48 | + LOOP AT ref_scan_manager->get_statements( ) ASSIGNING FIELD-SYMBOL(<statement>) |
| 49 | + FROM <structure>-stmnt_from TO <structure>-stmnt_to. |
| 50 | + |
| 51 | + inspect_tokens( index = index |
| 52 | + structure = <structure> |
| 53 | + statement = <statement> ). |
| 54 | + index = index + 1. |
| 55 | + ENDLOOP. |
| 56 | + ENDLOOP. |
| 57 | + ENDMETHOD. |
| 58 | + |
| 59 | + |
| 60 | + METHOD inspect_tokens. |
| 61 | + CHECK get_token_abs( statement-from ) = 'CHECK'. |
| 62 | + CHECK get_token_abs( get_back_statement( structure )-from ) = 'LOOP'. |
| 63 | + |
| 64 | + DATA(check_configuration) = detect_check_configuration( statement ). |
| 65 | + |
| 66 | + IF check_configuration IS INITIAL. |
| 67 | + RETURN. |
| 68 | + ENDIF. |
| 69 | + |
| 70 | + raise_error( statement_level = statement-level |
| 71 | + statement_index = index |
| 72 | + statement_from = statement-from |
| 73 | + error_priority = check_configuration-prio ). |
| 74 | + ENDMETHOD. |
| 75 | + |
| 76 | + |
| 77 | + METHOD get_back_statement. |
| 78 | + DATA(structures) = ref_scan_manager->get_structures( ). |
| 79 | + DATA(statements) = ref_scan_manager->get_statements( ). |
| 80 | + |
| 81 | + TRY. |
| 82 | + DATA(back_structure) = structures[ structure-back ]. |
| 83 | + result = statements[ back_structure-stmnt_from ]. |
| 84 | + CATCH cx_sy_itab_line_not_found. |
| 85 | + CLEAR result. |
| 86 | + ENDTRY. |
| 87 | + ENDMETHOD. |
| 88 | + |
| 89 | + |
| 90 | +ENDCLASS. |
0 commit comments