public abstract class AnnotationUtils extends Object
Modifier and Type | Field and Description |
---|---|
static boolean |
ADD_ALL
Boolean specifying that a
findAnnotationAttributes(AnnotatedElement, String, boolean) invocation should
contain all attributes of the target annotation recursively taken into account attributes of other annotations
the target is present on. |
static boolean |
OVERRIDE_ONLY
Boolean specifying that a
findAnnotationAttributes(AnnotatedElement, String, boolean) invocation should
only contain the exact attributes of the target annotation, overridden by identical attributes on meta-annotated
annotations. |
Modifier and Type | Method and Description |
---|---|
static <T> Optional<T> |
findAnnotationAttribute(AnnotatedElement element,
Class<? extends Annotation> annotationType,
String attributeName)
Find the
attributeName of an annotation of type annotationType on the given element . |
static Optional<Map<String,Object>> |
findAnnotationAttributes(AnnotatedElement element,
Class<? extends Annotation> annotationType)
Find the attributes of an annotation of type
annotationType on the given element . |
static Optional<Map<String,Object>> |
findAnnotationAttributes(AnnotatedElement element,
Class<? extends Annotation> annotationType,
boolean overrideOnly)
Find the attributes of an annotation of type
annotationType on the given element . |
static Optional<Map<String,Object>> |
findAnnotationAttributes(AnnotatedElement element,
String annotationName)
Find the attributes of an annotation with given
annotationName on the given element . |
static Optional<Map<String,Object>> |
findAnnotationAttributes(AnnotatedElement element,
String annotationName,
boolean overrideOnly)
Find the attributes of an annotation with given
annotationName on the given element . |
static boolean |
isAnnotatedWith(Class<? extends Annotation> target,
Class<? extends Annotation> subject,
Set<Class<? extends Annotation>> annotatedWithSubject,
Set<Class<? extends Annotation>> visited)
|
static boolean |
isAnnotationPresent(AnnotatedElement element,
Class<? extends Annotation> annotationType)
Indicates whether an annotation of given
annotationType is present on the given element ,
considering that the given annotationType may be present as a meta annotation on any other annotation on
that element. |
static boolean |
isAnnotationPresent(AnnotatedElement element,
String annotationType)
Indicates whether an annotation with given
annotationType is present on the given element ,
considering that the given annotationType may be present as a meta annotation on any other annotation on
that element. |
public static final boolean OVERRIDE_ONLY
findAnnotationAttributes(AnnotatedElement, String, boolean)
invocation should
only contain the exact attributes of the target annotation, overridden by identical attributes on meta-annotated
annotations.public static final boolean ADD_ALL
findAnnotationAttributes(AnnotatedElement, String, boolean)
invocation should
contain all attributes of the target annotation recursively taken into account attributes of other annotations
the target is present on.public static boolean isAnnotationPresent(AnnotatedElement element, Class<? extends Annotation> annotationType)
annotationType
is present on the given element
,
considering that the given annotationType
may be present as a meta annotation on any other annotation on
that element.element
- The element to inspectannotationType
- The type of annotation to findtrue
if such annotation is present.public static boolean isAnnotationPresent(AnnotatedElement element, String annotationType)
annotationType
is present on the given element
,
considering that the given annotationType
may be present as a meta annotation on any other annotation on
that element.element
- The element to inspectannotationType
- The name of the annotation to findtrue
if such annotation is present.public static Optional<Map<String,Object>> findAnnotationAttributes(AnnotatedElement element, Class<? extends Annotation> annotationType)
annotationType
on the given element
. The returned
optional has a value present if the annotation has been found, either directly on the element
, or as a
meta-annotation.
The map of attributes contains all the attributes found on the annotation, as well as attributes of any annotations on which the targeted annotation was placed (directly, or indirectly).
Note that the value
property of annotations is reported as the simple class name (lowercase first
character) of the annotation. This allows specific attribute overrides for annotations that have multiple
meta-annotation with the value
property.
element
- The element for find the annotation onannotationType
- The type of the annotation to findpublic static Optional<Map<String,Object>> findAnnotationAttributes(AnnotatedElement element, Class<? extends Annotation> annotationType, boolean overrideOnly)
annotationType
on the given element
. The returned
optional has a value present if the annotation has been found, either directly on the element
, or as a
meta-annotation.
The map of attributes contains all the attributes found on the annotation. The overrideOnly
parameter
defines whether all attributes of any annotation on which the targeted annotation was placed (directly, or
indirectly) should be included. For OVERRIDE_ONLY
, only attribute overrides will be added on top of
that, whereas for ADD_ALL
all attributes on any meta-annotated level will be included in the result.
Note that the value
property of annotations is reported as the simple class name (lowercase first
character) of the annotation. This allows specific attribute overrides for annotations that have multiple
meta-annotation with the value
property.
element
- the element for find the annotation onannotationType
- the type of the annotation to findoverrideOnly
- boolean
defining whether or not to only take attribute overrides from
meta-annotations into account for the result or to include all attributes from every levelpublic static Optional<Map<String,Object>> findAnnotationAttributes(AnnotatedElement element, String annotationName)
annotationName
on the given element
. The returned
optional has a value present if the annotation has been found, either directly on the element
, or as a
meta-annotation.
The map of attributes contains all the attributes found on the annotation, as well as attributes of any annotations on which the targeted annotation was placed (directly, or indirectly).
element
- The element for find the annotation onannotationName
- The name of the annotation to findpublic static Optional<Map<String,Object>> findAnnotationAttributes(AnnotatedElement element, String annotationName, boolean overrideOnly)
annotationName
on the given element
. The returned
optional has a value present if the annotation has been found, either directly on the element
, or as a
meta-annotation.
The map of attributes contains all the attributes found on the annotation. The overrideOnly
parameter
defines whether all attributes of any annotation on which the targeted annotation was placed (directly, or
indirectly) should be included. For OVERRIDE_ONLY
, only attribute overrides will be added on top of
that, whereas for ADD_ALL
all attributes on any meta-annotated level will be included in the result.
Note that the value
property of annotations is reported as the simple class name (lowercase first
character) of the annotation. This allows specific attribute overrides for annotations that have multiple
meta-annotation with the value
property.
element
- the element for find the annotation onannotationName
- the name of the annotation to findoverrideOnly
- boolean
defining whether or not to only take attribute overrides from
meta-annotations into account for the result or to include all attributes from every levelpublic static <T> Optional<T> findAnnotationAttribute(AnnotatedElement element, Class<? extends Annotation> annotationType, String attributeName)
attributeName
of an annotation of type annotationType
on the given element
. The
returned optional has a value present if the annotation has been found, either directly on the element
,
or as a meta-annotation, if the named attribute exist.element
- the element to find the annotation onannotationType
- the type of the annotation to findattributeName
- the name of the attribute to findpublic static boolean isAnnotatedWith(Class<? extends Annotation> target, Class<? extends Annotation> subject, Set<Class<? extends Annotation>> annotatedWithSubject, Set<Class<? extends Annotation>> visited)
target
annotation Class
is meta-annotated with the given subject
. If this is the case for the target
itself or any meta-annotation on any level of the target
, true
will be returned.
Any Annotation
classes which are directly annotated or meta-annotated with the given subject
will
be stored in the annotatedWithSubject
Set
. The visited
Set
is used to ignore
annotations which have already been validated.
target
- the annotation Class
to validate if it is annotated with the given subject
subject
- the annotation Class
to check whether it is present on the given target
, directly or through meta-annotationsannotatedWithSubject
- a Set
to store all class' in which are annotated with the subject
,
either directly or through meta-annotationsvisited
- a Set
containing all annotation class' which have been visited in the process
to overcome an endless validation looptrue
if the target
or any meta-annotations of the target
are annotated with the
subject
, false
otherwiseCopyright © 2010–2024. All rights reserved.