Skip to content

Commit b31afa0

Browse files
committed
Simplifying new architecture
1 parent 50920d4 commit b31afa0

17 files changed

+437
-422
lines changed

src/checks/y_check_comment_usage.clas.abap

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,22 @@ CLASS y_check_comment_usage DEFINITION PUBLIC INHERITING FROM y_check_base CREAT
33
METHODS constructor.
44

55
PROTECTED SECTION.
6-
METHODS execute_check REDEFINITION.
6+
METHODS inspect_statements REDEFINITION.
77
METHODS inspect_tokens REDEFINITION.
88

99
PRIVATE SECTION.
10-
DATA leading_structure TYPE sstruc.
11-
1210
DATA abs_statement_number TYPE i VALUE 0.
1311
DATA comment_number TYPE i VALUE 0.
14-
DATA percentage_of_comments TYPE decfloat16 VALUE 0.
1512
DATA is_function_module TYPE abap_bool.
1613

17-
METHODS calc_percentage_of_comments.
18-
METHODS check_leading_structure.
14+
METHODS get_percentage_of_comments RETURNING VALUE(result) TYPE int4.
15+
16+
METHODS check_result IMPORTING structure TYPE sstruc.
1917

2018
METHODS is_code_disabled IMPORTING structure TYPE sstruc
2119
statement TYPE sstmnt
2220
RETURNING VALUE(result) TYPE abap_bool.
2321

24-
METHODS set_leading_structure IMPORTING structure TYPE sstruc.
25-
2622
ENDCLASS.
2723

2824

@@ -39,26 +35,23 @@ CLASS y_check_comment_usage IMPLEMENTATION.
3935

4036
relevant_statement_types = VALUE #( BASE relevant_statement_types
4137
( scan_struc_stmnt_type-class_definition )
42-
( scan_struc_stmnt_type-class_implementation )
4338
( scan_struc_stmnt_type-interface ) ).
4439

4540
set_check_message( 'Percentage of comments must be lower than &3% of the productive code! (&2%>=&3%) (&1 lines found)' ).
4641
ENDMETHOD.
4742

4843

49-
METHOD execute_check.
50-
super->execute_check( ).
51-
check_leading_structure( ).
52-
ENDMETHOD.
44+
METHOD inspect_statements.
45+
abs_statement_number = 0.
46+
comment_number = 0.
5347

48+
super->inspect_statements( structure ).
5449

55-
METHOD inspect_tokens.
50+
check_result( structure ).
51+
ENDMETHOD.
5652

57-
IF leading_structure <> structure.
58-
check_leading_structure( ).
59-
set_leading_structure( structure ).
60-
ENDIF.
6153

54+
METHOD inspect_tokens.
6255
DATA(code_disabled) = is_code_disabled( statement = statement
6356
structure = structure ).
6457

@@ -75,7 +68,6 @@ CLASS y_check_comment_usage IMPLEMENTATION.
7568
LOOP AT ref_scan_manager->tokens ASSIGNING FIELD-SYMBOL(<token>)
7669
FROM statement-from TO statement-to
7770
WHERE type EQ scan_token_type-comment.
78-
7971
IF strlen( <token>-str ) GE 2 AND NOT
8072
( <token>-str+0(2) EQ |*"| OR
8173
<token>-str+0(2) EQ |"!| OR
@@ -87,41 +79,39 @@ CLASS y_check_comment_usage IMPLEMENTATION.
8779
comment_number = comment_number + 1.
8880
ENDIF.
8981
ENDLOOP.
90-
9182
ENDMETHOD.
9283

9384

94-
METHOD check_leading_structure.
85+
METHOD check_result.
86+
DATA(percentage_of_comments) = get_percentage_of_comments( ).
9587

96-
CHECK leading_structure IS NOT INITIAL.
88+
DATA(statement_for_message) = ref_scan_manager->statements[ structure-stmnt_from ].
9789

98-
calc_percentage_of_comments( ).
99-
100-
DATA(statement_for_message) = ref_scan_manager->statements[ leading_structure-stmnt_from ].
101-
102-
DATA(check_configuration) = detect_check_configuration( error_count = round( val = percentage_of_comments
103-
dec = 0
104-
mode = cl_abap_math=>round_down )
90+
DATA(check_configuration) = detect_check_configuration( error_count = percentage_of_comments
10591
statement = statement_for_message ).
10692

10793
IF check_configuration IS INITIAL.
10894
RETURN.
10995
ENDIF.
11096

11197
raise_error( statement_level = statement_for_message-level
112-
statement_index = leading_structure-stmnt_from
98+
statement_index = structure-stmnt_from
11399
statement_from = statement_for_message-from
114100
error_priority = check_configuration-prio
115101
parameter_01 = |{ comment_number }|
116102
parameter_02 = |{ percentage_of_comments }|
117103
parameter_03 = |{ check_configuration-threshold }| ).
118-
119104
ENDMETHOD.
120105

121106

122-
METHOD calc_percentage_of_comments.
123-
percentage_of_comments = ( comment_number / abs_statement_number ) * 100.
124-
percentage_of_comments = round( val = percentage_of_comments dec = 2 ).
107+
METHOD get_percentage_of_comments.
108+
DATA percentage TYPE decfloat16.
109+
110+
percentage = ( comment_number / abs_statement_number ) * 100.
111+
112+
result = round( val = percentage
113+
dec = 0
114+
mode = cl_abap_math=>round_down ).
125115
ENDMETHOD.
126116

127117

@@ -138,13 +128,4 @@ CLASS y_check_comment_usage IMPLEMENTATION.
138128
ENDMETHOD.
139129

140130

141-
METHOD set_leading_structure.
142-
leading_structure = structure.
143-
144-
abs_statement_number = 0.
145-
comment_number = 0.
146-
percentage_of_comments = 0.
147-
ENDMETHOD.
148-
149-
150131
ENDCLASS.

src/checks/y_check_comment_usage.clas.testclasses.abap

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
CLASS local_test_class DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
1+
CLASS ltc_report DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
22
PROTECTED SECTION.
33
METHODS get_cut REDEFINITION.
44
METHODS get_code_with_issue REDEFINITION.
55
METHODS get_code_without_issue REDEFINITION.
66
METHODS get_code_with_exemption REDEFINITION.
77
ENDCLASS.
88

9-
CLASS local_test_class IMPLEMENTATION.
9+
CLASS ltc_report IMPLEMENTATION.
1010

1111
METHOD get_cut.
1212
result ?= NEW y_check_comment_usage( ).
@@ -44,3 +44,66 @@ CLASS local_test_class IMPLEMENTATION.
4444
ENDMETHOD.
4545

4646
ENDCLASS.
47+
48+
49+
CLASS ltc_class DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
50+
PROTECTED SECTION.
51+
METHODS get_cut REDEFINITION.
52+
METHODS get_code_with_issue REDEFINITION.
53+
METHODS get_code_without_issue REDEFINITION.
54+
METHODS get_code_with_exemption REDEFINITION.
55+
ENDCLASS.
56+
57+
CLASS ltc_class IMPLEMENTATION.
58+
59+
METHOD get_cut.
60+
result ?= NEW y_check_comment_usage( ).
61+
ENDMETHOD.
62+
63+
METHOD get_code_with_issue.
64+
result = VALUE #(
65+
( 'REPORT y_example. ' )
66+
67+
( ' CLASS y_example DEFINITION.' )
68+
( ' PUBLIC SECTION. ' )
69+
( ' METHODS example.' )
70+
( ' ENDCLASS. ' )
71+
72+
( ' CLASS y_example IMPLEMENTATION.' )
73+
( ' METHOD example.' )
74+
( '* COMMENT ' )
75+
( ' "do something ' )
76+
( ' "do more ' )
77+
( ' "do much more ' )
78+
( ' "but not any time soon ' )
79+
( ' ENDMETHOD.' )
80+
( ' ENDCLASS. ' )
81+
).
82+
ENDMETHOD.
83+
84+
METHOD get_code_without_issue.
85+
result = VALUE #(
86+
( 'REPORT y_example. ' )
87+
88+
( ' CLASS y_example DEFINITION.' )
89+
( ' PUBLIC SECTION. ' )
90+
( ' METHODS example.' )
91+
( ' ENDCLASS. ' )
92+
93+
( ' CLASS y_example IMPLEMENTATION.' )
94+
( ' METHOD example.' )
95+
( ' DATA name3 TYPE string. ' )
96+
( ' "?<html> ' )
97+
( '*"*COMMENT ' )
98+
( '*" ' )
99+
( ' "! docu ' )
100+
( ' ENDMETHOD.' )
101+
( ' ENDCLASS. ' )
102+
).
103+
ENDMETHOD.
104+
105+
METHOD get_code_with_exemption.
106+
result = VALUE #( ).
107+
ENDMETHOD.
108+
109+
ENDCLASS.

src/checks/y_check_constants_interface.clas.abap

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@ CLASS y_check_constants_interface DEFINITION PUBLIC INHERITING FROM y_check_base
33
METHODS constructor .
44

55
PROTECTED SECTION.
6-
METHODS execute_check REDEFINITION.
6+
METHODS inspect_statements REDEFINITION.
77
METHODS inspect_tokens REDEFINITION.
88

99
PRIVATE SECTION.
10-
DATA leading_structure TYPE sstruc.
1110
DATA has_something_else TYPE abap_bool VALUE abap_false.
1211

13-
METHODS check_leading_structure.
14-
1512
METHODS is_structure_empty IMPORTING structure TYPE sstruc
1613
RETURNING VALUE(result) TYPE abap_bool.
1714

18-
METHODS set_leading_structure IMPORTING structure TYPE sstruc.
15+
METHODS check_result IMPORTING structure TYPE sstruc.
1916

2017
ENDCLASS.
2118

@@ -39,24 +36,22 @@ CLASS Y_CHECK_CONSTANTS_INTERFACE IMPLEMENTATION.
3936
ENDMETHOD.
4037

4138

42-
METHOD execute_check.
43-
super->execute_check( ).
44-
check_leading_structure( ).
39+
METHOD inspect_statements.
40+
CHECK is_structure_empty( structure ) = abap_false.
41+
42+
has_something_else = abap_false.
43+
44+
super->inspect_statements( structure ).
45+
46+
check_result( structure ).
4547
ENDMETHOD.
4648

4749

4850
METHOD inspect_tokens.
49-
CHECK is_structure_empty( structure ) = abap_false.
50-
5151
CHECK statement-type <> scan_stmnt_type-comment.
5252
CHECK statement-type <> scan_stmnt_type-comment_in_stmnt.
5353
CHECK statement-type <> scan_stmnt_type-pragma.
5454

55-
IF leading_structure <> structure.
56-
check_leading_structure( ).
57-
set_leading_structure( structure ).
58-
ENDIF.
59-
6055
DATA(token) = get_token_abs( statement-from ).
6156

6257
IF token <> 'CONSTANTS'
@@ -70,23 +65,21 @@ CLASS Y_CHECK_CONSTANTS_INTERFACE IMPLEMENTATION.
7065
ENDMETHOD.
7166

7267

73-
METHOD check_leading_structure.
74-
CHECK leading_structure IS NOT INITIAL.
68+
METHOD check_result.
69+
CHECK has_something_else = abap_false.
7570

76-
DATA(statement_for_message) = ref_scan_manager->statements[ leading_structure-stmnt_from ].
71+
DATA(statement_for_message) = ref_scan_manager->statements[ structure-stmnt_from ].
7772

7873
DATA(check_configuration) = detect_check_configuration( statement_for_message ).
7974

8075
IF check_configuration IS INITIAL.
8176
RETURN.
8277
ENDIF.
8378

84-
IF has_something_else EQ abap_false.
85-
raise_error( statement_level = statement_for_message-level
86-
statement_index = leading_structure-stmnt_from
87-
statement_from = statement_for_message-from
88-
error_priority = check_configuration-prio ).
89-
ENDIF.
79+
raise_error( statement_level = statement_for_message-level
80+
statement_index = structure-stmnt_from
81+
statement_from = statement_for_message-from
82+
error_priority = check_configuration-prio ).
9083
ENDMETHOD.
9184

9285

@@ -95,10 +88,4 @@ CLASS Y_CHECK_CONSTANTS_INTERFACE IMPLEMENTATION.
9588
ENDMETHOD.
9689

9790

98-
METHOD set_leading_structure.
99-
leading_structure = structure.
100-
has_something_else = abap_false.
101-
ENDMETHOD.
102-
103-
10491
ENDCLASS.

0 commit comments

Comments
 (0)