public abstract class AnnotationUtils
extends java.lang.Object
Note that most of the features of this class are not provided by the JDK's introspection facilities themselves.
As a general rule for runtime-retained annotations (e.g. for transaction
control, authorization, or service exposure), always use the lookup methods
on this class (e.g., findAnnotation(Method, Class)
,
getAnnotation(Method, Class)
, and getAnnotations(Method)
)
instead of the plain annotation lookup methods in the JDK. You can still
explicitly choose between a get lookup on the given class level only
(getAnnotation(Method, Class)
) and a find lookup in the entire
inheritance hierarchy of the given method (findAnnotation(Method, Class)
).
AnnotatedElement
(in Java 8).
An annotation is meta-present on an element if the annotation
is declared as a meta-annotation on some other annotation which is
present on the element. Annotation A
is meta-present
on another annotation if A
is either directly present or
meta-present on the other annotation.
Most find*()
methods and some get*()
methods in this
class provide support for finding annotations used as meta-annotations.
Consult the Javadoc for each method in this class for details. For support
for meta-annotations with attribute overrides in
composed annotations, use AnnotatedElementUtils
instead.
All public methods in this class that return annotations, arrays of
annotations, or AnnotationAttributes
transparently support attribute
aliases configured via @AliasFor
. Consult the various
synthesizeAnnotation*(..)
methods for details.
The search algorithms used by methods in this class stop searching for an annotation once the first annotation of the specified type has been found. As a consequence, additional annotations of the specified type will be silently ignored.
AliasFor
,
AnnotationAttributes
,
AnnotatedElementUtils
,
BridgeMethodResolver
,
AnnotatedElement.getAnnotations()
,
AnnotatedElement.getAnnotation(Class)
,
AnnotatedElement.getDeclaredAnnotations()
Modifier and Type | Class and Description |
---|---|
private static class |
AnnotationUtils.AliasDescriptor
AliasDescriptor encapsulates the declaration of @AliasFor
on a given annotation attribute and includes support for validating
the configuration of aliases (both explicit and implicit). |
private static class |
AnnotationUtils.AnnotationCacheKey
Cache key for the AnnotatedElement cache.
|
private static class |
AnnotationUtils.AnnotationCollector<A extends java.lang.annotation.Annotation> |
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.reflect.Method,AnnotationUtils.AliasDescriptor> |
aliasDescriptorCache |
private static java.util.Map<java.lang.Class<?>,java.lang.Boolean> |
annotatedInterfaceCache |
private static java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.Map<java.lang.String,java.util.List<java.lang.String>>> |
attributeAliasesCache |
private static java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<java.lang.reflect.Method>> |
attributeMethodsCache |
private static java.lang.Object |
DEFAULT_VALUE_PLACEHOLDER
An object that can be stored in
AnnotationAttributes as a
placeholder for an attribute's declared default value. |
private static java.util.Map<AnnotationUtils.AnnotationCacheKey,java.lang.annotation.Annotation> |
findAnnotationCache |
private static Log |
logger |
private static java.util.Map<AnnotationUtils.AnnotationCacheKey,java.lang.Boolean> |
metaPresentCache |
private static java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.Boolean> |
synthesizableCache |
static java.lang.String |
VALUE
The attribute name for annotations with a single element.
|
Constructor and Description |
---|
AnnotationUtils() |
Modifier and Type | Method and Description |
---|---|
(package private) static java.lang.Object |
adaptValue(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Object value,
boolean classValuesAsString,
boolean nestedAnnotationsAsMap)
Adapt the given value according to the given class and nested annotation settings.
|
static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<A> annotationType)
Find a single
Annotation of annotationType on the
supplied AnnotatedElement . |
private static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<A> annotationType,
java.util.Set<java.lang.annotation.Annotation> visited)
Perform the search algorithm for
findAnnotation(AnnotatedElement, Class)
avoiding endless recursion by tracking which annotations have already
been visited. |
static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.Class<?> clazz,
java.lang.Class<A> annotationType)
Find a single
Annotation of annotationType on the
supplied Class , traversing its interfaces, annotations, and
superclasses if the annotation is not directly present on
the given class itself. |
private static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.Class<?> clazz,
java.lang.Class<A> annotationType,
boolean synthesize)
Perform the actual work for
findAnnotation(AnnotatedElement, Class) ,
honoring the synthesize flag. |
private static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.Class<?> clazz,
java.lang.Class<A> annotationType,
java.util.Set<java.lang.annotation.Annotation> visited)
Perform the search algorithm for
findAnnotation(Class, Class) ,
avoiding endless recursion by tracking which annotations have already
been visited. |
static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.reflect.Method method,
java.lang.Class<A> annotationType)
Find a single
Annotation of annotationType on the supplied
Method , traversing its super methods (i.e., from superclasses and
interfaces) if the annotation is not directly present on the given
method itself. |
static java.lang.Class<?> |
findAnnotationDeclaringClass(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.Class<?> clazz)
Find the first
Class in the inheritance hierarchy of the
specified clazz (including the specified clazz itself)
on which an annotation of the specified annotationType is
directly present. |
static java.lang.Class<?> |
findAnnotationDeclaringClassForTypes(java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes,
java.lang.Class<?> clazz)
Find the first
Class in the inheritance hierarchy of the
specified clazz (including the specified clazz itself)
on which at least one of the specified annotationTypes is
directly present. |
static <A extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<A> annotationType)
Get a single
Annotation of annotationType from the supplied
AnnotatedElement , where the annotation is either present or
meta-present on the AnnotatedElement . |
(package private) static java.lang.annotation.Annotation |
getAnnotation(java.lang.reflect.AnnotatedElement element,
java.lang.String annotationName)
Get the annotation with the supplied
annotationName on the
supplied element . |
static <A extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.annotation.Annotation ann,
java.lang.Class<A> annotationType)
Get a single
Annotation of annotationType from the supplied
annotation: either the given annotation itself or a direct meta-annotation
thereof. |
static <A extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.reflect.Method method,
java.lang.Class<A> annotationType)
Get a single
Annotation of annotationType from the
supplied Method , where the annotation is either present
or meta-present on the method. |
static AnnotationAttributes |
getAnnotationAttributes(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.annotation.Annotation annotation)
Retrieve the given annotation's attributes as an
AnnotationAttributes map. |
static AnnotationAttributes |
getAnnotationAttributes(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.annotation.Annotation annotation,
boolean classValuesAsString,
boolean nestedAnnotationsAsMap)
Retrieve the given annotation's attributes as an
AnnotationAttributes map. |
(package private) static AnnotationAttributes |
getAnnotationAttributes(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.annotation.Annotation annotation,
boolean classValuesAsString,
boolean nestedAnnotationsAsMap,
boolean mergeMode)
Retrieve the given annotation's attributes as an
AnnotationAttributes map. |
static java.util.Map<java.lang.String,java.lang.Object> |
getAnnotationAttributes(java.lang.annotation.Annotation annotation)
Retrieve the given annotation's attributes as a
Map , preserving all
attribute types. |
static java.util.Map<java.lang.String,java.lang.Object> |
getAnnotationAttributes(java.lang.annotation.Annotation annotation,
boolean classValuesAsString)
Retrieve the given annotation's attributes as a
Map . |
static AnnotationAttributes |
getAnnotationAttributes(java.lang.annotation.Annotation annotation,
boolean classValuesAsString,
boolean nestedAnnotationsAsMap)
Retrieve the given annotation's attributes as an
AnnotationAttributes map. |
static java.lang.annotation.Annotation[] |
getAnnotations(java.lang.reflect.AnnotatedElement annotatedElement)
Get all
Annotations that are present on the
supplied AnnotatedElement . |
static java.lang.annotation.Annotation[] |
getAnnotations(java.lang.reflect.Method method)
Get all
Annotations that are present on the
supplied Method . |
(package private) static java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getAttributeAliasMap(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Get a map of all attribute aliases declared via
@AliasFor
in the supplied annotation type. |
(package private) static java.util.List<java.lang.String> |
getAttributeAliasNames(java.lang.reflect.Method attribute)
Get the names of the aliased attributes configured via
@AliasFor for the supplied annotation attribute . |
(package private) static java.util.List<java.lang.reflect.Method> |
getAttributeMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Get all methods declared in the supplied
annotationType that
match Java's requirements for annotation attributes. |
(package private) static java.lang.String |
getAttributeOverrideName(java.lang.reflect.Method attribute,
java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationType)
Get the name of the overridden attribute configured via
@AliasFor for the supplied annotation attribute . |
static <A extends java.lang.annotation.Annotation> |
getDeclaredRepeatableAnnotations(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<A> annotationType)
Get the declared repeatable annotations
of
annotationType from the supplied AnnotatedElement ,
where such annotations are either directly present,
indirectly present, or meta-present on the element. |
static <A extends java.lang.annotation.Annotation> |
getDeclaredRepeatableAnnotations(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<A> annotationType,
java.lang.Class<? extends java.lang.annotation.Annotation> containerAnnotationType)
Get the declared repeatable annotations
of
annotationType from the supplied AnnotatedElement ,
where such annotations are either directly present,
indirectly present, or meta-present on the element. |
static java.lang.Object |
getDefaultValue(java.lang.annotation.Annotation annotation)
Retrieve the default value of the
value attribute
of a single-element Annotation, given an annotation instance. |
static java.lang.Object |
getDefaultValue(java.lang.annotation.Annotation annotation,
java.lang.String attributeName)
Retrieve the default value of a named attribute, given an annotation instance.
|
static java.lang.Object |
getDefaultValue(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Retrieve the default value of the
value attribute
of a single-element Annotation, given the annotation type . |
static java.lang.Object |
getDefaultValue(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.String attributeName)
Retrieve the default value of a named attribute, given the
annotation type . |
static <A extends java.lang.annotation.Annotation> |
getRepeatableAnnotation(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<? extends java.lang.annotation.Annotation> containerAnnotationType,
java.lang.Class<A> annotationType)
Deprecated.
As of Spring Framework 4.2, use
getRepeatableAnnotations()
or getDeclaredRepeatableAnnotations() instead. |
static <A extends java.lang.annotation.Annotation> |
getRepeatableAnnotation(java.lang.reflect.Method method,
java.lang.Class<? extends java.lang.annotation.Annotation> containerAnnotationType,
java.lang.Class<A> annotationType)
Deprecated.
As of Spring Framework 4.2, use
getRepeatableAnnotations()
or getDeclaredRepeatableAnnotations() instead. |
static <A extends java.lang.annotation.Annotation> |
getRepeatableAnnotations(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<A> annotationType)
Get the repeatable annotations of
annotationType from the supplied AnnotatedElement , where
such annotations are either present, indirectly present,
or meta-present on the element. |
static <A extends java.lang.annotation.Annotation> |
getRepeatableAnnotations(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<A> annotationType,
java.lang.Class<? extends java.lang.annotation.Annotation> containerAnnotationType)
Get the repeatable annotations of
annotationType from the supplied AnnotatedElement , where
such annotations are either present, indirectly present,
or meta-present on the element. |
private static <A extends java.lang.annotation.Annotation> |
getRepeatableAnnotations(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<A> annotationType,
java.lang.Class<? extends java.lang.annotation.Annotation> containerAnnotationType,
boolean declaredMode)
Perform the actual work for
getRepeatableAnnotations(AnnotatedElement, Class, Class)
and getDeclaredRepeatableAnnotations(AnnotatedElement, Class, Class) . |
static java.lang.Object |
getValue(java.lang.annotation.Annotation annotation)
Retrieve the value of the
value attribute of a
single-element Annotation, given an annotation instance. |
static java.lang.Object |
getValue(java.lang.annotation.Annotation annotation,
java.lang.String attributeName)
Retrieve the value of a named attribute, given an annotation instance.
|
(package private) static void |
handleIntrospectionFailure(java.lang.reflect.AnnotatedElement element,
java.lang.Exception ex)
Handle the supplied annotation introspection exception.
|
static boolean |
isAnnotationDeclaredLocally(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.Class<?> clazz)
Determine whether an annotation of the specified
annotationType
is declared locally (i.e., directly present) on the supplied
clazz . |
static boolean |
isAnnotationInherited(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.Class<?> clazz)
Determine whether an annotation of the specified
annotationType
is present on the supplied clazz and is
inherited (i.e., not
directly present). |
static boolean |
isAnnotationMetaPresent(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationType)
Determine if an annotation of type
metaAnnotationType is
meta-present on the supplied annotationType . |
(package private) static boolean |
isAnnotationTypeMethod(java.lang.reflect.Method method)
Determine if the supplied method is an "annotationType" method.
|
(package private) static boolean |
isAttributeMethod(java.lang.reflect.Method method)
Determine if the supplied
method is an annotation attribute method. |
static boolean |
isInJavaLangAnnotationPackage(java.lang.annotation.Annotation annotation)
Determine if the supplied
Annotation is defined in the core JDK
java.lang.annotation package. |
static boolean |
isInJavaLangAnnotationPackage(java.lang.String annotationType)
Determine if the
Annotation with the supplied name is defined
in the core JDK java.lang.annotation package. |
(package private) static boolean |
isInterfaceWithAnnotatedMethods(java.lang.Class<?> iface) |
private static boolean |
isSynthesizable(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if annotations of the supplied
annotationType are
synthesizable (i.e., in need of being wrapped in a dynamic
proxy that provides functionality above that of a standard JDK
annotation). |
(package private) static void |
postProcessAnnotationAttributes(java.lang.reflect.AnnotatedElement element,
AnnotationAttributes attributes,
boolean classValuesAsString,
boolean nestedAnnotationsAsMap)
Post-process the supplied
AnnotationAttributes . |
(package private) static void |
rethrowAnnotationConfigurationException(java.lang.Throwable ex)
If the supplied throwable is an
AnnotationConfigurationException ,
it will be cast to an AnnotationConfigurationException and thrown,
allowing it to propagate to the caller. |
private static <A extends java.lang.annotation.Annotation> |
searchOnInterfaces(java.lang.reflect.Method method,
java.lang.Class<A> annotationType,
java.lang.Class<?>... ifcs) |
(package private) static <A extends java.lang.annotation.Annotation> |
synthesizeAnnotation(A annotation)
Synthesize an annotation from the supplied
annotation
by wrapping it in a dynamic proxy that transparently enforces
attribute alias semantics for annotation attributes that are
annotated with @AliasFor . |
static <A extends java.lang.annotation.Annotation> |
synthesizeAnnotation(A annotation,
java.lang.reflect.AnnotatedElement annotatedElement)
Synthesize an annotation from the supplied
annotation
by wrapping it in a dynamic proxy that transparently enforces
attribute alias semantics for annotation attributes that are
annotated with @AliasFor . |
static <A extends java.lang.annotation.Annotation> |
synthesizeAnnotation(java.lang.Class<A> annotationType)
Synthesize an annotation from its default attributes values.
|
static <A extends java.lang.annotation.Annotation> |
synthesizeAnnotation(java.util.Map<java.lang.String,java.lang.Object> attributes,
java.lang.Class<A> annotationType,
java.lang.reflect.AnnotatedElement annotatedElement)
Synthesize an annotation from the supplied map of annotation
attributes by wrapping the map in a dynamic proxy that implements an
annotation of the specified
annotationType and transparently
enforces attribute alias semantics for annotation attributes
that are annotated with @AliasFor . |
static java.lang.annotation.Annotation[] |
synthesizeAnnotationArray(java.lang.annotation.Annotation[] annotations,
java.lang.reflect.AnnotatedElement annotatedElement)
Synthesize an array of annotations from the supplied array
of
annotations by creating a new array of the same size and
type and populating it with synthesized versions of the annotations from the input array. |
(package private) static <A extends java.lang.annotation.Annotation> |
synthesizeAnnotationArray(java.util.Map<java.lang.String,java.lang.Object>[] maps,
java.lang.Class<A> annotationType)
Synthesize an array of annotations from the supplied array
of
maps of annotation attributes by creating a new array of
annotationType with the same size and populating it with
synthesized versions of the maps from the input array. |
public static final java.lang.String VALUE
private static final java.lang.Object DEFAULT_VALUE_PLACEHOLDER
AnnotationAttributes
as a
placeholder for an attribute's declared default value.private static final java.util.Map<AnnotationUtils.AnnotationCacheKey,java.lang.annotation.Annotation> findAnnotationCache
private static final java.util.Map<java.lang.Class<?>,java.lang.Boolean> annotatedInterfaceCache
private static final java.util.Map<AnnotationUtils.AnnotationCacheKey,java.lang.Boolean> metaPresentCache
private static final java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.Boolean> synthesizableCache
private static final java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.Map<java.lang.String,java.util.List<java.lang.String>>> attributeAliasesCache
private static final java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<java.lang.reflect.Method>> attributeMethodsCache
private static final java.util.Map<java.lang.reflect.Method,AnnotationUtils.AliasDescriptor> aliasDescriptorCache
private static transient Log logger
public static <A extends java.lang.annotation.Annotation> A getAnnotation(java.lang.annotation.Annotation ann, java.lang.Class<A> annotationType)
Annotation
of annotationType
from the supplied
annotation: either the given annotation itself or a direct meta-annotation
thereof.
Note that this method supports only a single level of meta-annotations.
For support for arbitrary levels of meta-annotations, use one of the
find*()
methods instead.
ann
- the Annotation to checkannotationType
- the annotation type to look for, both locally and as a meta-annotationnull
if not foundpublic static <A extends java.lang.annotation.Annotation> A getAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType)
Annotation
of annotationType
from the supplied
AnnotatedElement
, where the annotation is either present or
meta-present on the AnnotatedElement
.
Note that this method supports only a single level of meta-annotations.
For support for arbitrary levels of meta-annotations, use
findAnnotation(AnnotatedElement, Class)
instead.
annotatedElement
- the AnnotatedElement
from which to get the annotationannotationType
- the annotation type to look for, both locally and as a meta-annotationnull
if not foundpublic static <A extends java.lang.annotation.Annotation> A getAnnotation(java.lang.reflect.Method method, java.lang.Class<A> annotationType)
Annotation
of annotationType
from the
supplied Method
, where the annotation is either present
or meta-present on the method.
Correctly handles bridge Methods
generated by the compiler.
Note that this method supports only a single level of meta-annotations.
For support for arbitrary levels of meta-annotations, use
findAnnotation(Method, Class)
instead.
method
- the method to look for annotations onannotationType
- the annotation type to look fornull
if not foundBridgeMethodResolver.findBridgedMethod(Method)
,
getAnnotation(AnnotatedElement, Class)
public static java.lang.annotation.Annotation[] getAnnotations(java.lang.reflect.AnnotatedElement annotatedElement)
Annotations
that are present on the
supplied AnnotatedElement
.
Meta-annotations will not be searched.
annotatedElement
- the Method, Constructor or Field to retrieve annotations fromnull
if not
resolvable (e.g. because nested Class values in annotation attributes
failed to resolve at runtime)AnnotatedElement.getAnnotations()
public static java.lang.annotation.Annotation[] getAnnotations(java.lang.reflect.Method method)
Annotations
that are present on the
supplied Method
.
Correctly handles bridge Methods
generated by the compiler.
Meta-annotations will not be searched.
method
- the Method to retrieve annotations fromnull
if not
resolvable (e.g. because nested Class values in annotation attributes
failed to resolve at runtime)BridgeMethodResolver.findBridgedMethod(Method)
,
AnnotatedElement.getAnnotations()
@Deprecated public static <A extends java.lang.annotation.Annotation> java.util.Set<A> getRepeatableAnnotation(java.lang.reflect.Method method, java.lang.Class<? extends java.lang.annotation.Annotation> containerAnnotationType, java.lang.Class<A> annotationType)
getRepeatableAnnotations()
or getDeclaredRepeatableAnnotations()
instead.getRepeatableAnnotations(AnnotatedElement, Class, Class)
.@Deprecated public static <A extends java.lang.annotation.Annotation> java.util.Set<A> getRepeatableAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation> containerAnnotationType, java.lang.Class<A> annotationType)
getRepeatableAnnotations()
or getDeclaredRepeatableAnnotations()
instead.getRepeatableAnnotations(AnnotatedElement, Class, Class)
.public static <A extends java.lang.annotation.Annotation> java.util.Set<A> getRepeatableAnnotations(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType)
annotationType
from the supplied AnnotatedElement
, where
such annotations are either present, indirectly present,
or meta-present on the element.
This method mimics the functionality of Java 8's
AnnotatedElement.getAnnotationsByType(Class)
with support for automatic detection of a container annotation
declared via @Repeatable
(when running on
Java 8 or higher) and with additional support for meta-annotations.
Handles both single annotations and annotations nested within a container annotation.
Correctly handles bridge methods generated by the
compiler if the supplied element is a Method
.
Meta-annotations will be searched if the annotation is not present on the supplied element.
annotatedElement
- the element to look for annotations on; never null
annotationType
- the annotation type to look for; never null
null
getRepeatableAnnotations(AnnotatedElement, Class, Class)
,
getDeclaredRepeatableAnnotations(AnnotatedElement, Class, Class)
,
BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
,
Repeatable
,
AnnotatedElement.getAnnotationsByType(java.lang.Class<T>)
public static <A extends java.lang.annotation.Annotation> java.util.Set<A> getRepeatableAnnotations(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> containerAnnotationType)
annotationType
from the supplied AnnotatedElement
, where
such annotations are either present, indirectly present,
or meta-present on the element.
This method mimics the functionality of Java 8's
AnnotatedElement.getAnnotationsByType(Class)
with additional support for meta-annotations.
Handles both single annotations and annotations nested within a container annotation.
Correctly handles bridge methods generated by the
compiler if the supplied element is a Method
.
Meta-annotations will be searched if the annotation is not present on the supplied element.
annotatedElement
- the element to look for annotations on; never null
annotationType
- the annotation type to look for; never null
containerAnnotationType
- the type of the container that holds
the annotations; may be null
if a container is not supported
or if it should be looked up via @Repeatable
when running on Java 8 or highernull
getRepeatableAnnotations(AnnotatedElement, Class)
,
getDeclaredRepeatableAnnotations(AnnotatedElement, Class)
,
getDeclaredRepeatableAnnotations(AnnotatedElement, Class, Class)
,
BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
,
Repeatable
,
AnnotatedElement.getAnnotationsByType(java.lang.Class<T>)
public static <A extends java.lang.annotation.Annotation> java.util.Set<A> getDeclaredRepeatableAnnotations(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType)
annotationType
from the supplied AnnotatedElement
,
where such annotations are either directly present,
indirectly present, or meta-present on the element.
This method mimics the functionality of Java 8's
AnnotatedElement.getDeclaredAnnotationsByType(Class)
with support for automatic detection of a container annotation
declared via @Repeatable
(when running on
Java 8 or higher) and with additional support for meta-annotations.
Handles both single annotations and annotations nested within a container annotation.
Correctly handles bridge methods generated by the
compiler if the supplied element is a Method
.
Meta-annotations will be searched if the annotation is not present on the supplied element.
annotatedElement
- the element to look for annotations on; never null
annotationType
- the annotation type to look for; never null
null
getRepeatableAnnotations(AnnotatedElement, Class)
,
getRepeatableAnnotations(AnnotatedElement, Class, Class)
,
getDeclaredRepeatableAnnotations(AnnotatedElement, Class, Class)
,
BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
,
Repeatable
,
AnnotatedElement.getDeclaredAnnotationsByType(java.lang.Class<T>)
public static <A extends java.lang.annotation.Annotation> java.util.Set<A> getDeclaredRepeatableAnnotations(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> containerAnnotationType)
annotationType
from the supplied AnnotatedElement
,
where such annotations are either directly present,
indirectly present, or meta-present on the element.
This method mimics the functionality of Java 8's
AnnotatedElement.getDeclaredAnnotationsByType(Class)
with additional support for meta-annotations.
Handles both single annotations and annotations nested within a container annotation.
Correctly handles bridge methods generated by the
compiler if the supplied element is a Method
.
Meta-annotations will be searched if the annotation is not present on the supplied element.
annotatedElement
- the element to look for annotations on; never null
annotationType
- the annotation type to look for; never null
containerAnnotationType
- the type of the container that holds
the annotations; may be null
if a container is not supported
or if it should be looked up via @Repeatable
when running on Java 8 or highernull
getRepeatableAnnotations(AnnotatedElement, Class)
,
getRepeatableAnnotations(AnnotatedElement, Class, Class)
,
getDeclaredRepeatableAnnotations(AnnotatedElement, Class)
,
BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
,
Repeatable
,
AnnotatedElement.getDeclaredAnnotationsByType(java.lang.Class<T>)
private static <A extends java.lang.annotation.Annotation> java.util.Set<A> getRepeatableAnnotations(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> containerAnnotationType, boolean declaredMode)
getRepeatableAnnotations(AnnotatedElement, Class, Class)
and getDeclaredRepeatableAnnotations(AnnotatedElement, Class, Class)
.
Correctly handles bridge methods generated by the
compiler if the supplied element is a Method
.
Meta-annotations will be searched if the annotation is not present on the supplied element.
annotatedElement
- the element to look for annotations on; never null
annotationType
- the annotation type to look for; never null
containerAnnotationType
- the type of the container that holds
the annotations; may be null
if a container is not supported
or if it should be looked up via @Repeatable
when running on Java 8 or higherdeclaredMode
- true
if only declared annotations (i.e.,
directly or indirectly present) should be considerednull
BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
,
Repeatable
public static <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType)
Annotation
of annotationType
on the
supplied AnnotatedElement
.
Meta-annotations will be searched if the annotation is not directly present on the supplied element.
Warning: this method operates generically on
annotated elements. In other words, this method does not execute
specialized search algorithms for classes or methods. If you require
the more specific semantics of findAnnotation(Class, Class)
or findAnnotation(Method, Class)
, invoke one of those methods
instead.
annotatedElement
- the AnnotatedElement
on which to find the annotationannotationType
- the annotation type to look for, both locally and as a meta-annotationnull
if not foundprivate static <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType, java.util.Set<java.lang.annotation.Annotation> visited)
findAnnotation(AnnotatedElement, Class)
avoiding endless recursion by tracking which annotations have already
been visited.annotatedElement
- the AnnotatedElement
on which to find the annotationannotationType
- the annotation type to look for, both locally and as a meta-annotationvisited
- the set of annotations that have already been visitednull
if not foundpublic static <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.reflect.Method method, java.lang.Class<A> annotationType)
Annotation
of annotationType
on the supplied
Method
, traversing its super methods (i.e., from superclasses and
interfaces) if the annotation is not directly present on the given
method itself.
Correctly handles bridge Methods
generated by the compiler.
Meta-annotations will be searched if the annotation is not directly present on the method.
Annotations on methods are not inherited by default, so we need to handle this explicitly.
method
- the method to look for annotations onannotationType
- the annotation type to look fornull
if not foundgetAnnotation(Method, Class)
private static <A extends java.lang.annotation.Annotation> A searchOnInterfaces(java.lang.reflect.Method method, java.lang.Class<A> annotationType, java.lang.Class<?>... ifcs)
static boolean isInterfaceWithAnnotatedMethods(java.lang.Class<?> iface)
public static <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.Class<?> clazz, java.lang.Class<A> annotationType)
Annotation
of annotationType
on the
supplied Class
, traversing its interfaces, annotations, and
superclasses if the annotation is not directly present on
the given class itself.
This method explicitly handles class-level annotations which are not
declared as inherited
as well
as meta-annotations and annotations on interfaces.
The algorithm operates as follows:
Note: in this context, the term recursively means that the search process continues by returning to step #1 with the current interface, annotation, or superclass as the class to look for annotations on.
clazz
- the class to look for annotations onannotationType
- the type of annotation to look fornull
if not foundprivate static <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.Class<?> clazz, java.lang.Class<A> annotationType, boolean synthesize)
findAnnotation(AnnotatedElement, Class)
,
honoring the synthesize
flag.clazz
- the class to look for annotations on; never null
annotationType
- the type of annotation to look forsynthesize
- true
if the result should be
synthesizednull
if not foundprivate static <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.Class<?> clazz, java.lang.Class<A> annotationType, java.util.Set<java.lang.annotation.Annotation> visited)
findAnnotation(Class, Class)
,
avoiding endless recursion by tracking which annotations have already
been visited.clazz
- the class to look for annotations onannotationType
- the type of annotation to look forvisited
- the set of annotations that have already been visitednull
if not foundpublic static java.lang.Class<?> findAnnotationDeclaringClass(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Class<?> clazz)
Class
in the inheritance hierarchy of the
specified clazz
(including the specified clazz
itself)
on which an annotation of the specified annotationType
is
directly present.
If the supplied clazz
is an interface, only the interface
itself will be checked; the inheritance hierarchy for interfaces will
not be traversed.
Meta-annotations will not be searched.
The standard Class
API does not provide a mechanism for
determining which class in an inheritance hierarchy actually declares
an Annotation
, so we need to handle this explicitly.
annotationType
- the annotation type to look forclazz
- the class to check for the annotation on (may be null
)Class
in the inheritance hierarchy that
declares an annotation of the specified annotationType
, or
null
if not foundClass.isAnnotationPresent(Class)
,
Class.getDeclaredAnnotations()
,
findAnnotationDeclaringClassForTypes(List, Class)
,
isAnnotationDeclaredLocally(Class, Class)
public static java.lang.Class<?> findAnnotationDeclaringClassForTypes(java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes, java.lang.Class<?> clazz)
Class
in the inheritance hierarchy of the
specified clazz
(including the specified clazz
itself)
on which at least one of the specified annotationTypes
is
directly present.
If the supplied clazz
is an interface, only the interface
itself will be checked; the inheritance hierarchy for interfaces will
not be traversed.
Meta-annotations will not be searched.
The standard Class
API does not provide a mechanism for
determining which class in an inheritance hierarchy actually declares
one of several candidate annotations, so we
need to handle this explicitly.
annotationTypes
- the annotation types to look forclazz
- the class to check for the annotations on, or null
Class
in the inheritance hierarchy that
declares an annotation of at least one of the specified
annotationTypes
, or null
if not foundClass.isAnnotationPresent(Class)
,
Class.getDeclaredAnnotations()
,
findAnnotationDeclaringClass(Class, Class)
,
isAnnotationDeclaredLocally(Class, Class)
public static boolean isAnnotationDeclaredLocally(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Class<?> clazz)
annotationType
is declared locally (i.e., directly present) on the supplied
clazz
.
The supplied Class
may represent any type.
Meta-annotations will not be searched.
Note: This method does not determine if the annotation
is inherited. For greater
clarity regarding inherited annotations, consider using
isAnnotationInherited(Class, Class)
instead.
annotationType
- the annotation type to look forclazz
- the class to check for the annotation ontrue
if an annotation of the specified annotationType
is directly presentClass.getDeclaredAnnotations()
,
Class.getDeclaredAnnotation(Class)
,
isAnnotationInherited(Class, Class)
public static boolean isAnnotationInherited(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Class<?> clazz)
annotationType
is present on the supplied clazz
and is
inherited (i.e., not
directly present).
Meta-annotations will not be searched.
If the supplied clazz
is an interface, only the interface
itself will be checked. In accordance with standard meta-annotation
semantics in Java, the inheritance hierarchy for interfaces will not
be traversed. See the Javadoc
for the @Inherited
meta-annotation for further details regarding
annotation inheritance.
annotationType
- the annotation type to look forclazz
- the class to check for the annotation ontrue
if an annotation of the specified annotationType
is present and inheritedClass.isAnnotationPresent(Class)
,
isAnnotationDeclaredLocally(Class, Class)
public static boolean isAnnotationMetaPresent(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationType)
metaAnnotationType
is
meta-present on the supplied annotationType
.annotationType
- the annotation type to search on; never null
metaAnnotationType
- the type of meta-annotation to search fortrue
if such an annotation is meta-presentpublic static boolean isInJavaLangAnnotationPackage(java.lang.annotation.Annotation annotation)
Annotation
is defined in the core JDK
java.lang.annotation
package.annotation
- the annotation to check (never null
)true
if the annotation is in the java.lang.annotation
packagepublic static boolean isInJavaLangAnnotationPackage(java.lang.String annotationType)
Annotation
with the supplied name is defined
in the core JDK java.lang.annotation
package.annotationType
- the name of the annotation type to check (never null
or empty)true
if the annotation is in the java.lang.annotation
packagepublic static java.util.Map<java.lang.String,java.lang.Object> getAnnotationAttributes(java.lang.annotation.Annotation annotation)
Map
, preserving all
attribute types.
Equivalent to calling getAnnotationAttributes(Annotation, boolean, boolean)
with the classValuesAsString
and nestedAnnotationsAsMap
parameters
set to false
.
Note: This method actually returns an AnnotationAttributes
instance.
However, the Map
signature has been preserved for binary compatibility.
annotation
- the annotation to retrieve the attributes fornull
getAnnotationAttributes(AnnotatedElement, Annotation)
,
getAnnotationAttributes(Annotation, boolean, boolean)
,
getAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean)
public static java.util.Map<java.lang.String,java.lang.Object> getAnnotationAttributes(java.lang.annotation.Annotation annotation, boolean classValuesAsString)
Map
.
Equivalent to calling getAnnotationAttributes(Annotation, boolean, boolean)
with the nestedAnnotationsAsMap
parameter set to false
.
Note: This method actually returns an AnnotationAttributes
instance.
However, the Map
signature has been preserved for binary compatibility.
annotation
- the annotation to retrieve the attributes forclassValuesAsString
- whether to convert Class references into Strings (for
compatibility with AnnotationMetadata
)
or to preserve them as Class referencesnull
getAnnotationAttributes(Annotation, boolean, boolean)
public static AnnotationAttributes getAnnotationAttributes(java.lang.annotation.Annotation annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
AnnotationAttributes
map.
This method provides fully recursive annotation reading capabilities on par with
the reflection-based StandardAnnotationMetadata
.
annotation
- the annotation to retrieve the attributes forclassValuesAsString
- whether to convert Class references into Strings (for
compatibility with AnnotationMetadata
)
or to preserve them as Class referencesnestedAnnotationsAsMap
- whether to convert nested annotations into
AnnotationAttributes
maps (for compatibility with
AnnotationMetadata
) or to preserve them as
Annotation
instancesnull
public static AnnotationAttributes getAnnotationAttributes(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.annotation.Annotation annotation)
AnnotationAttributes
map.
Equivalent to calling getAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean)
with the classValuesAsString
and nestedAnnotationsAsMap
parameters
set to false
.
annotatedElement
- the element that is annotated with the supplied annotation;
may be null
if unknownannotation
- the annotation to retrieve the attributes fornull
getAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean)
public static AnnotationAttributes getAnnotationAttributes(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.annotation.Annotation annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
AnnotationAttributes
map.
This method provides fully recursive annotation reading capabilities on par with
the reflection-based StandardAnnotationMetadata
.
annotatedElement
- the element that is annotated with the supplied annotation;
may be null
if unknownannotation
- the annotation to retrieve the attributes forclassValuesAsString
- whether to convert Class references into Strings (for
compatibility with AnnotationMetadata
)
or to preserve them as Class referencesnestedAnnotationsAsMap
- whether to convert nested annotations into
AnnotationAttributes
maps (for compatibility with
AnnotationMetadata
) or to preserve them as
Annotation
instancesnull
static AnnotationAttributes getAnnotationAttributes(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.annotation.Annotation annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap, boolean mergeMode)
AnnotationAttributes
map.
This method provides fully recursive annotation reading capabilities on par with
the reflection-based StandardAnnotationMetadata
.
NOTE: This variant of getAnnotationAttributes()
is
only intended for use within the framework. Specifically, the mergeMode
flag
can be set to true
in order to support processing of attribute aliases while
merging attributes within an annotation hierarchy. When running in merge mode,
the following special rules apply:
DEFAULT_VALUE_PLACEHOLDER
.@AliasFor
semantics.annotatedElement
- the element that is annotated with the supplied annotation;
may be null
if unknownannotation
- the annotation to retrieve the attributes forclassValuesAsString
- whether to convert Class references into Strings (for
compatibility with AnnotationMetadata
)
or to preserve them as Class referencesnestedAnnotationsAsMap
- whether to convert nested annotations into
AnnotationAttributes
maps (for compatibility with
AnnotationMetadata
) or to preserve them as
Annotation
instancesmergeMode
- whether the annotation attributes should be created
using merge modenull
postProcessAnnotationAttributes(java.lang.reflect.AnnotatedElement, org.springframework.core.annotation.AnnotationAttributes, boolean, boolean)
static java.lang.Object adaptValue(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Object value, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
Nested annotations will be synthesized.
annotatedElement
- the element that is annotated, used for contextual
logging; may be null
if unknownvalue
- the annotation attribute valueclassValuesAsString
- whether to convert Class references into Strings (for
compatibility with AnnotationMetadata
)
or to preserve them as Class referencesnestedAnnotationsAsMap
- whether to convert nested annotations into
AnnotationAttributes
maps (for compatibility with
AnnotationMetadata
) or to preserve them as
Annotation
instancespublic static java.lang.Object getValue(java.lang.annotation.Annotation annotation)
value
attribute of a
single-element Annotation, given an annotation instance.annotation
- the annotation instance from which to retrieve the valuenull
if not foundgetValue(Annotation, String)
public static java.lang.Object getValue(java.lang.annotation.Annotation annotation, java.lang.String attributeName)
annotation
- the annotation instance from which to retrieve the valueattributeName
- the name of the attribute value to retrievenull
if not foundgetValue(Annotation)
public static java.lang.Object getDefaultValue(java.lang.annotation.Annotation annotation)
value
attribute
of a single-element Annotation, given an annotation instance.annotation
- the annotation instance from which to retrieve the default valuenull
if not foundgetDefaultValue(Annotation, String)
public static java.lang.Object getDefaultValue(java.lang.annotation.Annotation annotation, java.lang.String attributeName)
annotation
- the annotation instance from which to retrieve the default valueattributeName
- the name of the attribute value to retrievenull
if not foundgetDefaultValue(Class, String)
public static java.lang.Object getDefaultValue(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
value
attribute
of a single-element Annotation, given the annotation type
.annotationType
- the annotation type for which the default value should be retrievednull
if not foundgetDefaultValue(Class, String)
public static java.lang.Object getDefaultValue(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.String attributeName)
annotation type
.annotationType
- the annotation type for which the default value should be retrievedattributeName
- the name of the attribute value to retrieve.null
if not foundgetDefaultValue(Annotation, String)
static <A extends java.lang.annotation.Annotation> A synthesizeAnnotation(A annotation)
annotation
by wrapping it in a dynamic proxy that transparently enforces
attribute alias semantics for annotation attributes that are
annotated with @AliasFor
.annotation
- the annotation to synthesizenull
if the supplied annotation is
null
; otherwise, the supplied annotation unmodifiedAnnotationConfigurationException
- if invalid configuration of
@AliasFor
is detectedsynthesizeAnnotation(Annotation, AnnotatedElement)
public static <A extends java.lang.annotation.Annotation> A synthesizeAnnotation(A annotation, java.lang.reflect.AnnotatedElement annotatedElement)
annotation
by wrapping it in a dynamic proxy that transparently enforces
attribute alias semantics for annotation attributes that are
annotated with @AliasFor
.annotation
- the annotation to synthesizeannotatedElement
- the element that is annotated with the supplied
annotation; may be null
if unknownnull
if the supplied annotation is
null
; otherwise the supplied annotation unmodifiedAnnotationConfigurationException
- if invalid configuration of
@AliasFor
is detectedsynthesizeAnnotation(Map, Class, AnnotatedElement)
,
synthesizeAnnotation(Class)
public static <A extends java.lang.annotation.Annotation> A synthesizeAnnotation(java.util.Map<java.lang.String,java.lang.Object> attributes, java.lang.Class<A> annotationType, java.lang.reflect.AnnotatedElement annotatedElement)
annotationType
and transparently
enforces attribute alias semantics for annotation attributes
that are annotated with @AliasFor
.
The supplied map must contain a key-value pair for every attribute
defined in the supplied annotationType
that is not aliased or
does not have a default value. Nested maps and nested arrays of maps
will be recursively synthesized into nested annotations or nested
arrays of annotations, respectively.
Note that AnnotationAttributes
is a specialized type of
Map
that is an ideal candidate for this method's
attributes
argument.
attributes
- the map of annotation attributes to synthesizeannotationType
- the type of annotation to synthesize; never null
annotatedElement
- the element that is annotated with the annotation
corresponding to the supplied attributes; may be null
if unknownnull
if the supplied attributes
map is null
java.lang.IllegalArgumentException
- if a required attribute is missing or if an
attribute is not of the correct typeAnnotationConfigurationException
- if invalid configuration of
@AliasFor
is detectedsynthesizeAnnotation(Annotation, AnnotatedElement)
,
synthesizeAnnotation(Class)
,
getAnnotationAttributes(AnnotatedElement, Annotation)
,
getAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean)
public static <A extends java.lang.annotation.Annotation> A synthesizeAnnotation(java.lang.Class<A> annotationType)
This method simply delegates to
synthesizeAnnotation(Map, Class, AnnotatedElement)
,
supplying an empty map for the source attribute values and null
for the AnnotatedElement
.
annotationType
- the type of annotation to synthesize; never null
java.lang.IllegalArgumentException
- if a required attribute is missingAnnotationConfigurationException
- if invalid configuration of
@AliasFor
is detectedsynthesizeAnnotation(Map, Class, AnnotatedElement)
,
synthesizeAnnotation(Annotation, AnnotatedElement)
public static java.lang.annotation.Annotation[] synthesizeAnnotationArray(java.lang.annotation.Annotation[] annotations, java.lang.reflect.AnnotatedElement annotatedElement)
annotations
by creating a new array of the same size and
type and populating it with synthesized versions of the annotations from the input array.annotations
- the array of annotations to synthesizeannotatedElement
- the element that is annotated with the supplied
array of annotations; may be null
if unknownnull
if
the supplied array is null
AnnotationConfigurationException
- if invalid configuration of
@AliasFor
is detectedsynthesizeAnnotation(Annotation, AnnotatedElement)
,
synthesizeAnnotation(Map, Class, AnnotatedElement)
static <A extends java.lang.annotation.Annotation> A[] synthesizeAnnotationArray(java.util.Map<java.lang.String,java.lang.Object>[] maps, java.lang.Class<A> annotationType)
maps
of annotation attributes by creating a new array of
annotationType
with the same size and populating it with
synthesized versions of the maps from the input array.maps
- the array of maps of annotation attributes to synthesizeannotationType
- the type of annotations to synthesize; never
null
null
if
the supplied array is null
AnnotationConfigurationException
- if invalid configuration of
@AliasFor
is detectedsynthesizeAnnotation(Map, Class, AnnotatedElement)
,
synthesizeAnnotationArray(Annotation[], AnnotatedElement)
static java.util.Map<java.lang.String,java.util.List<java.lang.String>> getAttributeAliasMap(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
@AliasFor
in the supplied annotation type.
The map is keyed by attribute name with each value representing a list of names of aliased attributes.
For explicit alias pairs such as x and y (i.e., where x
is an @AliasFor("y")
and y is an @AliasFor("x")
, there
will be two entries in the map: x -> (y)
and y -> (x)
.
For implicit aliases (i.e., attributes that are declared
as attribute overrides for the same attribute in the same meta-annotation),
there will be n entries in the map. For example, if x, y, and z are
implicit aliases, the map will contain the following entries:
x -> (y, z)
, y -> (x, z)
, z -> (x, y)
.
An empty return value implies that the annotation does not declare any attribute aliases.
annotationType
- the annotation type to find attribute aliases innull
private static boolean isSynthesizable(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
annotationType
are
synthesizable (i.e., in need of being wrapped in a dynamic
proxy that provides functionality above that of a standard JDK
annotation).
Specifically, an annotation is synthesizable if it declares
any attributes that are configured as aliased pairs via
@AliasFor
or if any nested annotations used by the
annotation declare such aliased pairs.
SynthesizedAnnotation
,
SynthesizedAnnotationInvocationHandler
static java.util.List<java.lang.String> getAttributeAliasNames(java.lang.reflect.Method attribute)
@AliasFor
for the supplied annotation attribute
.attribute
- the attribute to find aliases for; never null
null
, though
potentially emptyjava.lang.IllegalArgumentException
- if the supplied attribute method is
null
or not from an annotationAnnotationConfigurationException
- if invalid configuration of
@AliasFor
is detectedgetAttributeOverrideName(Method, Class)
static java.lang.String getAttributeOverrideName(java.lang.reflect.Method attribute, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationType)
@AliasFor
for the supplied annotation attribute
.attribute
- the attribute from which to retrieve the override;
never null
metaAnnotationType
- the type of meta-annotation in which the
overridden attribute is allowed to be declarednull
if not
found or not applicable for the specified meta-annotation typejava.lang.IllegalArgumentException
- if the supplied attribute method is
null
or not from an annotation, or if the supplied meta-annotation
type is null
or Annotation
AnnotationConfigurationException
- if invalid configuration of
@AliasFor
is detectedstatic java.util.List<java.lang.reflect.Method> getAttributeMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
annotationType
that
match Java's requirements for annotation attributes.
All methods in the returned list will be made accessible.
annotationType
- the type in which to search for attribute methods;
never null
null
, though potentially emptystatic java.lang.annotation.Annotation getAnnotation(java.lang.reflect.AnnotatedElement element, java.lang.String annotationName)
annotationName
on the
supplied element
.element
- the element to search onannotationName
- the fully qualified class name of the annotation
type to find; never null
or emptynull
otherwisestatic boolean isAttributeMethod(java.lang.reflect.Method method)
method
is an annotation attribute method.method
- the method to checktrue
if the method is an attribute methodstatic boolean isAnnotationTypeMethod(java.lang.reflect.Method method)
true
if the method is an "annotationType" methodAnnotation.annotationType()
static void postProcessAnnotationAttributes(java.lang.reflect.AnnotatedElement element, AnnotationAttributes attributes, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
AnnotationAttributes
.
Specifically, this method enforces attribute alias semantics
for annotation attributes that are annotated with @AliasFor
and replaces placeholders with their
original default values.
element
- the element that is annotated with an annotation or
annotation hierarchy from which the supplied attributes were created;
may be null
if unknownattributes
- the annotation attributes to post-processclassValuesAsString
- whether to convert Class references into Strings (for
compatibility with AnnotationMetadata
)
or to preserve them as Class referencesnestedAnnotationsAsMap
- whether to convert nested annotations into
AnnotationAttributes
maps (for compatibility with
AnnotationMetadata
) or to preserve them as
Annotation
instancesgetAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean, boolean)
,
DEFAULT_VALUE_PLACEHOLDER
,
getDefaultValue(Class, String)
static void rethrowAnnotationConfigurationException(java.lang.Throwable ex)
If the supplied throwable is an AnnotationConfigurationException
,
it will be cast to an AnnotationConfigurationException
and thrown,
allowing it to propagate to the caller.
Otherwise, this method does nothing.
ex
- the throwable to inspectstatic void handleIntrospectionFailure(java.lang.reflect.AnnotatedElement element, java.lang.Exception ex)
If the supplied exception is an AnnotationConfigurationException
,
it will simply be thrown, allowing it to propagate to the caller, and
nothing will be logged.
Otherwise, this method logs an introspection failure (in particular
TypeNotPresentExceptions
) before moving on, assuming nested
Class values were not resolvable within annotation attributes and
thereby effectively pretending there were no annotations on the specified
element.
element
- the element that we tried to introspect annotations onex
- the exception that we encounteredrethrowAnnotationConfigurationException(java.lang.Throwable)