public class AnnotatedElementUtils extends Object
AnnotatedElements.
AnnotatedElementUtils defines the public API for Spring's
meta-annotation programming model with support for annotation attribute
overrides. If you do not need support for annotation attribute
overrides, consider using AnnotationUtils instead.
Note that the features of this class are not provided by the JDK's introspection facilities themselves.
Support for meta-annotations with attribute overrides in
composed annotations is provided by all variants of the
getAnnotationAttributes() and findAnnotationAttributes()
methods.
The search algorithms used by methods in this class follow either find or get semantics. Consult the Javadoc for each individual method for details on which search algorithm is used.
Get semantics are limited to searching for annotations
that are either present on an AnnotatedElement (i.e.,
declared locally or inherited)
or declared within the annotation hierarchy above an
AnnotatedElement.
Find semantics are much more exhaustive, providing get semantics plus support for the following:
@InheritedMethods following get semantics will honor the contract of
Java's @Inherited annotation except
that locally declared annotations (including custom composed annotations)
will be favored over inherited annotations. In contrast, methods following
find semantics will completely ignore the presence of
@Inherited since the find search algorithm manually
traverses type and method hierarchies and thereby implicitly supports
annotation inheritance without the need for @Inherited.
AliasFor,
AnnotationAttributes,
AnnotationUtils,
BridgeMethodResolver| Constructor and Description |
|---|
AnnotatedElementUtils() |
| Modifier and Type | Method and Description |
|---|---|
static AnnotationAttributes |
findAnnotationAttributes(AnnotatedElement element,
Class<? extends Annotation> annotationType)
Find the first annotation of the specified
annotationType within
the annotation hierarchy above the supplied element and
merge that annotation's attributes with matching attributes from
annotations in lower levels of the annotation hierarchy. |
static AnnotationAttributes |
findAnnotationAttributes(AnnotatedElement element,
String annotationType)
Find the first annotation of the specified
annotationType within
the annotation hierarchy above the supplied element and
merge that annotation's attributes with matching attributes from
annotations in lower levels of the annotation hierarchy. |
static AnnotationAttributes |
findAnnotationAttributes(AnnotatedElement element,
String annotationType,
boolean classValuesAsString,
boolean nestedAnnotationsAsMap)
Find the first annotation of the specified
annotationType within
the annotation hierarchy above the supplied element and
merge that annotation's attributes with matching attributes from
annotations in lower levels of the annotation hierarchy. |
static MultiValueMap<String,Object> |
getAllAnnotationAttributes(AnnotatedElement element,
String annotationType)
Get the annotation attributes of all annotations
of the specified
annotationType in the annotation hierarchy above
the supplied AnnotatedElement and store the results in a
MultiValueMap. |
static MultiValueMap<String,Object> |
getAllAnnotationAttributes(AnnotatedElement element,
String annotationType,
boolean classValuesAsString,
boolean nestedAnnotationsAsMap)
Get the annotation attributes of all annotations
of the specified
annotationType in the annotation hierarchy above
the supplied AnnotatedElement and store the results in a
MultiValueMap. |
static AnnotationAttributes |
getAnnotationAttributes(AnnotatedElement element,
String annotationType)
Get the first annotation of the specified
annotationType within
the annotation hierarchy above the supplied element and
merge that annotation's attributes with matching attributes from
annotations in lower levels of the annotation hierarchy. |
static AnnotationAttributes |
getAnnotationAttributes(AnnotatedElement element,
String annotationType,
boolean classValuesAsString,
boolean nestedAnnotationsAsMap)
Get the first annotation of the specified
annotationType within
the annotation hierarchy above the supplied element and
merge that annotation's attributes with matching attributes from
annotations in lower levels of the annotation hierarchy. |
static Set<String> |
getMetaAnnotationTypes(AnnotatedElement element,
Class<? extends Annotation> annotationType)
Get the fully qualified class names of all meta-annotation
types present on the annotation (of the specified
annotationType) on the supplied AnnotatedElement. |
static Set<String> |
getMetaAnnotationTypes(AnnotatedElement element,
String annotationType)
Get the fully qualified class names of all meta-annotation
types present on the annotation (of the specified
annotationType) on the supplied AnnotatedElement. |
static boolean |
hasMetaAnnotationTypes(AnnotatedElement element,
String annotationType)
Determine if the supplied
AnnotatedElement is annotated with
a composed annotation that is meta-annotated with an
annotation of the specified annotationType. |
static boolean |
isAnnotated(AnnotatedElement element,
String annotationType)
Determine if an annotation of the specified
annotationType
is present on the supplied AnnotatedElement or
within the annotation hierarchy above the specified element. |
public static Set<String> getMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType)
annotationType) on the supplied AnnotatedElement.
This method follows get semantics as described in the class-level Javadoc.
element - the annotated element; never nullannotationType - the annotation type on which to find
meta-annotations; never nullnull if not foundgetMetaAnnotationTypes(AnnotatedElement, String),
hasMetaAnnotationTypes(java.lang.reflect.AnnotatedElement, java.lang.String)public static Set<String> getMetaAnnotationTypes(AnnotatedElement element, String annotationType)
annotationType) on the supplied AnnotatedElement.
This method follows get semantics as described in the class-level Javadoc.
element - the annotated element; never nullannotationType - the fully qualified class name of the annotation
type on which to find meta-annotations; never null or emptynull if not foundgetMetaAnnotationTypes(AnnotatedElement, Class),
hasMetaAnnotationTypes(java.lang.reflect.AnnotatedElement, java.lang.String)public static boolean hasMetaAnnotationTypes(AnnotatedElement element, String annotationType)
AnnotatedElement is annotated with
a composed annotation that is meta-annotated with an
annotation of the specified annotationType.
This method follows get semantics as described in the class-level Javadoc.
element - the annotated element; never nullannotationType - the fully qualified class name of the meta-annotation
type to find; never null or emptytrue if a matching meta-annotation is presentgetMetaAnnotationTypes(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)public static boolean isAnnotated(AnnotatedElement element, String annotationType)
annotationType
is present on the supplied AnnotatedElement or
within the annotation hierarchy above the specified element.
If this method returns true, then getAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.String)
will return a non-null value.
This method follows get semantics as described in the class-level Javadoc.
element - the annotated element; never nullannotationType - the fully qualified class name of the annotation
type to find; never null or emptytrue if a matching annotation is presentpublic static AnnotationAttributes getAnnotationAttributes(AnnotatedElement element, String annotationType)
annotationType within
the annotation hierarchy above the supplied element and
merge that annotation's attributes with matching attributes from
annotations in lower levels of the annotation hierarchy.
This method delegates to getAnnotationAttributes(AnnotatedElement, String, boolean, boolean),
supplying false for classValuesAsString and nestedAnnotationsAsMap.
element - the annotated element; never nullannotationType - the fully qualified class name of the annotation
type to find; never null or emptyAnnotationAttributes, or null if
not foundgetAnnotationAttributes(AnnotatedElement, String, boolean, boolean),
findAnnotationAttributes(AnnotatedElement, Class),
findAnnotationAttributes(AnnotatedElement, String),
getAllAnnotationAttributes(AnnotatedElement, String)public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement element, String annotationType, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
annotationType within
the annotation hierarchy above the supplied element and
merge that annotation's attributes with matching attributes from
annotations in lower levels of the annotation hierarchy.
Attributes from lower levels in the annotation hierarchy override attributes of the same name from higher levels.
In contrast to getAllAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.String), the search
algorithm used by this method will stop searching the annotation
hierarchy once the first annotation of the specified
annotationType has been found. As a consequence, additional
annotations of the specified annotationType will be ignored.
This method follows get semantics as described in the class-level Javadoc.
element - the annotated element; never nullannotationType - the fully qualified class name of the annotation
type to find; never null or emptyclassValuesAsString - whether to convert Class references into
Strings or to preserve them as Class referencesnestedAnnotationsAsMap - whether to convert nested Annotation
instances into AnnotationAttributes maps or to preserve them
as Annotation instancesAnnotationAttributes, or null if
not foundfindAnnotationAttributes(AnnotatedElement, Class),
findAnnotationAttributes(AnnotatedElement, String),
findAnnotationAttributes(AnnotatedElement, String, boolean, boolean),
getAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean)public static AnnotationAttributes findAnnotationAttributes(AnnotatedElement element, Class<? extends Annotation> annotationType)
annotationType within
the annotation hierarchy above the supplied element and
merge that annotation's attributes with matching attributes from
annotations in lower levels of the annotation hierarchy.
This method delegates to findAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
supplying false for classValuesAsString and nestedAnnotationsAsMap.
element - the annotated element; never nullannotationType - the annotation type to find; never nullAnnotationAttributes, or null if
not foundfindAnnotationAttributes(AnnotatedElement, String),
findAnnotationAttributes(AnnotatedElement, String, boolean, boolean)public static AnnotationAttributes findAnnotationAttributes(AnnotatedElement element, String annotationType)
annotationType within
the annotation hierarchy above the supplied element and
merge that annotation's attributes with matching attributes from
annotations in lower levels of the annotation hierarchy.
This method delegates to findAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
supplying false for classValuesAsString and nestedAnnotationsAsMap.
element - the annotated element; never nullannotationType - the fully qualified class name of the annotation
type to find; never null or emptyAnnotationAttributes, or null if
not foundfindAnnotationAttributes(AnnotatedElement, Class),
findAnnotationAttributes(AnnotatedElement, String, boolean, boolean)public static AnnotationAttributes findAnnotationAttributes(AnnotatedElement element, String annotationType, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
annotationType within
the annotation hierarchy above the supplied element and
merge that annotation's attributes with matching attributes from
annotations in lower levels of the annotation hierarchy.
Attributes from lower levels in the annotation hierarchy override attributes of the same name from higher levels.
In contrast to getAllAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.String), the search
algorithm used by this method will stop searching the annotation
hierarchy once the first annotation of the specified
annotationType has been found. As a consequence, additional
annotations of the specified annotationType will be ignored.
This method follows find semantics as described in the class-level Javadoc.
element - the annotated element; never nullannotationType - the fully qualified class name of the annotation
type to find; never null or emptyclassValuesAsString - whether to convert Class references into
Strings or to preserve them as Class referencesnestedAnnotationsAsMap - whether to convert nested Annotation
instances into AnnotationAttributes maps or to preserve them
as Annotation instancesAnnotationAttributes, or null if
not foundfindAnnotationAttributes(AnnotatedElement, Class),
findAnnotationAttributes(AnnotatedElement, String),
getAnnotationAttributes(AnnotatedElement, String, boolean, boolean)public static MultiValueMap<String,Object> getAllAnnotationAttributes(AnnotatedElement element, String annotationType)
annotationType in the annotation hierarchy above
the supplied AnnotatedElement and store the results in a
MultiValueMap.
Note: in contrast to getAnnotationAttributes(AnnotatedElement, String),
this method does not support attribute overrides.
This method follows get semantics as described in the class-level Javadoc.
element - the annotated element; never nullannotationType - the fully qualified class name of the annotation
type to find; never null or emptyMultiValueMap keyed by attribute name, containing
the annotation attributes from all annotations found, or null
if not foundgetAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean)public static MultiValueMap<String,Object> getAllAnnotationAttributes(AnnotatedElement element, String annotationType, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
annotationType in the annotation hierarchy above
the supplied AnnotatedElement and store the results in a
MultiValueMap.
Note: in contrast to getAnnotationAttributes(AnnotatedElement, String),
this method does not support attribute overrides.
This method follows get semantics as described in the class-level Javadoc.
element - the annotated element; never nullannotationType - the fully qualified class name of the annotation
type to find; never null or emptyclassValuesAsString - whether to convert Class references into
Strings or to preserve them as Class referencesnestedAnnotationsAsMap - whether to convert nested Annotation
instances into AnnotationAttributes maps or to preserve them
as Annotation instancesMultiValueMap keyed by attribute name, containing
the annotation attributes from all annotations found, or null
if not found