@@ -3,21 +3,23 @@ CLASS y_check_chain_decl_usage DEFINITION PUBLIC INHERITING FROM y_check_base CR
3
3
METHODS constructor.
4
4
5
5
PROTECTED SECTION .
6
+ METHODS inspect_statements REDEFINITION .
6
7
METHODS inspect_tokens REDEFINITION .
7
8
8
9
PRIVATE SECTION .
9
- TYPES : BEGIN OF ty_raised_issues,
10
- include TYPE slevel-name,
11
- line_number_colon TYPE sstmnt-colonrow,
12
- END OF ty_raised_issues.
13
-
14
- DATA raised_issues TYPE TABLE OF ty_raised_issues.
10
+ METHODS get_chained_statements RETURNING VALUE (result ) TYPE sstmnt_tab.
11
+ METHODS get_chained_variables IMPORTING structure_index TYPE sy -tabix
12
+ RETURNING VALUE (result ) TYPE sstmnt_tab.
13
+ METHODS get_chained_structures IMPORTING structure_index TYPE sy -tabix
14
+ RETURNING VALUE (result ) TYPE sstmnt_tab.
15
+ METHODS is_chained_structure RETURNING VALUE (result ) TYPE abap_bool .
16
+ METHODS is_complex_structure RETURNING VALUE (result ) TYPE abap_bool .
15
17
16
18
ENDCLASS .
17
19
18
20
19
21
20
- CLASS Y_CHECK_CHAIN_DECL_USAGE IMPLEMENTATION .
22
+ CLASS y_check_chain_decl_usage IMPLEMENTATION .
21
23
22
24
23
25
METHOD constructor .
@@ -28,33 +30,98 @@ CLASS Y_CHECK_CHAIN_DECL_USAGE IMPLEMENTATION.
28
30
settings-threshold = 0 .
29
31
settings-documentation = | { c_docs_path-checks } chain-declaration-usage.md| .
30
32
33
+ relevant_statement_types = VALUE #( BASE relevant_statement_types
34
+ ( scan_struc_stmnt_type-public_section )
35
+ ( scan_struc_stmnt_type-protected_section )
36
+ ( scan_struc_stmnt_type-private_section ) ).
37
+
31
38
set_check_message( 'Do not chain up-front declarations!' ).
32
39
ENDMETHOD .
33
40
34
41
42
+ METHOD inspect_statements .
43
+ DATA (statements ) = get_chained_statements( ).
44
+
45
+ LOOP AT statements INTO statement_wa
46
+ GROUP BY statement_wa-colonrow.
47
+ IF keyword( ) <> if_kaizen_keywords_c=>gc_data
48
+ AND keyword( ) <> if_kaizen_keywords_c=>gc_class_data
49
+ AND keyword( ) <> if_kaizen_keywords_c=>gc_constants
50
+ AND keyword( ) <> if_kaizen_keywords_c=>gc_types.
51
+ CONTINUE .
52
+ ENDIF .
53
+
54
+ DATA (count ) = REDUCE i( INIT x = 0
55
+ FOR row IN statements
56
+ WHERE ( colonrow = statement_wa-colonrow )
57
+ NEXT x = x + 1 ).
58
+
59
+ IF count = 1 .
60
+ CONTINUE .
61
+ ENDIF .
62
+
63
+ DATA (configuration ) = detect_check_configuration( statement_wa ).
64
+
65
+ raise_error( statement_level = statement_wa-level
66
+ statement_index = statement_wa-number
67
+ statement_from = statement_wa-from
68
+ check_configuration = configuration ).
69
+ ENDLOOP .
70
+ ENDMETHOD .
71
+
72
+
35
73
METHOD inspect_tokens .
36
- CHECK statement-colonrow IS NOT INITIAL .
37
- CHECK statement-terminator = ',' .
38
- CHECK get_token_abs( statement-from ) = 'DATA' .
74
+ RETURN .
75
+ ENDMETHOD .
39
76
40
- DATA (include ) = get_include( p_level = statement-level ).
41
77
42
- DATA (raised_issue ) = VALUE ty_raised_issues( include = include
43
- line_number_colon = statement-colonrow ).
78
+ METHOD get_chained_statements .
79
+ DATA (index ) = line_index ( ref_scan->structures[ table_line = structure_wa ] ).
80
+ APPEND LINES OF get_chained_variables( index ) TO result .
81
+ APPEND LINES OF get_chained_structures( index ) TO result .
82
+ ENDMETHOD .
44
83
45
- IF line_exists ( raised_issues[ include = raised_issue-include
46
- line_number_colon = raised_issue-line_number_colon ] ).
47
- RETURN .
48
- ENDIF .
49
84
50
- APPEND raised_issue TO raised_issues.
85
+ METHOD get_chained_variables .
86
+ result = VALUE sstmnt_tab( FOR statement IN ref_scan->statements
87
+ FROM structure_wa-stmnt_from TO structure_wa-stmnt_to
88
+ WHERE ( struc = structure_index AND prefixlen > 0 )
89
+ ( statement ) ).
90
+ ENDMETHOD .
91
+
92
+
93
+ METHOD get_chained_structures .
94
+ DATA (chained_structures ) = VALUE sstmnt_tab( FOR statement IN ref_scan->statements
95
+ FROM structure_wa-stmnt_from TO structure_wa-stmnt_to
96
+ WHERE ( struc <> structure_index AND prefixlen > 0 )
97
+ ( statement ) ).
98
+
99
+ LOOP AT chained_structures ASSIGNING FIELD-SYMBOL (<chained_structure> )
100
+ GROUP BY <chained_structure> -struc.
101
+ structure_wa = ref_scan->structures[ <chained_structure> -struc ].
102
+
103
+ IF is_chained_structure( ) = abap_false
104
+ OR is_complex_structure( ) = abap_true .
105
+ CONTINUE .
106
+ ENDIF .
107
+
108
+ APPEND <chained_structure> TO result .
109
+ ENDLOOP .
110
+ ENDMETHOD .
111
+
112
+
113
+ METHOD is_chained_structure .
114
+ result = xsdbool ( structure_wa-stmnt_type = scan_struc_stmnt_type-data
115
+ OR structure_wa-stmnt_type = scan_struc_stmnt_type-sequence
116
+ OR structure_wa-stmnt_type = scan_struc_stmnt_type-types ).
117
+ ENDMETHOD .
118
+
51
119
52
- DATA (configuration ) = detect_check_configuration( statement ).
120
+ METHOD is_complex_structure .
121
+ DATA (statement_type ) = ref_scan->structures[ structure_wa-back ]-stmnt_type.
53
122
54
- raise_error( statement_level = statement-level
55
- statement_index = index
56
- statement_from = statement-from
57
- check_configuration = configuration ).
123
+ result = xsdbool ( statement_type = scan_struc_stmnt_type-data
124
+ OR statement_type = scan_struc_stmnt_type-types ).
58
125
ENDMETHOD .
59
126
60
127
0 commit comments