Skip to content

Commit

Permalink
103 update quick fix with as (#1141)
Browse files Browse the repository at this point in the history
  • Loading branch information
fidley authored Apr 3, 2024
1 parent 1504010 commit a8b53ac
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
49 changes: 38 additions & 11 deletions src/checks/zcl_aoc_check_103.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CLASS zcl_aoc_check_103 DEFINITION
message_code TYPE sci_errc,
oss_note TYPE c LENGTH 10,
END OF ty_message_detail.
CLASS-DATA gt_replace_proposalst TYPE tty_proposals READ-ONLY.
CLASS-DATA gt_replace_proposals TYPE tty_proposals READ-ONLY.
METHODS constructor.
METHODS check REDEFINITION.
CLASS-METHODS class_constructor.
Expand All @@ -47,6 +47,12 @@ CLASS zcl_aoc_check_103 DEFINITION
iv_replacement_object TYPE dd02v-viewref
RETURNING
VALUE(rs_message_detail) TYPE ty_message_detail.
METHODS check_table_as_used
IMPORTING
it_statement_tokens TYPE stokesx_tab
iv_tabix TYPE sy-tabix
RETURNING
VALUE(rv_table_as_used) TYPE abap_bool.
ENDCLASS.


Expand Down Expand Up @@ -80,8 +86,9 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION.
METHOD check.
DATA lv_include TYPE sobj_name.
DATA lv_tabname TYPE tabname.
DATA lv_table_as_used TYPE abap_bool.
DATA lt_statement_tokens TYPE stokesx_tab.
DATA ls_next LIKE LINE OF lt_statement_tokens.
DATA ls_next TYPE stokesx.
DATA ls_table_info TYPE dd02v.
DATA lv_position TYPE int4.
DATA lv_detail TYPE xstring.
Expand Down Expand Up @@ -115,6 +122,10 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION.
ENDIF.

lv_tabname = ls_next-str.

lv_table_as_used = check_table_as_used( it_statement_tokens = lt_statement_tokens
iv_tabix = sy-tabix + 1 ).

ls_table_info = get_table_info( lv_tabname ).


Expand All @@ -128,13 +139,14 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION.
ENDIF.

lv_detail = lcl_quickfix=>get_quick_fixes( iv_current_tab_name = lv_tabname
iv_new_tab_name = ls_table_info-viewref
iv_include = lv_include
iv_col = ls_next-col
iv_source = lt_source
iv_line = ls_next-row ).

lv_message_detail = get_message_detail( iv_tabname = lv_tabname
iv_new_tab_name = ls_table_info-viewref
iv_include = lv_include
iv_col = ls_next-col
iv_source = lt_source
iv_line = ls_next-row
iv_table_as_used = lv_table_as_used ).

lv_message_detail = get_message_detail( iv_tabname = lv_tabname
iv_replacement_object = ls_table_info-viewref ).
inform( p_sub_obj_name = lv_include
p_line = <ls_token>-row
Expand All @@ -155,6 +167,21 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION.
ENDLOOP.
ENDMETHOD.

METHOD check_table_as_used.
DATA ls_next TYPE stokesx.

READ TABLE it_statement_tokens INDEX iv_tabix INTO ls_next.
IF sy-subrc = 0 AND ls_next-str = 'AS'.
READ TABLE it_statement_tokens INDEX iv_tabix + 1 INTO ls_next.
IF sy-subrc = 0.
rv_table_as_used = abap_true.
ENDIF.
ENDIF.

ENDMETHOD.



METHOD get_tokens_for_statement.
FIELD-SYMBOLS <ls_token> LIKE LINE OF it_tokens.

Expand Down Expand Up @@ -191,14 +218,14 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION.
ENDMETHOD.

METHOD class_constructor.
gt_replace_proposalst = lcl_quickfix=>build_proposals_list( ).
gt_replace_proposals = lcl_quickfix=>build_proposals_list( ).
ENDMETHOD.


METHOD get_message_detail.
DATA lv_proposals TYPE ty_replace_proposal.

READ TABLE gt_replace_proposalst INTO lv_proposals WITH KEY from = iv_tabname sequence = 1.
READ TABLE gt_replace_proposals INTO lv_proposals WITH KEY from = iv_tabname sequence = 1.
IF sy-subrc = 0.
rs_message_detail-message_code = gc_code-table_has_replacement_proposal.
rs_message_detail-proposed_table = lv_proposals-to.
Expand Down
23 changes: 17 additions & 6 deletions src/checks/zcl_aoc_check_103.clas.locals_imp.abap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CLASS lcl_quickfix DEFINITION FINAL.
iv_source TYPE string_table
iv_line TYPE i
iv_col TYPE token_col
iv_table_as_used TYPE abap_bool
RETURNING
VALUE(rv_qf_xstring) TYPE xstring.

Expand All @@ -34,7 +35,8 @@ CLASS lcl_quickfix DEFINITION FINAL.
iv_current_tab_name TYPE tabname
iv_quickfixes TYPE REF TO object
iv_context TYPE any
iv_proposal TYPE zcl_aoc_check_103=>ty_replace_proposal.
iv_proposal TYPE zcl_aoc_check_103=>ty_replace_proposal
iv_table_as_used TYPE abap_bool.

ENDCLASS.

Expand Down Expand Up @@ -70,11 +72,12 @@ CLASS lcl_quickfix IMPLEMENTATION.
ASSIGN lo_context_interface->* TO <lv_context>.
<lv_context> ?= lo_context.

LOOP AT zcl_aoc_check_103=>gt_replace_proposalst ASSIGNING <lv_proposal> WHERE from = iv_current_tab_name.
LOOP AT zcl_aoc_check_103=>gt_replace_proposals ASSIGNING <lv_proposal> WHERE from = iv_current_tab_name.
add_new_quickfix( iv_current_tab_name = iv_current_tab_name
iv_quickfixes = lv_quickfixes
iv_context = <lv_context>
iv_proposal = <lv_proposal> ).
iv_quickfixes = lv_quickfixes
iv_context = <lv_context>
iv_proposal = <lv_proposal>
iv_table_as_used = iv_table_as_used ).
ENDLOOP.
CALL METHOD lv_quickfixes->('CREATE_QUICKFIX')
RECEIVING
Expand All @@ -100,7 +103,15 @@ CLASS lcl_quickfix IMPLEMENTATION.
DATA lv_quickfix_code TYPE c LENGTH 10.
DATA lv_current_tab_for_msg TYPE sy-msgv1.
DATA lv_new_tab_for_msg TYPE sy-msgv2.
DATA lv_proposal TYPE c LENGTH 255.

IF iv_table_as_used = abap_false.
CONCATENATE iv_proposal-to ' AS ' iv_proposal-from INTO lv_proposal RESPECTING BLANKS.
ELSE.
lv_proposal = iv_proposal-to.
ENDIF.

CONDENSE lv_proposal.

"Each quick-fix should have a unique code
CONCATENATE '001_' iv_proposal-sequence INTO lv_quickfix_code.
Expand All @@ -112,7 +123,7 @@ CLASS lcl_quickfix IMPLEMENTATION.
p_quickfix = lv_quickfix.
CALL METHOD lv_quickfix->('IF_CI_QUICKFIX_ABAP_ACTIONS~REPLACE_BY')
EXPORTING
p_new_code = iv_proposal-to
p_new_code = lv_proposal
p_context = iv_context.

CALL METHOD lv_quickfix->('IF_CI_QUICKFIX_SINGLE~ENABLE_AUTOMATIC_EXECUTION').
Expand Down

0 comments on commit a8b53ac

Please sign in to comment.