Skip to content

Commit 35ff755

Browse files
committed
Lint
1 parent fe697ea commit 35ff755

14 files changed

+1765
-1930
lines changed

src/zcl_highlighter.clas.abap

Lines changed: 122 additions & 145 deletions
Large diffs are not rendered by default.
Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,61 @@
11
CLASS lcl_out DEFINITION.
2+
23
PUBLIC SECTION.
4+
35
CLASS-METHODS convert
46
IMPORTING
5-
!iv_string TYPE string
7+
!string TYPE string
68
RETURNING
7-
VALUE(rv_xstring) TYPE xstring
9+
VALUE(result) TYPE xstring
810
RAISING
911
zcx_abapgit_exception.
12+
1013
PRIVATE SECTION.
11-
CLASS-DATA go_conv_new TYPE REF TO object.
12-
CLASS-DATA go_conv_old TYPE REF TO object.
14+
15+
CLASS-DATA conv_new TYPE REF TO object.
16+
CLASS-DATA conv_old TYPE REF TO object.
17+
1318
ENDCLASS.
1419

1520
CLASS lcl_out IMPLEMENTATION.
21+
1622
METHOD convert.
17-
DATA lx_error TYPE REF TO cx_root.
18-
DATA lv_class TYPE string.
1923

20-
IF go_conv_new IS INITIAL AND go_conv_old IS INITIAL.
24+
IF conv_new IS INITIAL AND conv_old IS INITIAL.
2125
TRY.
2226
CALL METHOD ('CL_ABAP_CONV_CODEPAGE')=>create_out
2327
RECEIVING
24-
instance = go_conv_new.
28+
instance = conv_new.
2529
CATCH cx_sy_dyn_call_illegal_class.
26-
lv_class = 'CL_ABAP_CONV_OUT_CE'.
27-
CALL METHOD (lv_class)=>create
30+
DATA(class) = 'CL_ABAP_CONV_OUT_CE'.
31+
CALL METHOD (class)=>create
2832
EXPORTING
2933
encoding = 'UTF-8'
3034
RECEIVING
31-
conv = go_conv_old.
35+
conv = conv_old.
3236
ENDTRY.
3337
ENDIF.
3438

3539
TRY.
36-
IF go_conv_new IS NOT INITIAL.
37-
CALL METHOD go_conv_new->('IF_ABAP_CONV_OUT~CONVERT')
40+
IF conv_new IS NOT INITIAL.
41+
CALL METHOD conv_new->('IF_ABAP_CONV_OUT~CONVERT')
3842
EXPORTING
39-
source = iv_string
43+
source = string
4044
RECEIVING
41-
result = rv_xstring.
45+
result = result.
4246
ELSE.
43-
CALL METHOD go_conv_old->('CONVERT')
47+
CALL METHOD conv_old->('CONVERT')
4448
EXPORTING
45-
data = iv_string
49+
data = string
4650
IMPORTING
47-
buffer = rv_xstring.
51+
buffer = result.
4852
ENDIF.
4953
CATCH cx_parameter_invalid_range
5054
cx_sy_codepage_converter_init
5155
cx_sy_conversion_codepage
52-
cx_parameter_invalid_type INTO lx_error.
53-
zcx_abapgit_exception=>raise_with_text( lx_error ).
56+
cx_parameter_invalid_type INTO DATA(error).
57+
zcx_abapgit_exception=>raise_with_text( error ).
5458
ENDTRY.
5559
ENDMETHOD.
60+
5661
ENDCLASS.

src/zcl_highlighter_abap.clas.abap

Lines changed: 63 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ CLASS zcl_highlighter_abap DEFINITION
2828

2929
PROTECTED SECTION.
3030

31-
CLASS-DATA gt_keywords TYPE HASHED TABLE OF string WITH UNIQUE KEY table_line.
31+
CLASS-DATA keywords TYPE HASHED TABLE OF string WITH UNIQUE KEY table_line.
3232

3333
CLASS-METHODS init_keywords.
3434

3535
CLASS-METHODS is_keyword
3636
IMPORTING
37-
iv_chunk TYPE string
37+
chunk TYPE string
3838
RETURNING
39-
VALUE(rv_yes) TYPE abap_bool.
39+
VALUE(result) TYPE abap_bool.
4040

4141
METHODS order_matches REDEFINITION.
4242

@@ -62,27 +62,24 @@ CLASS zcl_highlighter_abap IMPLEMENTATION.
6262
super->constructor( ).
6363

6464
" Initialize instances of regular expression
65-
add_rule( iv_regex = c_regex-keyword
66-
iv_token = c_token-keyword
67-
iv_style = c_css-keyword ).
65+
add_rule( regex = c_regex-keyword
66+
token = c_token-keyword
67+
style = c_css-keyword ).
6868

69-
add_rule( iv_regex = c_regex-comment
70-
iv_token = c_token-comment
71-
iv_style = c_css-comment ).
69+
add_rule( regex = c_regex-comment
70+
token = c_token-comment
71+
style = c_css-comment ).
7272

73-
add_rule( iv_regex = c_regex-text
74-
iv_token = c_token-text
75-
iv_style = c_css-text ).
73+
add_rule( regex = c_regex-text
74+
token = c_token-text
75+
style = c_css-text ).
7676

7777
ENDMETHOD.
7878

7979

8080
METHOD init_keywords.
8181

82-
DATA: lv_keywords TYPE string,
83-
lt_keywords TYPE STANDARD TABLE OF string.
84-
85-
lv_keywords =
82+
DATA(list) =
8683
'&&|?TO|ABAP-SOURCE|ABBREVIATED|ABS|ABSTRACT|ACCEPT|ACCEPTING' &&
8784
'|ACCORDING|ACOS|ACTIVATION|ACTUAL|ADD|ADD-CORRESPONDING|ADJACENT|AFTER|ALIAS' &&
8885
'|ALIASES|ALIGN|ALL|ALLOCATE|ALPHA|ANALYSIS|ANALYZER|AND|ANY|APPEND|APPENDAGE' &&
@@ -195,114 +192,102 @@ CLASS zcl_highlighter_abap IMPLEMENTATION.
195192
'|TO_LOWER|TO_MIXED|TO_UPPER|UTCLONG_ADD|UTCLONG_CURRENT|UTCLONG_DIFF|XSDBOOL'.
196193

197194

198-
SPLIT lv_keywords AT '|' INTO TABLE lt_keywords.
195+
SPLIT list AT '|' INTO TABLE DATA(keyword_list).
196+
199197
" remove duplicates to avoid dumps when converting to a hash table
200-
SORT lt_keywords BY table_line ASCENDING.
201-
DELETE ADJACENT DUPLICATES FROM lt_keywords.
202-
gt_keywords = lt_keywords. " Hash table
198+
SORT keyword_list BY table_line ASCENDING.
199+
DELETE ADJACENT DUPLICATES FROM keyword_list.
200+
201+
keywords = keyword_list. " Hash table
203202

204203
ENDMETHOD.
205204

206205

207206
METHOD is_keyword.
208207

209-
DATA lv_str TYPE string.
210-
211-
lv_str = to_upper( iv_chunk ).
212-
READ TABLE gt_keywords WITH KEY table_line = lv_str TRANSPORTING NO FIELDS.
213-
rv_yes = boolc( sy-subrc = 0 ).
208+
result = xsdbool( line_exists( keywords[ table_line = to_upper( chunk ) ] ) ).
214209

215210
ENDMETHOD.
216211

217212

218213
METHOD order_matches.
219214

220-
DATA:
221-
lv_index TYPE sy-tabix,
222-
lv_line_len TYPE i,
223-
lv_prev_token TYPE c.
215+
FIELD-SYMBOLS <prev_match> TYPE ty_match.
224216

225-
FIELD-SYMBOLS:
226-
<ls_prev> TYPE ty_match,
227-
<ls_match> TYPE ty_match.
217+
SORT matches BY offset.
228218

229-
SORT ct_matches BY offset.
219+
DATA(line_len) = strlen( line ).
220+
DATA(prev_token) = ''.
230221

231-
lv_line_len = strlen( iv_line ).
232-
233-
LOOP AT ct_matches ASSIGNING <ls_match>.
234-
lv_index = sy-tabix.
222+
LOOP AT matches ASSIGNING FIELD-SYMBOL(<match>).
223+
DATA(index) = sy-tabix.
235224

236225
" Delete matches after open text match
237-
IF lv_prev_token = c_token-text AND <ls_match>-token <> c_token-text.
238-
DELETE ct_matches INDEX lv_index.
226+
IF prev_token = c_token-text AND <match>-token <> c_token-text.
227+
DELETE matches INDEX index.
239228
CONTINUE.
240229
ENDIF.
241230

242-
CASE <ls_match>-token.
231+
CASE <match>-token.
243232
WHEN c_token-keyword.
244-
IF <ls_match>-offset > 0
245-
AND substring( val = iv_line
246-
off = ( <ls_match>-offset - 1 )
233+
IF <match>-offset > 0
234+
AND substring( val = line
235+
off = ( <match>-offset - 1 )
247236
len = 1 ) CA '-<'.
248237
" Delete match if keyword is part of structure or field symbol
249-
DELETE ct_matches INDEX lv_index.
238+
DELETE matches INDEX index.
250239
CONTINUE.
251240
ENDIF.
252241

253242
WHEN c_token-comment.
254-
<ls_match>-length = lv_line_len - <ls_match>-offset.
255-
DELETE ct_matches FROM lv_index + 1.
243+
<match>-length = line_len - <match>-offset.
244+
DELETE matches FROM index + 1.
256245
CONTINUE.
257246

258247
WHEN c_token-text.
259-
<ls_match>-text_tag = substring( val = iv_line
260-
off = <ls_match>-offset
261-
len = <ls_match>-length ).
262-
IF lv_prev_token = c_token-text.
263-
IF <ls_match>-text_tag = <ls_prev>-text_tag.
264-
<ls_prev>-length = <ls_match>-offset + <ls_match>-length - <ls_prev>-offset.
265-
CLEAR lv_prev_token.
266-
ELSEIF <ls_prev>-text_tag = '}' AND <ls_match>-text_tag = '{'.
267-
<ls_prev>-length = <ls_match>-offset - <ls_prev>-offset - 1. " Shift } out of scope
268-
<ls_prev>-offset = <ls_prev>-offset + 1. " Shift { out of scope
269-
CLEAR lv_prev_token.
270-
ELSEIF <ls_match>-text_tag = '{'.
271-
<ls_prev>-length = <ls_match>-offset - <ls_prev>-offset.
272-
CLEAR lv_prev_token.
273-
ELSEIF <ls_prev>-text_tag = '}'.
274-
<ls_prev>-length = <ls_match>-offset - <ls_prev>-offset.
275-
<ls_prev>-offset = <ls_prev>-offset + 1. " Shift } out of scope
276-
CLEAR lv_prev_token.
248+
<match>-text_tag = substring( val = line
249+
off = <match>-offset
250+
len = <match>-length ).
251+
IF prev_token = c_token-text.
252+
IF <match>-text_tag = <prev_match>-text_tag.
253+
<prev_match>-length = <match>-offset + <match>-length - <prev_match>-offset.
254+
CLEAR prev_token.
255+
ELSEIF <prev_match>-text_tag = '}' AND <match>-text_tag = '{'.
256+
<prev_match>-length = <match>-offset - <prev_match>-offset - 1. " Shift } out of scope
257+
<prev_match>-offset = <prev_match>-offset + 1. " Shift { out of scope
258+
CLEAR prev_token.
259+
ELSEIF <match>-text_tag = '{'.
260+
<prev_match>-length = <match>-offset - <prev_match>-offset.
261+
CLEAR prev_token.
262+
ELSEIF <prev_match>-text_tag = '}'.
263+
<prev_match>-length = <match>-offset - <prev_match>-offset.
264+
<prev_match>-offset = <prev_match>-offset + 1. " Shift } out of scope
265+
CLEAR prev_token.
277266
ENDIF.
278-
DELETE ct_matches INDEX lv_index.
267+
DELETE matches INDEX index.
279268
CONTINUE.
280269
ENDIF.
281270

282271
ENDCASE.
283272

284-
lv_prev_token = <ls_match>-token.
285-
ASSIGN <ls_match> TO <ls_prev>.
273+
prev_token = <match>-token.
274+
ASSIGN <match> TO <prev_match>.
286275
ENDLOOP.
287276

288277
ENDMETHOD.
289278

290279

291280
METHOD parse_line. "REDEFINITION
292281

293-
DATA lv_index TYPE i.
294-
295-
FIELD-SYMBOLS <ls_match> LIKE LINE OF rt_matches.
296-
297-
rt_matches = super->parse_line( iv_line ).
282+
result = super->parse_line( line ).
298283

299284
" Remove non-keywords
300-
LOOP AT rt_matches ASSIGNING <ls_match> WHERE token = c_token-keyword.
301-
lv_index = sy-tabix.
302-
IF abap_false = is_keyword( substring( val = iv_line
303-
off = <ls_match>-offset
304-
len = <ls_match>-length ) ).
305-
DELETE rt_matches INDEX lv_index.
285+
LOOP AT result ASSIGNING FIELD-SYMBOL(<match>) WHERE token = c_token-keyword.
286+
DATA(tabix) = sy-tabix.
287+
IF NOT is_keyword( substring( val = line
288+
off = <match>-offset
289+
len = <match>-length ) ).
290+
DELETE result INDEX tabix.
306291
ENDIF.
307292
ENDLOOP.
308293

0 commit comments

Comments
 (0)