T
- the type of result returned by the processorprivate static interface AnnotatedElementUtils.Processor<T>
Depending on the use case, a processor may choose to process(java.lang.reflect.AnnotatedElement, java.lang.annotation.Annotation, int) a single target annotation, multiple target annotations, or all annotations discovered by the currently executing search. The term "target" in this context refers to a matching annotation (i.e., a specific annotation type that was found during the search).
Returning a non-null value from the process(java.lang.reflect.AnnotatedElement, java.lang.annotation.Annotation, int)
method instructs the search algorithm to stop searching further;
whereas, returning null
from the process(java.lang.reflect.AnnotatedElement, java.lang.annotation.Annotation, int)
method
instructs the search algorithm to continue searching for additional
annotations. One exception to this rule applies to processors
that aggregate results. If an aggregating
processor returns a non-null value, that value will be added to the
list of aggregated results
and the search algorithm will continue.
Processors can optionally post-process
the result of the process(java.lang.reflect.AnnotatedElement, java.lang.annotation.Annotation, int)
method as the search algorithm
goes back down the annotation hierarchy from an invocation of
process(java.lang.reflect.AnnotatedElement, java.lang.annotation.Annotation, int)
that returned a non-null value down to the
AnnotatedElement
that was supplied as the starting point to
the search algorithm.
Modifier and Type | Method and Description |
---|---|
boolean |
aggregates()
Determine if this processor aggregates the results returned by
process(java.lang.reflect.AnnotatedElement, java.lang.annotation.Annotation, int) . |
boolean |
alwaysProcesses()
Determine if this processor always processes annotations regardless of
whether or not the target annotation has been found.
|
java.util.List<T> |
getAggregatedResults()
Get the list of results aggregated by this processor.
|
void |
postProcess(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.annotation.Annotation annotation,
T result)
Post-process the result returned by the
process(java.lang.reflect.AnnotatedElement, java.lang.annotation.Annotation, int) method. |
T |
process(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.annotation.Annotation annotation,
int metaDepth)
Process the supplied annotation.
|
T process(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.annotation.Annotation annotation, int metaDepth)
The supplied annotation will be an actual target annotation
that has been found by the search algorithm, unless this processor
is configured to always process
annotations in which case it may be some other annotation within an
annotation hierarchy. In the latter case, the metaDepth
will have a value greater than 0
. In any case, it is
up to concrete implementations of this method to decide what to
do with the supplied annotation.
The metaDepth
parameter represents the depth of the
annotation relative to the first annotated element in the
annotation hierarchy. For example, an annotation that is
present on a non-annotation element will have a depth
of 0; a meta-annotation will have a depth of 1; and a
meta-meta-annotation will have a depth of 2; etc.
annotatedElement
- the element that is annotated with the
supplied annotation, used for contextual logging; may be
null
if unknownannotation
- the annotation to processmetaDepth
- the meta-depth of the annotationnull
to continue
searching for additional annotationsvoid postProcess(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.annotation.Annotation annotation, T result)
process(java.lang.reflect.AnnotatedElement, java.lang.annotation.Annotation, int)
method.
The annotation
supplied to this method is an annotation
that is present in the annotation hierarchy, between the initial
AnnotatedElement
and an invocation of process(java.lang.reflect.AnnotatedElement, java.lang.annotation.Annotation, int)
that returned a non-null value.
annotatedElement
- the element that is annotated with the
supplied annotation, used for contextual logging; may be
null
if unknownannotation
- the annotation to post-processresult
- the result to post-processboolean alwaysProcesses()
true
if this processor always processes annotationsboolean aggregates()
process(java.lang.reflect.AnnotatedElement, java.lang.annotation.Annotation, int)
.
If this method returns true
, then getAggregatedResults()
must return a non-null value.
true
if this processor supports aggregated resultsgetAggregatedResults()
java.util.List<T> getAggregatedResults()
NOTE: the processor does not aggregate the results
itself. Rather, the search algorithm that uses this processor is
responsible for asking this processor if it aggregates()
results
and then adding the post-processed results to the list returned by this
method.
null
)aggregates()