This code is useful to scan ABAP code.
Provide source code, and the parser will return structures, statements and tokens.
| CLASS zcl_ci_scan_service DEFINITION | |
| PUBLIC | |
| FINAL | |
| CREATE PUBLIC . | |
| PUBLIC SECTION. | |
| INTERFACES if_http_extension . | |
| PROTECTED SECTION. | |
| PRIVATE SECTION. | |
| ENDCLASS. | |
| CLASS zcl_ci_scan_service IMPLEMENTATION. | |
| METHOD if_http_extension~handle_request. | |
| DATA(method) = server->request->get_method( ). | |
| IF method NE 'POST'. | |
| server->response->set_header_field( name = 'Allow' value = 'POST' ). | |
| server->response->set_status( code = '405' reason = 'Method not allowed' ). | |
| RETURN. | |
| ENDIF. | |
| TRY. | |
| DATA(code_string) = server->request->get_cdata( ). | |
| SPLIT code_string AT cl_abap_char_utilities=>cr_lf INTO TABLE DATA(code_table). | |
| LOOP AT code_table ASSIGNING FIELD-SYMBOL(<code_line>). | |
| REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>newline IN <code_line> WITH ''. | |
| ENDLOOP. | |
| DATA(source) = cl_ci_source_include=>feed( p_include = code_table ). | |
| DATA(scan) = NEW cl_ci_scan( p_include = source ). | |
| IF scan->subrc EQ 0 OR | |
| scan->subrc EQ 1 . " subrc=1 means missing include, ignore | |
| DATA(tokens) = /ui2/cl_json=>serialize( | |
| data = scan->tokens | |
| pretty_name = /ui2/cl_json=>pretty_mode-camel_case | |
| compress = abap_true ). | |
| DATA(statements) = /ui2/cl_json=>serialize( | |
| data = scan->statements | |
| pretty_name = /ui2/cl_json=>pretty_mode-camel_case | |
| compress = abap_true ). | |
| DATA(structures) = /ui2/cl_json=>serialize( | |
| data = scan->structures | |
| pretty_name = /ui2/cl_json=>pretty_mode-camel_case | |
| compress = abap_true ). | |
| DATA(response_data) = |\{"tokens": { tokens }, "statements": { statements }, "structures": { structures }\}|. | |
| server->response->set_header_field( name = 'Content-Type' value = 'application/json; charset=UTF-8' ). | |
| server->response->set_cdata( data = response_data ). | |
| ELSE. | |
| server->response->set_status( code = '400' | |
| reason = |ABAP Source Scan Error: { CONV string( scan->message ) }| ). | |
| ENDIF. | |
| CATCH cx_root INTO DATA(exception). | |
| server->response->set_status( code = '400' | |
| reason = |ABAP Source Scan Error: { CONV string( exception->get_text( ) ) }| ). | |
| ENDTRY. | |
| ENDMETHOD. | |
| ENDCLASS. |
This code is useful to scan ABAP code.
Provide source code, and the parser will return structures, statements and tokens.