Skip to content

Commit

Permalink
Merge pull request #9 from flaiker/processor-impl
Browse files Browse the repository at this point in the history
Implement remaining processors
  • Loading branch information
fabianlupa committed Dec 26, 2016
2 parents b767075 + 998a81b commit c44532c
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 163 deletions.
49 changes: 28 additions & 21 deletions src/proc/zcl_aap_proc_attribute.clas.abap
@@ -1,45 +1,52 @@
"! Attribute processor
CLASS zcl_aap_proc_attribute DEFINITION
PUBLIC
FINAL
INHERITING FROM zcl_aap_proc_base
CREATE PRIVATE.
CREATE PRIVATE
GLOBAL FRIENDS zcl_aap_proc_object.

PUBLIC SECTION.
METHODS:
load_all REDEFINITION,
is_annotation_present_by_name REDEFINITION,
is_annotation_present_by_descr REDEFINITION,
get_annotation_by_name REDEFINITION,
get_annotation_by_descr REDEFINITION,
get_annotations REDEFINITION.
DATA:
"! Name of the containing class or interface
mv_containing_object_name TYPE abap_classname READ-ONLY,
"! Attribute description
ms_attribute_description TYPE abap_attrdescr READ-ONLY,
"! Attribute name in its containing object
mv_attribute_name TYPE abap_attrname READ-ONLY.
PROTECTED SECTION.
PRIVATE SECTION.
METHODS:
constructor IMPORTING is_attribute_description TYPE abap_attrdescr
iv_containing_object_name TYPE abap_classname.
ENDCLASS.



CLASS zcl_aap_proc_attribute IMPLEMENTATION.
METHOD load_all.

ENDMETHOD.
METHOD constructor.
super->constructor( ).

METHOD get_annotations.
ASSERT: iv_containing_object_name IS NOT INITIAL,
is_attribute_description IS NOT INITIAL.

mv_containing_object_name = iv_containing_object_name.
ms_attribute_description = is_attribute_description.
mv_attribute_name = is_attribute_description-name.
ENDMETHOD.

METHOD get_annotation_by_descr.

METHOD load_all ##NEEDED.
" Nothing to do here
ENDMETHOD.

METHOD get_annotation_by_name.

ENDMETHOD.

METHOD is_annotation_present_by_descr.

ENDMETHOD.

METHOD is_annotation_present_by_name.

METHOD get_annotations.
" TODO: Think of propagating the exception in some way
rt_annotations = get_resolver( )->get_annotations_for_attribute(
iv_containing_object_name = mv_containing_object_name
iv_attribute_name = mv_attribute_name
).
ENDMETHOD.
ENDCLASS.
103 changes: 78 additions & 25 deletions src/proc/zcl_aap_proc_base.clas.abap
@@ -1,3 +1,4 @@
"! Processor base class
CLASS zcl_aap_proc_base DEFINITION
PUBLIC
ABSTRACT
Expand All @@ -6,31 +7,33 @@ CLASS zcl_aap_proc_base DEFINITION
PUBLIC SECTION.
METHODS:
"! Check if an annotation is present by classname
"! @parameter iv_classname |
"! @parameter rv_present |
is_annotation_present_by_name ABSTRACT IMPORTING iv_classname TYPE abap_classname
RETURNING VALUE(rv_present) TYPE abap_bool,
"!
"! @parameter io_descr |
"! @parameter rv_present |
is_annotation_present_by_descr ABSTRACT IMPORTING io_descr TYPE REF TO cl_abap_classdescr
RETURNING VALUE(rv_present) TYPE abap_bool,
"!
"! @parameter iv_annotation_key |
"! @parameter ro_annotation |
"! @raising zcx_aap_illegal_argument |
get_annotation_by_name ABSTRACT IMPORTING iv_classname TYPE abap_classname
RETURNING VALUE(ro_annotation) TYPE REF TO zcl_aap_annotation_base
RAISING zcx_aap_illegal_argument,
"!
"! @parameter io_descr |
"! @parameter ro_annotation |
"! @raising zcx_aap_illegal_argument |
get_annotation_by_descr ABSTRACT IMPORTING io_descr TYPE REF TO cl_abap_classdescr
RETURNING VALUE(ro_annotation) TYPE REF TO zcl_aap_annotation_base
RAISING zcx_aap_illegal_argument,
"!
"! @parameter rt_annotations |
"! @parameter iv_classname | Annotation class name
"! @parameter rv_present | Annotation is present
is_annotation_present_by_name IMPORTING iv_classname TYPE abap_classname
RETURNING VALUE(rv_present) TYPE abap_bool,
"! Check if an annotation is present by descriptor
"! @parameter io_descr | Descriptor instance
"! @parameter rv_present | Annotation is present
"! @raising zcx_aap_illegal_argument | io_descr cannot be null
is_annotation_present_by_descr IMPORTING io_descr TYPE REF TO cl_abap_classdescr
RETURNING VALUE(rv_present) TYPE abap_bool
RAISING zcx_aap_illegal_argument,
"! Get an annotation instance by its name
"! @parameter iv_classname | Annotation class name
"! @parameter ro_annotation | Found annotation class instance
"! @raising zcx_aap_illegal_argument | Annotation class not present
get_annotation_by_name IMPORTING iv_classname TYPE abap_classname
RETURNING VALUE(ro_annotation) TYPE REF TO zcl_aap_annotation_base
RAISING zcx_aap_illegal_argument,
"! Get an annotation instance by descriptor
"! @parameter io_descr | Descriptor instance
"! @parameter ro_annotation | Found annotation class instance
"! @raising zcx_aap_illegal_argument | io_descr cannot be null or annotation not present
get_annotation_by_descr IMPORTING io_descr TYPE REF TO cl_abap_classdescr
RETURNING VALUE(ro_annotation) TYPE REF TO zcl_aap_annotation_base
RAISING zcx_aap_illegal_argument,
"! Get all annotations directly associated to this processor
"! @parameter rt_annotations | Associated annotations
get_annotations ABSTRACT RETURNING VALUE(rt_annotations) TYPE zif_aap_annotation_resolver=>gty_annotation_tab,
"! Force populate internal caches recursively (disables loading on demand)
load_all ABSTRACT.
Expand All @@ -57,4 +60,54 @@ CLASS zcl_aap_proc_base IMPLEMENTATION.
METHOD get_resolver.
ri_resolver = mi_resolver.
ENDMETHOD.

METHOD get_annotation_by_descr.
DATA(lt_annotations) = get_annotations( ).

zcx_aap_illegal_argument=>raise_if_nullpointer( iv_name = 'IO_DESCR'
io_ref = io_descr ) ##NO_TEXT.

TRY.
ro_annotation = lt_annotations[ descriptor = io_descr ]-instance.
CATCH cx_sy_itab_line_not_found INTO DATA(lx_ex).
MESSAGE e018(zaap) WITH io_descr->get_relative_name( ) INTO DATA(lv_msg).
RAISE EXCEPTION TYPE zcx_aap_illegal_argument
EXPORTING
is_textid = zcx_aap_illegal_argument=>gc_with_name_and_reason
ix_previous = lx_ex
iv_name = 'IO_DESCR'
iv_reason = lv_msg ##NO_TEXT.
ENDTRY.
ENDMETHOD.

METHOD get_annotation_by_name.
DATA(lt_annotations) = get_annotations( ).

TRY.
ro_annotation = lt_annotations[ classname = iv_classname ]-instance.
CATCH cx_sy_itab_line_not_found INTO DATA(lx_ex).
MESSAGE e018(zaap) WITH iv_classname INTO DATA(lv_msg).
RAISE EXCEPTION TYPE zcx_aap_illegal_argument
EXPORTING
is_textid = zcx_aap_illegal_argument=>gc_with_name_and_reason
ix_previous = lx_ex
iv_name = 'IV_CLASSNAME'
iv_reason = lv_msg
iv_value = iv_classname ##NO_TEXT.
ENDTRY.
ENDMETHOD.

METHOD is_annotation_present_by_descr.
DATA(lt_annotations) = get_annotations( ).

zcx_aap_illegal_argument=>raise_if_nullpointer( iv_name = 'IO_DESCR'
io_ref = io_descr ) ##NO_TEXT.

rv_present = boolc( line_exists( lt_annotations[ descriptor = io_descr ] ) ).
ENDMETHOD.

METHOD is_annotation_present_by_name.
DATA(lt_annotations) = get_annotations( ).
rv_present = boolc( line_exists( lt_annotations[ classname = iv_classname ] ) ).
ENDMETHOD.
ENDCLASS.
98 changes: 77 additions & 21 deletions src/proc/zcl_aap_proc_method.clas.abap
@@ -1,54 +1,110 @@
"! Method processor
CLASS zcl_aap_proc_method DEFINITION
PUBLIC
FINAL
INHERITING FROM zcl_aap_proc_base
CREATE PUBLIC.
CREATE PRIVATE
GLOBAL FRIENDS zcl_aap_proc_object.

PUBLIC SECTION.
TYPES:
BEGIN OF gty_parameter_proc,
parameter_name TYPE abap_parmname,
processor TYPE REF TO zcl_aap_proc_parameter,
END OF gty_parameter_proc,
gty_parameter_proc_tab TYPE SORTED TABLE OF gty_parameter_proc
WITH UNIQUE KEY parameter_name.
METHODS:
"!
"! @parameter ro_processor |
get_parameter_processor RETURNING VALUE(ro_processor) TYPE REF TO zcl_aap_proc_parameter,
"! Get all parameter processors
"! @parameter rt_processors | Parameter processors
get_parameter_processors RETURNING VALUE(rt_processors) TYPE gty_parameter_proc_tab,
"! Get parameter processor by name
"! @parameter iv_parameter_name | Parameter name
"! @parameter ro_processor | Found parameter processor
"! @raising zcx_aap_illegal_argument | Parameter does not exist
get_parameter_processor IMPORTING iv_parameter_name TYPE abap_parmname
RETURNING VALUE(ro_processor) TYPE REF TO zcl_aap_proc_parameter
RAISING zcx_aap_illegal_argument,
load_all REDEFINITION,
is_annotation_present_by_name REDEFINITION,
is_annotation_present_by_descr REDEFINITION,
get_annotation_by_name REDEFINITION,
get_annotation_by_descr REDEFINITION,
get_annotations REDEFINITION.
DATA:
mv_method_name TYPE abap_methname READ-ONLY.
"! Name of the containing class or interface
mv_containing_object_name TYPE abap_classname READ-ONLY,
"! Name of the method in its containing object
mv_method_name TYPE abap_methname READ-ONLY,
"! Method description
ms_method_description TYPE abap_methdescr READ-ONLY.
PROTECTED SECTION.
PRIVATE SECTION.
METHODS:
constructor IMPORTING is_methdescr TYPE abap_methdescr
iv_containing_object_name TYPE abap_classname,
load_parameters.
DATA:
mt_parameter_processor_cache TYPE gty_parameter_proc_tab.
ENDCLASS.



CLASS zcl_aap_proc_method IMPLEMENTATION.
METHOD load_all.
METHOD constructor.
super->constructor( ).

ENDMETHOD.

METHOD get_annotations.
ASSERT: is_methdescr IS NOT INITIAL,
iv_containing_object_name IS NOT INITIAL.

ms_method_description = is_methdescr.
mv_method_name = is_methdescr-name.
mv_containing_object_name = iv_containing_object_name.
ENDMETHOD.

METHOD get_annotation_by_descr.
METHOD load_all.

ENDMETHOD.

METHOD get_annotation_by_name.

METHOD get_annotations.
" TODO: Think of propagating the exception in some way
rt_annotations = get_resolver( )->get_annotations_for_method(
iv_containing_object_name = mv_containing_object_name
iv_method_name = mv_method_name
).
ENDMETHOD.

METHOD get_parameter_processor.
METHOD get_parameter_processors.
" On demand lazy loading of processors
IF lines( mt_parameter_processor_cache ) = 0.
load_parameters( ).
ENDIF.

rt_processors = mt_parameter_processor_cache.
ENDMETHOD.

METHOD is_annotation_present_by_descr.

METHOD get_parameter_processor.
DATA(lt_processors) = get_parameter_processors( ).

TRY.
ro_processor = lt_processors[ parameter_name = iv_parameter_name ]-processor.
CATCH cx_sy_itab_line_not_found INTO DATA(lx_ex).
MESSAGE e019(zaap) WITH iv_parameter_name INTO DATA(lv_reason).
RAISE EXCEPTION TYPE zcx_aap_illegal_argument
EXPORTING
is_textid = zcx_aap_illegal_argument=>gc_with_name_and_reason
ix_previous = lx_ex
iv_name = 'IV_PARAMETER_NAME'
iv_reason = lv_reason
iv_value = iv_parameter_name ##NO_TEXT.
ENDTRY.
ENDMETHOD.

METHOD is_annotation_present_by_name.

METHOD load_parameters.
LOOP AT ms_method_description-parameters ASSIGNING FIELD-SYMBOL(<ls_parameter>).
INSERT VALUE #( parameter_name = <ls_parameter>-name
processor = NEW zcl_aap_proc_parameter(
is_parameter_description = <ls_parameter>
iv_containing_object_name = mv_containing_object_name
iv_containing_method_name = mv_method_name
)
) INTO TABLE mt_parameter_processor_cache.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
2 changes: 1 addition & 1 deletion src/proc/zcl_aap_proc_method.clas.xml
Expand Up @@ -9,7 +9,7 @@
<DESCRIPT>Method processor</DESCRIPT>
<UUID/>
<CATEGORY>00</CATEGORY>
<EXPOSURE>2</EXPOSURE>
<EXPOSURE>0</EXPOSURE>
<STATE>1</STATE>
<RELEASE>0</RELEASE>
<AUTHOR/>
Expand Down

0 comments on commit c44532c

Please sign in to comment.