Skip to content

Commit cbdd8fa

Browse files
authored
Merge pull request #303 from SAP/check-statement-position
solves #301
2 parents 4980292 + f0a285b commit cbdd8fa

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

src/checks/y_check_check_stmnt_position.clas.abap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,16 @@ CLASS y_check_check_stmnt_position IMPLEMENTATION.
7474
METHOD has_wrong_position.
7575
LOOP AT ref_scan_manager->statements ASSIGNING FIELD-SYMBOL(<statement>)
7676
FROM structure-stmnt_from TO structure-stmnt_to.
77+
IF <statement>-type = scan_stmnt_type-empty
78+
OR <statement>-type = scan_stmnt_type-comment
79+
OR <statement>-type = scan_stmnt_type-comment_in_stmnt.
80+
CONTINUE.
81+
ENDIF.
82+
7783
IF <statement>-number = check-number.
7884
RETURN.
7985
ENDIF.
86+
8087
IF is_not_relevant_token( get_token_abs( <statement>-from ) ) = abap_false.
8188
result = abap_true.
8289
RETURN.

src/checks/y_check_check_stmnt_position.clas.testclasses.abap

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,79 @@ CLASS ltc_constants IMPLEMENTATION.
463463
ENDMETHOD.
464464

465465
ENDCLASS.
466+
467+
468+
CLASS ltc_comments DEFINITION INHERITING FROM ltc_inline_data_declaration FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
469+
PROTECTED SECTION.
470+
METHODS get_code_without_issue REDEFINITION.
471+
ENDCLASS.
472+
473+
CLASS ltc_comments IMPLEMENTATION.
474+
475+
METHOD get_code_without_issue.
476+
result = VALUE #(
477+
( ' REPORT y_example. ' )
478+
479+
( ' CLASS y_example_class DEFINITION. ' )
480+
( ' PUBLIC SECTION. ' )
481+
( ' METHODS example. ' )
482+
( ' ENDCLASS. ' )
483+
484+
( ' CLASS y_example_class IMPLEMENTATION. ' )
485+
( ' METHOD example. ' )
486+
( ' " Comment ' )
487+
( '* Before ' )
488+
( ' CHECK sy-mandt = 100. ' )
489+
( ' ENDMETHOD. ' )
490+
( ' ENDCLASS. ' )
491+
).
492+
ENDMETHOD.
493+
494+
ENDCLASS.
495+
496+
497+
CLASS ltc_pseudo_comment DEFINITION INHERITING FROM ltc_inline_data_declaration FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
498+
PROTECTED SECTION.
499+
METHODS get_code_with_issue REDEFINITION.
500+
METHODS get_code_without_issue REDEFINITION.
501+
ENDCLASS.
502+
503+
CLASS ltc_pseudo_comment IMPLEMENTATION.
504+
505+
METHOD get_code_with_issue.
506+
result = VALUE #(
507+
( ' REPORT y_example. ' )
508+
509+
( ' CLASS y_example_class DEFINITION. ' )
510+
( ' PUBLIC SECTION. ' )
511+
( ' METHODS example. ' )
512+
( ' ENDCLASS. ' )
513+
514+
( ' CLASS y_example_class IMPLEMENTATION. ' )
515+
( ' METHOD example. ' )
516+
( ' me->example( ). "#EC SELF_REF ' )
517+
( ' CHECK sy-mandt = 100. ' )
518+
( ' ENDMETHOD. ' )
519+
( ' ENDCLASS. ' )
520+
).
521+
ENDMETHOD.
522+
523+
METHOD get_code_without_issue.
524+
result = VALUE #(
525+
( ' REPORT y_example. ' )
526+
527+
( ' CLASS y_example_class DEFINITION. ' )
528+
( ' PUBLIC SECTION. ' )
529+
( ' METHODS example. ' )
530+
( ' ENDCLASS. ' )
531+
532+
( ' CLASS y_example_class IMPLEMENTATION. ' )
533+
( ' METHOD example. ' )
534+
( ' CHECK sy-mandt = 100. "#EC CHECK_POSITION ' )
535+
( ' CHECK sy-mandt = 100. ' )
536+
( ' ENDMETHOD. ' )
537+
( ' ENDCLASS. ' )
538+
).
539+
ENDMETHOD.
540+
541+
ENDCLASS.

0 commit comments

Comments
 (0)