Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *&---------------------------------------------------------------------*
- *& Report Z_IMPL_FROM_DEF
- *&---------------------------------------------------------------------*
- *& Makes a class implementation skeleton from its definition
- *&---------------------------------------------------------------------*
- report z_impl_from_def.
- types: ty_methname_tab type standard table of seocpdname
- with non-unique default key,
- ty_mtdkey_tab type standard table of seomtdkey
- with non-unique key clsname.
- start-of-selection.
- perform start.
- * ---
- form start.
- data: lt_def type stringtab,
- lt_impl type stringtab,
- lo_ex type ref to cx_abap_error_analyze.
- try.
- perform :
- input_def changing lt_def,
- convert using lt_def changing lt_impl,
- output_impl using lt_impl.
- catch cx_abap_error_analyze into lo_ex.
- message lo_ex type 'I'.
- endtry.
- endform. "start
- * ---
- form input_def changing et_def type stringtab.
- perform edit_text
- using 'Section oder Klassen-Definition'(001)
- changing et_def.
- endform. "input_def
- * ---
- form convert using it_def type stringtab
- changing et_impl type stringtab.
- data: lv_classname type seoclsname,
- lt_methods type ty_mtdkey_tab.
- perform analyze_def using it_def changing lt_methods.
- perform make_impl using lt_methods
- changing et_impl.
- endform. "convert
- * ---
- form make_impl
- using it_methods type ty_mtdkey_tab
- changing et_impl type stringtab.
- field-symbols: <ls_methods> type seomtdkey.
- clear et_impl.
- loop at it_methods assigning <ls_methods>.
- at new clsname.
- perform make_class using <ls_methods>-clsname
- changing et_impl.
- endat.
- perform make_method using <ls_methods>
- changing et_impl.
- at end of clsname.
- perform make_endclass using <ls_methods>-clsname
- changing et_impl.
- endat.
- endloop.
- endform. "make_impl
- * ---
- form make_class using iv_classname type seoclsname
- changing ct_impl type stringtab.
- data: lv_classname type string,
- lv_line type string.
- lv_classname = iv_classname.
- check lv_classname is not initial.
- concatenate
- 'class ' lv_classname ' implementation.'
- into lv_line
- respecting blanks.
- append lv_line to ct_impl.
- endform. "make_class
- * ---
- form make_endclass using iv_classname type seoclsname
- changing ct_impl type stringtab.
- data: lv_classname type string,
- lv_line type string.
- lv_classname = iv_classname.
- check lv_classname is not initial.
- concatenate 'endclass. " ' lv_classname
- into lv_line
- respecting blanks.
- append lv_line to ct_impl.
- endform. "make_endclass
- * ---
- form make_method using is_methods type seomtdkey
- changing ct_impl type stringtab.
- data: lv_mtdname type string,
- lv_line type string.
- lv_mtdname = is_methods-mtdname.
- check lv_mtdname is not initial.
- concatenate ' method ' lv_mtdname '.' into lv_line respecting blanks.
- append lv_line to ct_impl.
- append ' endmethod.' to ct_impl.
- append initial line to ct_impl.
- endform. "make_endclass
- * ---
- form wrap_class_impl
- using iv_classname type seoclsname
- changing et_impl type stringtab.
- data: lv_line type string,
- lv_clsname type string.
- lv_clsname = iv_classname.
- translate lv_clsname to lower case.
- concatenate 'class ' lv_clsname ' implementation.' into lv_line respecting blanks.
- insert lv_line into et_impl index 1.
- * Clear last initial line, for esthetical reasons
- describe table et_impl lines sy-tfill.
- read table et_impl into lv_line index sy-tfill.
- if lv_line is initial.
- delete et_impl index sy-tfill.
- endif.
- append 'endclass.' to et_impl.
- endform. "wrap_class_impl
- * ---
- form output_impl using it_impl type stringtab.
- if it_impl is not initial.
- perform edit_text
- using 'Implementierungs-Rumpf'(002)
- changing it_impl.
- else.
- message 'Nichts zu übernehmen'(003) type 'S'.
- endif.
- endform. "output_impl
- * ---
- form analyze_def
- using
- it_def type stringtab
- changing
- et_methods type ty_mtdkey_tab
- raising cx_abap_error_analyze.
- data: lo_scanner type ref to zcl_scanner,
- ls_methods type seomtdkey,
- lv_interface type seoclsname,
- lv_first_token type string.
- field-symbols: <ls_stmnt> type sstmnt.
- clear et_methods.
- check it_def is not initial.
- create object lo_scanner
- exporting
- it_source = it_def.
- loop at lo_scanner->gt_stmnt assigning <ls_stmnt>.
- lv_first_token = lo_scanner->get_first_token( <ls_stmnt> ).
- case lv_first_token.
- when 'CLASS'.
- ls_methods-clsname = lo_scanner->get_second_token( <ls_stmnt> ).
- translate ls_methods-clsname to lower case.
- when 'METHODS' or 'CLASS-METHODS'.
- ls_methods-mtdname = lo_scanner->get_second_token( <ls_stmnt> ).
- translate ls_methods-mtdname to lower case.
- insert ls_methods into table et_methods.
- when 'INTERFACES'.
- lv_interface = lo_scanner->get_second_token( <ls_stmnt> ).
- perform add_methods_from_interface
- using ls_methods-clsname
- lv_interface
- changing et_methods.
- when 'ENDCLASS'.
- clear ls_methods-clsname.
- endcase.
- endloop.
- endform. "analyze_def
- * ---
- form add_methods_from_interface using iv_class_name type seoclsname
- iv_interface_name type csequence
- changing ct_methods type ty_mtdkey_tab.
- data: ls_key type seoclskey,
- ls_methods type seomtdkey,
- lt_methods type seoo_methods_r,
- lv_methname type seocpdname.
- field-symbols: <ls_method> type seoo_method_r.
- ls_methods-clsname = iv_class_name.
- ls_key-clsname = iv_interface_name.
- call function 'SEO_METHOD_READ_ALL'
- exporting
- cifkey = ls_key
- importing
- methods = lt_methods
- exceptions
- clif_not_existing = 1
- others = 2.
- if sy-subrc eq 0.
- loop at lt_methods assigning <ls_method>.
- concatenate <ls_method>-clsname '~' <ls_method>-cmpname into ls_methods-mtdname.
- translate ls_methods-mtdname to lower case.
- insert ls_methods into table ct_methods.
- endloop.
- endif.
- endform. "add_methods_from_interface
- * ---
- form edit_text using iv_title
- changing ct_text type stringtab.
- call function 'TERM_CONTROL_EDIT'
- exporting
- titel = iv_title
- tables
- textlines = ct_text
- exceptions
- user_cancelled = 1
- others = 2.
- if sy-subrc eq 1.
- leave to screen 0.
- elseif sy-subrc ne 0.
- message id sy-msgid type 'A' number sy-msgno
- with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
- endif.
- endform. "edit_text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement