@@ -3,26 +3,22 @@ CLASS y_check_comment_usage DEFINITION PUBLIC INHERITING FROM y_check_base CREAT
3
3
METHODS constructor.
4
4
5
5
PROTECTED SECTION .
6
- METHODS execute_check REDEFINITION .
6
+ METHODS inspect_statements REDEFINITION .
7
7
METHODS inspect_tokens REDEFINITION .
8
8
9
9
PRIVATE SECTION .
10
- DATA leading_structure TYPE sstruc.
11
-
12
10
DATA abs_statement_number TYPE i VALUE 0 .
13
11
DATA comment_number TYPE i VALUE 0 .
14
- DATA percentage_of_comments TYPE decfloat16 VALUE 0 .
15
12
DATA is_function_module TYPE abap_bool .
16
13
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.
19
17
20
18
METHODS is_code_disabled IMPORTING structure TYPE sstruc
21
19
statement TYPE sstmnt
22
20
RETURNING VALUE (result ) TYPE abap_bool .
23
21
24
- METHODS set_leading_structure IMPORTING structure TYPE sstruc.
25
-
26
22
ENDCLASS .
27
23
28
24
@@ -39,26 +35,23 @@ CLASS y_check_comment_usage IMPLEMENTATION.
39
35
40
36
relevant_statement_types = VALUE #( BASE relevant_statement_types
41
37
( scan_struc_stmnt_type-class_definition )
42
- ( scan_struc_stmnt_type-class_implementation )
43
38
( scan_struc_stmnt_type-interface ) ).
44
39
45
40
set_check_message( 'Percentage of comments must be lower than &3% of the productive code! (&2%>=&3%) (&1 lines found)' ).
46
41
ENDMETHOD .
47
42
48
43
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 .
53
47
48
+ super ->inspect_statements( structure ).
54
49
55
- METHOD inspect_tokens .
50
+ check_result( structure ).
51
+ ENDMETHOD .
56
52
57
- IF leading_structure <> structure .
58
- check_leading_structure( ).
59
- set_leading_structure( structure ).
60
- ENDIF .
61
53
54
+ METHOD inspect_tokens .
62
55
DATA (code_disabled ) = is_code_disabled( statement = statement
63
56
structure = structure ).
64
57
@@ -75,7 +68,6 @@ CLASS y_check_comment_usage IMPLEMENTATION.
75
68
LOOP AT ref_scan_manager->tokens ASSIGNING FIELD-SYMBOL (<token> )
76
69
FROM statement-from TO statement-to
77
70
WHERE type EQ scan_token_type-comment.
78
-
79
71
IF strlen ( <token> -str ) GE 2 AND NOT
80
72
( <token> -str+0 (2 ) EQ | *"| OR
81
73
<token> -str+0 (2 ) EQ | "!| OR
@@ -87,41 +79,39 @@ CLASS y_check_comment_usage IMPLEMENTATION.
87
79
comment_number = comment_number + 1 .
88
80
ENDIF .
89
81
ENDLOOP .
90
-
91
82
ENDMETHOD .
92
83
93
84
94
- METHOD check_leading_structure .
85
+ METHOD check_result .
86
+ DATA (percentage_of_comments ) = get_percentage_of_comments( ).
95
87
96
- CHECK leading_structure IS NOT INITIAL .
88
+ DATA ( statement_for_message ) = ref_scan_manager->statements[ structure-stmnt_from ] .
97
89
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
105
91
statement = statement_for_message ).
106
92
107
93
IF check_configuration IS INITIAL .
108
94
RETURN .
109
95
ENDIF .
110
96
111
97
raise_error( statement_level = statement_for_message-level
112
- statement_index = leading_structure -stmnt_from
98
+ statement_index = structure -stmnt_from
113
99
statement_from = statement_for_message-from
114
100
error_priority = check_configuration-prio
115
101
parameter_01 = | { comment_number } |
116
102
parameter_02 = | { percentage_of_comments } |
117
103
parameter_03 = | { check_configuration-threshold } | ).
118
-
119
104
ENDMETHOD .
120
105
121
106
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 ).
125
115
ENDMETHOD .
126
116
127
117
@@ -138,13 +128,4 @@ CLASS y_check_comment_usage IMPLEMENTATION.
138
128
ENDMETHOD .
139
129
140
130
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
-
150
131
ENDCLASS .
0 commit comments