Skip to content

Commit eb3baac

Browse files
committed
solving remaining syntax errors
1 parent e9cb839 commit eb3baac

File tree

3 files changed

+93
-100
lines changed

3 files changed

+93
-100
lines changed

src/checks/y_check_prefer_case_to_elseif.clas.abap

Lines changed: 45 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ CLASS y_check_prefer_case_to_elseif DEFINITION PUBLIC INHERITING FROM y_check_ba
77
METHODS inspect_tokens REDEFINITION.
88

99
PRIVATE SECTION.
10-
TYPES: BEGIN OF counter,
10+
TYPES: BEGIN OF ty_counter,
1111
if_structure TYPE sstruc,
1212
if_statement TYPE sstmnt,
1313
condition TYPE string,
1414
count TYPE i,
15-
END OF counter.
16-
TYPES counters TYPE TABLE OF counter.
15+
END OF ty_counter.
16+
17+
TYPES ty_counters TYPE TABLE OF ty_counter.
18+
19+
DATA counters TYPE ty_counters.
1720

1821
METHODS has_multiple_conditions IMPORTING statement TYPE sstmnt
1922
RETURNING VALUE(result) TYPE abap_bool.
2023

21-
METHODS should_skip_test_code IMPORTING structure TYPE sstruc
22-
RETURNING VALUE(result) TYPE abap_bool.
23-
24-
METHODS handle_result IMPORTING counters TYPE counters.
24+
METHODS handle_result.
2525

2626
ENDCLASS.
2727

@@ -37,69 +37,54 @@ CLASS y_check_prefer_case_to_elseif IMPLEMENTATION.
3737
settings-threshold = 5.
3838
settings-documentation = |{ c_docs_path-checks }prefer-case-to-elseif.md|.
3939

40+
relevant_statement_types = VALUE #( ).
41+
42+
relevant_structure_types = VALUE #( ( scan_struc_type-condition )
43+
( scan_struc_type-alternation ) ).
44+
4045
set_check_message( 'Prefer CASE to ELSE IF for multiple alternative conditions!' ).
4146
ENDMETHOD.
4247

4348

4449
METHOD execute_check.
45-
DATA counters TYPE counters.
46-
47-
DATA(structures) = ref_scan_manager->get_structures( ).
48-
DATA(statements) = ref_scan_manager->get_statements( ).
49-
50-
LOOP AT structures ASSIGNING FIELD-SYMBOL(<structure>)
51-
WHERE type = scan_struc_type-condition
52-
OR type = scan_struc_type-alternation.
53-
54-
IF should_skip_test_code( <structure> ) = abap_true.
55-
CONTINUE.
56-
ENDIF.
57-
58-
DATA(statement) = statements[ <structure>-stmnt_from ].
59-
60-
IF has_multiple_conditions( statement ) = abap_true.
61-
CONTINUE.
62-
ENDIF.
63-
64-
DATA(token) = get_token_abs( statement-from ).
65-
66-
DATA(if_structure) = COND #( WHEN token = 'IF' THEN <structure>
67-
WHEN token = 'ELSEIF' THEN structures[ <structure>-back ] ).
68-
69-
IF if_structure IS INITIAL.
70-
CONTINUE.
71-
ENDIF.
50+
super->execute_check( ).
51+
handle_result( ).
52+
ENDMETHOD.
7253

73-
DATA(condition) = get_token_abs( statement-from + 1 ).
7454

75-
TRY.
76-
counters[ if_structure = if_structure
77-
condition = condition ]-count = counters[ if_structure = if_structure
78-
condition = condition ]-count + 1.
79-
CATCH cx_sy_itab_line_not_found.
80-
counters = VALUE #( BASE counters
81-
( if_structure = if_structure
82-
if_statement = statements[ if_structure-stmnt_from ]
83-
condition = condition
84-
count = 1 ) ).
85-
ENDTRY.
55+
METHOD inspect_tokens.
8656

87-
ENDLOOP.
57+
" Only the first statement is relevant
58+
CHECK structure-stmnt_from = index.
8859

89-
handle_result( counters ).
90-
91-
ENDMETHOD.
60+
DATA(if_statement) = ref_scan_manager->statements[ structure-stmnt_from ].
9261

62+
IF has_multiple_conditions( if_statement ) = abap_true.
63+
RETURN.
64+
ENDIF.
9365

94-
METHOD inspect_tokens.
95-
RETURN.
96-
ENDMETHOD.
66+
DATA(if_token) = get_token_abs( if_statement-from ).
9767

68+
DATA(if_structure) = COND #( WHEN if_token = 'IF' THEN structure
69+
WHEN if_token = 'ELSEIF' THEN ref_scan_manager->structures[ structure-back ] ).
9870

99-
METHOD should_skip_test_code.
100-
CHECK test_code_detector->is_testcode( structure ) = abap_true.
101-
CHECK line_exists( check_configurations[ apply_on_testcode = abap_false ] ).
102-
result = abap_true.
71+
IF if_structure IS INITIAL.
72+
RETURN.
73+
ENDIF.
74+
75+
DATA(condition) = get_token_abs( if_statement-from + 1 ).
76+
77+
TRY.
78+
counters[ if_structure = if_structure
79+
condition = condition ]-count = counters[ if_structure = if_structure
80+
condition = condition ]-count + 1.
81+
CATCH cx_sy_itab_line_not_found.
82+
counters = VALUE #( BASE counters
83+
( if_structure = if_structure
84+
if_statement = if_statement
85+
condition = condition
86+
count = 1 ) ).
87+
ENDTRY.
10388
ENDMETHOD.
10489

10590

@@ -120,13 +105,15 @@ CLASS y_check_prefer_case_to_elseif IMPLEMENTATION.
120105
ENDLOOP.
121106
ENDMETHOD.
122107

108+
123109
METHOD has_multiple_conditions.
124-
LOOP AT ref_scan_manager->get_tokens( ) ASSIGNING FIELD-SYMBOL(<token>)
110+
LOOP AT ref_scan_manager->tokens ASSIGNING FIELD-SYMBOL(<token>)
125111
FROM statement-from TO statement-to
126112
WHERE str = 'AND' OR str = 'OR'.
127113
result = abap_true.
128114
RETURN.
129115
ENDLOOP.
130116
ENDMETHOD.
131117

118+
132119
ENDCLASS.

src/checks/y_check_pseudo_comment_usage.clas.abap

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
1-
CLASS y_check_pseudo_comment_usage DEFINITION
2-
PUBLIC
3-
INHERITING FROM y_check_base
4-
CREATE PUBLIC .
5-
1+
CLASS y_check_pseudo_comment_usage DEFINITION PUBLIC INHERITING FROM y_check_base CREATE PUBLIC.
62
PUBLIC SECTION.
3+
METHODS constructor.
74

8-
METHODS constructor .
95
PROTECTED SECTION.
10-
CONSTANTS check_base_name TYPE tadir-obj_name VALUE 'Y_CHECK_BASE'.
11-
DATA name_tab TYPE STANDARD TABLE OF tadir-obj_name.
12-
13-
METHODS select_object_list
14-
RETURNING VALUE(result) LIKE name_tab
15-
RAISING cx_failed.
16-
17-
METHODS call_get_pseudo_comment
18-
IMPORTING obj_name TYPE stokesx-str
19-
RETURNING VALUE(result) TYPE stokesx-str
20-
RAISING cx_sy_create_object_error.
21-
226
METHODS execute_check REDEFINITION.
237
METHODS inspect_tokens REDEFINITION.
248

259
PRIVATE SECTION.
10+
CONSTANTS check_base_name TYPE tadir-obj_name VALUE 'Y_CHECK_BASE'.
11+
12+
DATA name_tab TYPE STANDARD TABLE OF tadir-obj_name.
2613
DATA pseudo_comment_counter TYPE i VALUE 0 ##NO_TEXT.
2714
DATA class_names TYPE string_table.
2815

29-
METHODS count_cc_pseudo_comments
30-
IMPORTING token TYPE stokesx
31-
class_names TYPE string_table.
16+
METHODS count_cc_pseudo_comments IMPORTING token TYPE stokesx.
3217

3318
METHODS raise_error_wrapper.
19+
20+
METHODS select_object_list RETURNING VALUE(result) LIKE name_tab
21+
RAISING cx_failed.
22+
23+
METHODS call_get_pseudo_comment IMPORTING obj_name TYPE stokesx-str
24+
RETURNING VALUE(result) TYPE stokesx-str
25+
RAISING cx_sy_create_object_error.
26+
3427
ENDCLASS.
3528

3629

3730

38-
CLASS Y_CHECK_PSEUDO_COMMENT_USAGE IMPLEMENTATION.
31+
CLASS y_check_pseudo_comment_usage IMPLEMENTATION.
3932

4033

4134
METHOD call_get_pseudo_comment.
@@ -61,7 +54,17 @@ CLASS Y_CHECK_PSEUDO_COMMENT_USAGE IMPLEMENTATION.
6154
settings-apply_on_productive_code = abap_true.
6255
settings-prio = c_note.
6356

57+
relevant_statement_types = VALUE #( ).
58+
relevant_structure_types = VALUE #( ).
59+
6460
set_check_message( '&1 pseudo comments!' ).
61+
62+
TRY.
63+
class_names = select_object_list( ).
64+
CATCH cx_failed.
65+
APPEND INITIAL LINE TO class_names.
66+
ENDTRY.
67+
6568
ENDMETHOD.
6669

6770

@@ -79,26 +82,18 @@ CLASS Y_CHECK_PSEUDO_COMMENT_USAGE IMPLEMENTATION.
7982

8083

8184
METHOD execute_check.
82-
TRY.
83-
class_names = select_object_list( ).
84-
CATCH cx_failed.
85-
APPEND INITIAL LINE TO class_names.
86-
ENDTRY.
87-
88-
pseudo_comment_counter = 0.
89-
is_testcode = abap_false.
90-
91-
LOOP AT ref_scan_manager->get_tokens( ) ASSIGNING FIELD-SYMBOL(<token>)
92-
WHERE type EQ 'C' OR type EQ 'P'.
93-
count_cc_pseudo_comments( token = <token> class_names = class_names ).
94-
ENDLOOP.
95-
85+
super->execute_check( ).
9686
raise_error_wrapper( ).
9787
ENDMETHOD.
9888

9989

10090
METHOD inspect_tokens.
101-
RETURN.
91+
LOOP AT ref_scan_manager->tokens ASSIGNING FIELD-SYMBOL(<token>)
92+
FROM statement-from TO statement-to
93+
WHERE type EQ 'C'
94+
OR type EQ 'P'.
95+
count_cc_pseudo_comments( <token> ).
96+
ENDLOOP.
10297
ENDMETHOD.
10398

10499

@@ -134,4 +129,6 @@ CLASS Y_CHECK_PSEUDO_COMMENT_USAGE IMPLEMENTATION.
134129
RAISE EXCEPTION TYPE cx_failed.
135130
ENDIF.
136131
ENDMETHOD.
132+
133+
137134
ENDCLASS.

src/foundation/y_check_base.clas.abap

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,13 @@ CLASS y_check_base DEFINITION PUBLIC ABSTRACT
133133
RETURNING VALUE(result) TYPE abap_bool.
134134

135135
METHODS is_in_scope IMPORTING statement TYPE sstmnt
136-
RETURNING value(result) TYPE abap_bool.
136+
RETURNING VALUE(result) TYPE abap_bool.
137137

138138
METHODS get_application_component IMPORTING level TYPE slevel
139139
RETURNING VALUE(result) TYPE df14l-ps_posid.
140140

141+
METHODS are_relevant_types_set RETURNING VALUE(result) TYPE abap_bool.
142+
141143
ENDCLASS.
142144

143145

@@ -224,9 +226,11 @@ CLASS y_check_base IMPLEMENTATION.
224226

225227
METHOD execute_check.
226228
LOOP AT ref_scan_manager->structures ASSIGNING FIELD-SYMBOL(<structure>).
227-
IF is_statement_type_relevant( <structure> ) = abap_false
228-
AND is_structure_type_relevant( <structure> ) = abap_false.
229-
CONTINUE.
229+
IF are_relevant_types_set( ) = abap_true.
230+
IF is_statement_type_relevant( <structure> ) = abap_false
231+
AND is_structure_type_relevant( <structure> ) = abap_false.
232+
CONTINUE.
233+
ENDIF.
230234
ENDIF.
231235

232236
IF should_skip_test_code( <structure> ) = abap_true.
@@ -247,7 +251,6 @@ CLASS y_check_base IMPLEMENTATION.
247251
statement = <statement> ).
248252

249253
index = index + 1.
250-
251254
ENDLOOP.
252255
ENDLOOP.
253256
ENDMETHOD.
@@ -787,4 +790,10 @@ CLASS y_check_base IMPLEMENTATION.
787790
ENDMETHOD.
788791

789792

793+
METHOD are_relevant_types_set.
794+
result = xsdbool( relevant_statement_types IS NOT INITIAL
795+
OR relevant_structure_types IS NOT INITIAL ).
796+
ENDMETHOD.
797+
798+
790799
ENDCLASS.

0 commit comments

Comments
 (0)