@@ -11,13 +11,15 @@ CLASS y_check_prefer_pragmas DEFINITION PUBLIC INHERITING FROM y_check_base CREA
11
11
pseudo_com TYPE slin_desc-pseudo_com,
12
12
END OF mapping .
13
13
14
+ TYPES : pseudo_comments TYPE SORTED TABLE OF mapping-pseudo_com WITH UNIQUE KEY table_line .
15
+
14
16
CLASS-DATA mappings TYPE TABLE OF mapping .
15
17
16
- METHODS extract_pseudo_comment IMPORTING statement TYPE sstmnt
17
- RETURNING value (result ) TYPE string .
18
+ METHODS get_pseudo_comments IMPORTING statement TYPE sstmnt
19
+ RETURNING VALUE (result ) TYPE pseudo_comments .
18
20
19
- METHODS to_pragma IMPORTING pseudo_comment TYPE string
20
- RETURNING value (result ) TYPE string .
21
+ METHODS get_mapping IMPORTING pseudo_comments TYPE pseudo_comments
22
+ RETURNING VALUE (result ) LIKE mappings .
21
23
22
24
ENDCLASS .
23
25
@@ -35,60 +37,60 @@ CLASS y_check_prefer_pragmas IMPLEMENTATION.
35
37
settings-documentation = | { c_docs_path-checks } prefer-pragmas-to-pseudo-comments.md| .
36
38
37
39
IF mappings IS INITIAL .
38
- SELECT pragma, pseudo_com FROM slin_desc INTO CORRESPONDING FIELDS OF TABLE @mappings.
40
+ SELECT DISTINCT pragma, pseudo_com FROM slin_desc INTO CORRESPONDING FIELDS OF TABLE @mappings.
39
41
ENDIF .
40
42
41
43
set_check_message( 'Change the &1 to &2' ).
42
44
ENDMETHOD .
43
45
44
46
45
47
METHOD inspect_tokens .
46
- DATA (pseudo_comment ) = extract_pseudo_comment ( statement ).
48
+ DATA (pseudo_comments ) = get_pseudo_comments ( statement ).
47
49
48
- IF pseudo_comment IS INITIAL .
50
+ IF lines ( pseudo_comments ) = 0 .
49
51
RETURN .
50
52
ENDIF .
51
53
52
- DATA (pragma ) = to_pragma( pseudo_comment ).
54
+ DATA (mapping_to_pragmas ) = get_mapping( pseudo_comments ).
53
55
54
- IF pragma IS INITIAL .
56
+ IF lines ( mapping_to_pragmas ) = 0 .
55
57
RETURN .
56
58
ENDIF .
57
59
58
60
DATA (check_configuration ) = detect_check_configuration( statement ).
59
61
60
- pragma = | ## { pragma } | .
61
-
62
- raise_error( statement_level = statement-level
63
- statement_index = index
64
- statement_from = statement-from
65
- check_configuration = check_configuration
66
- parameter_01 = pseudo_comment
67
- parameter_02 = pragma ) .
62
+ LOOP AT mapping_to_pragmas ASSIGNING FIELD-SYMBOL ( <mapping> ) .
63
+ raise_error( statement_level = statement-level
64
+ statement_index = index
65
+ statement_from = statement-from
66
+ check_configuration = check_configuration
67
+ parameter_01 = | #EC { <mapping>-pseudo_com } |
68
+ parameter_02 = | ## { <mapping>-pragma } | ).
69
+ ENDLOOP .
68
70
ENDMETHOD .
69
71
70
72
71
- METHOD extract_pseudo_comment .
72
- LOOP AT ref_scan->tokens ASSIGNING FIELD-SYMBOL ( <token> )
73
+ METHOD get_pseudo_comments .
74
+ LOOP AT ref_scan->tokens INTO token_wa
73
75
FROM statement-from TO statement-to
74
- WHERE type = scan_token_type-comment.
75
- IF <token> -str CS '"#EC' .
76
- result = <token> -str.
77
- RETURN .
78
- ENDIF .
76
+ WHERE type = scan_token_type-comment
77
+ AND str CS '#EC ' .
78
+ REPLACE ALL OCCURRENCES OF `"#EC ` IN token_wa-str WITH `#EC ` .
79
+ REPLACE ALL OCCURRENCES OF ` #EC` IN token_wa-str WITH '#EC' .
80
+ REPLACE ALL OCCURRENCES OF `#EC ` IN token_wa-str WITH '#EC' .
81
+ SPLIT token_wa-str AT space INTO TABLE DATA (pseudo_comments ).
82
+ LOOP AT pseudo_comments ASSIGNING FIELD-SYMBOL (<pseudo_comment> )
83
+ WHERE table_line CS '#EC' .
84
+ REPLACE ALL OCCURRENCES OF '#EC' IN <pseudo_comment> WITH '' .
85
+ APPEND <pseudo_comment> TO result .
86
+ ENDLOOP .
79
87
ENDLOOP .
80
88
ENDMETHOD .
81
89
82
90
83
- METHOD to_pragma .
84
- TRY .
85
- DATA (text ) = pseudo_comment.
86
- REPLACE '"#EC' IN text WITH '' .
87
- CONDENSE text .
88
- result = mappings[ pseudo_com = text ]-pragma.
89
- CATCH cx_sy_itab_line_not_found.
90
- RETURN .
91
- ENDTRY .
91
+ METHOD get_mapping .
92
+ result = FILTER #( mappings IN pseudo_comments WHERE pseudo_com = table_line ).
92
93
ENDMETHOD .
93
94
95
+
94
96
ENDCLASS .
0 commit comments