Skip to content

Commit

Permalink
Quick Fix and Pragma for check 103 (#1136)
Browse files Browse the repository at this point in the history
Co-authored-by: abaplint[bot] <24845621+abaplint[bot]@users.noreply.github.com>
Co-authored-by: Lars Hvam <[email protected]>
  • Loading branch information
3 people authored Mar 19, 2024
1 parent d7e7de9 commit d703682
Show file tree
Hide file tree
Showing 4 changed files with 463 additions and 11 deletions.
3 changes: 2 additions & 1 deletion abaplint.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@
"checkForms": true,
"ignoreTestClasses": false,
"exclude": [
"zcl_aoc_check_69"
"zcl_aoc_check_69",
"zcl_aoc_check_103"
]
},
"method_parameter_names": {
Expand Down
103 changes: 93 additions & 10 deletions src/checks/zcl_aoc_check_103.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,55 @@ CLASS zcl_aoc_check_103 DEFINITION
CREATE PUBLIC.

PUBLIC SECTION.

CONSTANTS:
BEGIN OF gc_code,
table_has_replacement_object TYPE sci_errc VALUE '001',
table_has_replacement_object TYPE sci_errc VALUE '001',
table_has_replacement_proposal TYPE sci_errc VALUE '002',
END OF gc_code.

CONSTANTS gc_pseudo_comment TYPE sci_pcom VALUE 'AOC_103_SELECT_OK' ##NO_TEXT.
TYPES: BEGIN OF ty_replace_proposal,
from TYPE tabname,
sequence TYPE n LENGTH 1,
to TYPE tabname,
oss_note TYPE c LENGTH 10,
END OF ty_replace_proposal,
tty_proposals TYPE SORTED TABLE OF ty_replace_proposal WITH UNIQUE KEY from sequence.
TYPES: BEGIN OF ty_message_detail,
tabname TYPE tabname,
replacement_object TYPE tabname,
proposed_table TYPE tabname,
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.
METHODS constructor.
METHODS check REDEFINITION.
CLASS-METHODS class_constructor.

PRIVATE SECTION.
CLASS-DATA gt_proxy_objects TYPE HASHED TABLE OF dd02v WITH UNIQUE KEY tabname.

CLASS-DATA gt_proxy_objects TYPE HASHED TABLE OF dd02v WITH UNIQUE KEY tabname.
METHODS get_tokens_for_statement
IMPORTING is_statement TYPE sstmnt
it_tokens TYPE stokesx_tab
RETURNING VALUE(rt_tokens) TYPE stokesx_tab.

METHODS get_table_info
IMPORTING iv_tabname TYPE tabname
IMPORTING iv_tabname TYPE tabname
RETURNING VALUE(rs_table_info) TYPE dd02v.
METHODS get_message_detail
IMPORTING
iv_tabname TYPE tabname
iv_replacement_object TYPE dd02v-viewref
RETURNING
VALUE(rs_message_detail) TYPE ty_message_detail.
ENDCLASS.


CLASS zcl_aoc_check_103 IMPLEMENTATION.
METHOD constructor.
DATA: lv_message_text TYPE zcl_aoc_super=>ty_scimessage_text.
super->constructor( ).

version = '001'.
Expand All @@ -39,8 +64,17 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION.

enable_rfc( ).



insert_scimessage( iv_code = gc_code-table_has_replacement_object
iv_text = 'Table/View &1 has replacement object &2'(m01) ).
iv_text = 'Table/View &1 has replacement object &2'(m01)
iv_pcom = gc_pseudo_comment ).

insert_scimessage( iv_code = gc_code-table_has_replacement_proposal
iv_text = 'Table/View &1 has replacement object &2. Consider using &3 instead. OSS Note &4'(m02)
iv_pcom = gc_pseudo_comment ).


ENDMETHOD.

METHOD check.
Expand All @@ -49,11 +83,16 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION.
DATA lt_statement_tokens TYPE stokesx_tab.
DATA ls_next LIKE LINE OF lt_statement_tokens.
DATA ls_table_info TYPE dd02v.
DATA lv_position TYPE int4.
DATA lv_detail TYPE xstring.
DATA lv_message_detail TYPE ty_message_detail.
DATA lt_source TYPE string_table.
FIELD-SYMBOLS <ls_statement> LIKE LINE OF io_scan->statements.
FIELD-SYMBOLS <ls_token> LIKE LINE OF io_scan->tokens.
FIELD-SYMBOLS <ls_level> TYPE slevel.

LOOP AT io_scan->statements ASSIGNING <ls_statement>.

lv_position = sy-tabix.
READ TABLE io_scan->tokens ASSIGNING <ls_token> INDEX <ls_statement>-from.
IF sy-subrc <> 0.
CONTINUE.
Expand All @@ -74,20 +113,42 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
lv_tabname = ls_next-str.

lv_tabname = ls_next-str.
ls_table_info = get_table_info( lv_tabname ).



IF ls_table_info-viewref IS NOT INITIAL AND ls_table_info-viewref <> space.
lv_include = io_scan->get_include( <ls_statement>-level ).

READ TABLE io_scan->levels ASSIGNING <ls_level> WITH KEY name = lv_include.
IF sy-subrc = 0.
lt_source = get_source( <ls_level> ).
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_replacement_object = ls_table_info-viewref ).
inform( p_sub_obj_name = lv_include
p_line = <ls_token>-row
p_column = <ls_token>-col
p_position = lv_position
p_kind = mv_errty
p_test = myname
p_param_1 = lv_tabname
p_param_2 = ls_table_info-viewref
p_code = gc_code-table_has_replacement_object ).
p_param_1 = lv_message_detail-tabname
p_param_2 = lv_message_detail-replacement_object
p_param_3 = lv_message_detail-proposed_table
p_param_4 = lv_message_detail-oss_note
p_code = lv_message_detail-message_code
p_suppress = gc_pseudo_comment
p_detail = lv_detail ).

ENDIF.

Expand Down Expand Up @@ -128,4 +189,26 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION.
ENDIF.
INSERT rs_table_info INTO TABLE gt_proxy_objects.
ENDMETHOD.

METHOD class_constructor.
gt_replace_proposalst = 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.
IF sy-subrc = 0.
rs_message_detail-message_code = gc_code-table_has_replacement_proposal.
rs_message_detail-proposed_table = lv_proposals-to.
rs_message_detail-oss_note = lv_proposals-oss_note.
ELSE.
rs_message_detail-message_code = gc_code-table_has_replacement_object.
ENDIF.
rs_message_detail-tabname = iv_tabname.
rs_message_detail-replacement_object = iv_replacement_object.

ENDMETHOD.

ENDCLASS.
218 changes: 218 additions & 0 deletions src/checks/zcl_aoc_check_103.clas.locals_imp.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations

DEFINE add_replacement_proposal.
CLEAR lv_proposal.
lv_proposal-from = &1.
lv_proposal-sequence = &2.
lv_proposal-to = &3.
lv_proposal-oss_note = &4.
INSERT lv_proposal INTO TABLE rt_proposals.
END-OF-DEFINITION.

CLASS lcl_quickfix DEFINITION FINAL.

PUBLIC SECTION.
CLASS-METHODS get_quick_fixes
IMPORTING
iv_current_tab_name TYPE tabname
iv_new_tab_name TYPE tabname
iv_include TYPE program
iv_source TYPE string_table
iv_line TYPE i
iv_col TYPE token_col
RETURNING
VALUE(rv_qf_xstring) TYPE xstring.

CLASS-METHODS build_proposals_list RETURNING VALUE(rt_proposals) TYPE zcl_aoc_check_103=>tty_proposals.
PROTECTED SECTION.

PRIVATE SECTION.
CLASS-METHODS add_new_quickfix
IMPORTING
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.

ENDCLASS.

CLASS lcl_quickfix IMPLEMENTATION.


METHOD get_quick_fixes.
DATA: lv_quickfixes TYPE REF TO object.
DATA: lo_context TYPE REF TO object.
DATA: lo_context_interface TYPE REF TO data.
DATA: lv_quickfix TYPE REF TO object.
DATA: lv_quickfix_pragma TYPE REF TO object.
DATA: lv_column TYPE i.
FIELD-SYMBOLS: <lv_context> TYPE any.
FIELD-SYMBOLS: <lv_proposal> TYPE zcl_aoc_check_103=>ty_replace_proposal.

CALL METHOD ('CL_CI_QUICKFIX_CREATION')=>('CREATE_QUICKFIX_ALTERNATIVES')
RECEIVING
p_quickfix_alternatives = lv_quickfixes.


lv_column = iv_col.
CALL METHOD ('CL_CI_QUICKFIX_ABAP_CONTEXT')=>('CREATE_FROM_INCLUDE')
EXPORTING
p_include = iv_include
p_source = iv_source
p_line = iv_line
p_col = lv_column
RECEIVING
p_context = lo_context.

CREATE DATA lo_context_interface TYPE REF TO ('IF_CI_QUICKFIX_ABAP_CONTEXT').
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.
add_new_quickfix( iv_current_tab_name = iv_current_tab_name
iv_quickfixes = lv_quickfixes
iv_context = <lv_context>
iv_proposal = <lv_proposal> ).
ENDLOOP.
CALL METHOD lv_quickfixes->('CREATE_QUICKFIX')
RECEIVING
p_quickfix = lv_quickfix_pragma.

CALL METHOD lv_quickfix_pragma->('IF_CI_QUICKFIX_ABAP_ACTIONS~ADD_PSEUDO_COMMENT')
EXPORTING
p_pseudo_comment = zcl_aoc_check_103=>gc_pseudo_comment
p_context = <lv_context>.

TRY.
CALL METHOD lv_quickfixes->('EXPORT_TO_XSTRING')
RECEIVING
p_detail = rv_qf_xstring.
CATCH cx_root.
RETURN.
ENDTRY.
ENDMETHOD.

METHOD add_new_quickfix.

DATA lv_quickfix TYPE REF TO object.
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.


"Each quick-fix should have a unique code
CONCATENATE '001_' iv_proposal-sequence INTO lv_quickfix_code.

CALL METHOD iv_quickfixes->('CREATE_QUICKFIX')
EXPORTING
p_quickfix_code = lv_quickfix_code
RECEIVING
p_quickfix = lv_quickfix.
CALL METHOD lv_quickfix->('IF_CI_QUICKFIX_ABAP_ACTIONS~REPLACE_BY')
EXPORTING
p_new_code = iv_proposal-to
p_context = iv_context.

CALL METHOD lv_quickfix->('IF_CI_QUICKFIX_SINGLE~ENABLE_AUTOMATIC_EXECUTION').
CONCATENATE ' ' iv_current_tab_name INTO lv_current_tab_for_msg RESPECTING BLANKS.
CONCATENATE ' ' iv_proposal-to INTO lv_new_tab_for_msg RESPECTING BLANKS.
CALL METHOD lv_quickfix->('IF_CI_QUICKFIX_SINGLE~ADD_DOCU_FROM_MSGCLASS')
EXPORTING
p_msg_class = '00'
p_msg_number = '001'
p_msg_parameter1 = 'Replace'(m03)
p_msg_parameter2 = lv_current_tab_for_msg
p_msg_parameter3 = ' with'(m04)
p_msg_parameter4 = lv_new_tab_for_msg.

ENDMETHOD.



METHOD build_proposals_list.
DATA: lv_proposal TYPE zcl_aoc_check_103=>ty_replace_proposal.
add_replacement_proposal 'MARC' 1 'V_MARC_MD' '2206980'.
add_replacement_proposal 'MARC' 2 'NSDM_MIG_MARC' '2206980'.
add_replacement_proposal 'MARD' 1 'V_MARD_MD' '2206980'.
add_replacement_proposal 'MARD' 2 'NSDM_MIG_MARD' '2206980'.
add_replacement_proposal 'MKPF' 1 'NSDM_MIG_MKPF' '2206980'.
add_replacement_proposal 'MSEG' 1 'NSDM_MIG_MSEG' '2206980'.
add_replacement_proposal 'MCHB' 1 'V_MCHB_MD' '2206980'.
add_replacement_proposal 'MCHB' 2 'NSDM_MIG_MCHB' '2206980'.
add_replacement_proposal 'MKOL' 1 'V_MKOL_MD' '2206980'.
add_replacement_proposal 'MKOL' 2 'NSDM_MIG_MKOL' '2206980'.
add_replacement_proposal 'MSLB' 1 'V_MSLB_MD' '2206980'.
add_replacement_proposal 'MSLB' 2 'NSDM_MIG_MSLB' '2206980'.
add_replacement_proposal 'MSKA' 1 'V_MSKA_MD' '2206980'.
add_replacement_proposal 'MSKA' 2 'NSDM_MIG_MSKA' '2206980'.
add_replacement_proposal 'MSSA' 1 'NSDM_MIG_MSSA' '2206980'.
add_replacement_proposal 'MSPR' 1 'V_MSPR_MD' '2206980'.
add_replacement_proposal 'MSPR' 2 'NSDM_MIG_MSPR' '2206980'.
add_replacement_proposal 'MSSL' 1 'NSDM_MIG_MSSL' '2206980'.
add_replacement_proposal 'MSSQ' 1 'NSDM_MIG_MSSQ' '2206980'.
add_replacement_proposal 'MSKU' 1 'V_MSKU_MD' '2206980'.
add_replacement_proposal 'MSKU' 2 'NSDM_MIG_MSKU' '2206980'.
add_replacement_proposal 'MSTB' 1 'NSDM_MIG_MSTB' '2206980'.
add_replacement_proposal 'MSTE' 1 'NSDM_MIG_MSTE' '2206980'.
add_replacement_proposal 'MSTQ' 1 'NSDM_MIG_MSTQ' '2206980'.
add_replacement_proposal 'MCSD' 1 'MCSD_MD' '2206980'.
add_replacement_proposal 'MCSD' 2 'NSDM_MIG_MCSD' '2206980'.
add_replacement_proposal 'MCSS' 1 'MCSS_MD' '2206980'.
add_replacement_proposal 'MCSS' 2 'NSDM_MIG_MCSS' '2206980'.
add_replacement_proposal 'MSCD' 1 'MSCD_MD' '2206980'.
add_replacement_proposal 'MSCD' 2 'NSDM_MIG_MSCD' '2206980'.
add_replacement_proposal 'MSCS' 1 'MSCS_MD' '2206980'.
add_replacement_proposal 'MSCS' 2 'NSDM_MIG_MSCS' '2206980'.
add_replacement_proposal 'MSFD' 1 'MSFD_MD' '2206980'.
add_replacement_proposal 'MSFD' 2 'NSDM_MIG_MSFD' '2206980'.
add_replacement_proposal 'MSFS' 1 'MSFS_MD' '2206980'.
add_replacement_proposal 'MSFS' 2 'NSDM_MIG_MSFS' '2206980'.
add_replacement_proposal 'MSID' 1 'MSID_MD' '2206980'.
add_replacement_proposal 'MSID' 2 'NSDM_MIG_MSID' '2206980'.
add_replacement_proposal 'MSIS' 1 'MSIS_MD' '2206980'.
add_replacement_proposal 'MSIS' 2 'NSDM_MIG_MSIS' '2206980'.
add_replacement_proposal 'MSRD' 1 'MSRD_MD' '2206980'.
add_replacement_proposal 'MSRD' 2 'NSDM_MIG_MSRD' '2206980'.
add_replacement_proposal 'MSRS' 1 'MSRS_MD' '2206980'.
add_replacement_proposal 'MSRS' 2 'NSDM_MIG_MSRS' '2206980'.
add_replacement_proposal 'MARCH' 1 'NSDM_MIG_MARCH' '2206980'.
add_replacement_proposal 'MARDH' 1 'NSDM_MIG_MARDH' '2206980'.
add_replacement_proposal 'MCHBH' 1 'NSDM_MIG_MCHBH' '2206980'.
add_replacement_proposal 'MKOLH' 1 'NSDM_MIG_MKOLH' '2206980'.
add_replacement_proposal 'MSLBH' 1 'NSDM_MIG_MSLBH' '2206980'.
add_replacement_proposal 'MSKAH' 1 'NSDM_MIG_MSKAH' '2206980'.
add_replacement_proposal 'MSSAH' 1 'NSDM_MIG_MSSAH' '2206980'.
add_replacement_proposal 'MSPRH' 1 'NSDM_MIG_MSPRH' '2206980'.
add_replacement_proposal 'MSSQH' 1 'NSDM_MIG_MSSQH' '2206980'.
add_replacement_proposal 'MSKUH' 1 'NSDM_MIG_MSKUH' '2206980'.
add_replacement_proposal 'MSTBH' 1 'NSDM_MIG_MSTBH' '2206980'.
add_replacement_proposal 'MSTEH' 1 'NSDM_MIG_MSTEH' '2206980'.
add_replacement_proposal 'MSTQH' 1 'NSDM_MIG_MSTQH' '2206980'.
add_replacement_proposal 'MCSDH' 1 'NSDM_MIG_MCSDH' '2206980'.
add_replacement_proposal 'MCSSH' 1 'NSDM_MIG_MCSSH' '2206980'.
add_replacement_proposal 'MSCDH' 1 'NSDM_MIG_MSCDH' '2206980'.
add_replacement_proposal 'MSFDH' 1 'NSDM_MIG_MSFDH' '2206980'.
add_replacement_proposal 'MSIDH' 1 'NSDM_MIG_MSIDH' '2206980'.
add_replacement_proposal 'MSRDH' 1 'NSDM_MIG_MSRDH' '2206980'.
add_replacement_proposal 'EBEW' 1 'V_EBEW_MD' '2217299'.
add_replacement_proposal 'EBEW' 2 'MBVEBEWOLD' '2217299'.
add_replacement_proposal 'EBEWH' 1 'V_EBEWH_MD' '2217299'.
add_replacement_proposal 'EBEWH' 2 'MBVEBEWHOLD' '2217299'.
add_replacement_proposal 'MBEW' 1 'V_MBEW_MD' '2217299'.
add_replacement_proposal 'MBEW' 2 'MBVMBEWOLD' '2217299'.
add_replacement_proposal 'MBEWH' 1 'V_MBEWH_MD' '2217299'.
add_replacement_proposal 'MBEWH' 2 'MBVMBEWHOLD' '2217299'.
add_replacement_proposal 'OBEW' 1 'V_OBEW_MD' '2217299'.
add_replacement_proposal 'OBEW' 2 'MBVOBEWOLD' '2217299'.
add_replacement_proposal 'OBEWH' 1 'V_OBEWH_MD' '2217299'.
add_replacement_proposal 'OBEWH' 2 'MBVOBEWHOLD' '2217299'.
add_replacement_proposal 'QBEW' 1 'V_QBEW_MD' '2217299'.
add_replacement_proposal 'QBEW' 2 'MBVQBEWOLD' '2217299'.
add_replacement_proposal 'QBEWH' 1 'V_QBEWH_MD' '2217299'.
add_replacement_proposal 'QBEWH' 2 'MBVQBEWHOLD' '2217299'.

ENDMETHOD.

ENDCLASS.
Loading

0 comments on commit d703682

Please sign in to comment.