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 application annotations (e.g. for
transaction control, authorization, or service exposure), always use the
lookup methods on this class (e.g. findAnnotation(Method, Class) or
getAnnotation(Method, Class)) 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 fine-grained support for
meta-annotations with attribute overrides in composed annotations,
consider using AnnotatedElementUtils's more specific methods 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, java.lang.reflect.AnnotatedElement#getAnnotations() , java.lang.reflect.AnnotatedElement#getAnnotation(Class) , java.lang.reflect.AnnotatedElement#getDeclaredAnnotations()
| Modifier and Type | Class and Description |
|---|---|
| private static class | AnnotationUtils.
Internal holder used to wrap default values. |
| Modifier and Type | Field and Description |
|---|---|
| private static final Map | |
| private static final AnnotationFilter | |
| public static final String | VALUE
The attribute name for annotations with a single element. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static Object | |
| public static void | |
| private static Map | |
| public static <A extends Annotation> A | Returns: the first matching annotation, ornull if not foundthe annotatedElement, Class<A> AnnotatedElement on which to find the annotationthe annotation type to look for, both locally and as a meta-annotation annotationType)Find a single |
| public static <A extends Annotation> A | Returns: the first matching annotation, ornull if not foundthe method to look for annotations on method, Class<A> the annotation type to look for annotationType)Find a single |
| public static <A extends Annotation> A | Returns: the first matching annotation, ornull if not foundthe class to look for annotations on clazz, Class<A> the type of annotation to look for annotationType)Find a single |
| public static Class | Returns: the firstClass in the inheritance hierarchy that
declares an annotation of the specified annotationType,
or null if not foundthe annotation type to look for annotationType, Class<?> the class to check for the annotation on (may be clazz)null)
Deprecated
as of 5.2 since it is superseded by the
MergedAnnotations API
Find the first |
| public static Class | Returns: the firstClass in the inheritance hierarchy that
declares an annotation of at least one of the specified
annotationTypes, or null if not foundthe annotation types to look for annotationTypes, Class<?> the class to check for the annotation on (may be clazz)null)
Deprecated
as of 5.2 since it is superseded by the
MergedAnnotations API
Find the first |
| public static <A extends Annotation> A | Returns: the first matching annotation, ornull if not foundthe Annotation to check annotation, Class<A> the annotation type to look for, both locally and as a meta-annotation annotationType)Get a single |
| public static <A extends Annotation> A | Returns: the first matching annotation, ornull if not foundthe annotatedElement, Class<A> AnnotatedElement from which to get the annotationthe annotation type to look for, both locally and as a meta-annotation annotationType)Get a single |
| public static <A extends Annotation> A | Returns: the first matching annotation, ornull if not foundthe method to look for annotations on method, Class<A> the annotation type to look for annotationType)Get a single |
| public static Map | Returns: the Map of annotation attributes, with attribute names as keys and corresponding attribute values as values (nevernull)the annotation to retrieve the attributes for annotation)Retrieve the given annotation's attributes as a |
| public static Map | Returns: the Map of annotation attributes, with attribute names as keys and corresponding attribute values as values (nevernull)the annotation to retrieve the attributes for annotation, boolean whether to convert Class references into Strings (for
compatibility with classValuesAsString)org.)
or to preserve them as Class referencesRetrieve the given annotation's attributes as a |
| public static AnnotationAttributes | Returns: the annotation attributes (a specialized Map) with attribute names as keys and corresponding attribute values as values (nevernull)the annotation to retrieve the attributes for annotation, boolean whether to convert Class references into Strings (for
compatibility with classValuesAsString, boolean org.)
or to preserve them as Class referenceswhether to convert nested annotations into
nestedAnnotationsAsMap)AnnotationAttributes maps (for compatibility with
org.) or to preserve them as
Annotation instancesRetrieve the given annotation's attributes as an |
| public static AnnotationAttributes | Returns: the annotation attributes (a specialized Map) with attribute names as keys and corresponding attribute values as values (nevernull)the element that is annotated with the supplied annotation;
may be annotatedElement, Annotation null if unknownthe annotation to retrieve the attributes for annotation)Retrieve the given annotation's attributes as an |
| public static AnnotationAttributes | Returns: the annotation attributes (a specialized Map) with attribute names as keys and corresponding attribute values as values (nevernull)the element that is annotated with the supplied annotation;
may be annotatedElement, Annotation null if unknownthe annotation to retrieve the attributes for annotation, boolean whether to convert Class references into Strings (for
compatibility with classValuesAsString, boolean org.)
or to preserve them as Class referenceswhether to convert nested annotations into
nestedAnnotationsAsMap)AnnotationAttributes maps (for compatibility with
org.) or to preserve them as
Annotation instancesRetrieve the given annotation's attributes as an |
| public static Annotation[] | Returns: the annotations found, an empty array, ornull if not
resolvable (e.g. because nested Class values in annotation attributes
failed to resolve at runtime)the Method, Constructor or Field to retrieve annotations from annotatedElement)
Deprecated
as of 5.2 since it is superseded by the
MergedAnnotations API
Get all |
| public static Annotation[] | Returns: the annotations found, an empty array, ornull if not
resolvable (e.g. because nested Class values in annotation attributes
failed to resolve at runtime)the Method to retrieve annotations from method)
Deprecated
as of 5.2 since it is superseded by the
MergedAnnotations API
Get all |
| private static Object | |
| public static <A extends Annotation> Set | Returns: the annotations found or an empty set (nevernull)the element to look for annotations on annotatedElement, Class<A> the annotation type to look for annotationType)
Deprecated
as of 5.2 since it is superseded by the
MergedAnnotations API
Get the declared repeatable annotations
of |
| public static <A extends Annotation> Set | Returns: the annotations found or an empty set (nevernull)the element to look for annotations on annotatedElement, Class<A> the annotation type to look for annotationType, Class<? extends Annotation> the type of the container that holds
the annotations; may be containerAnnotationType)null if a container is not supported
or if it should be looked up via @java.
when running on Java 8 or higher
Deprecated
as of 5.2 since it is superseded by the
MergedAnnotations API
Get the declared repeatable annotations
of |
| public static Object | Returns: the default value, ornull if not foundthe annotation instance from which to retrieve the default value annotation)Retrieve the default value of the |
| public static Object | Returns: the default value of the named attribute, ornull if not foundthe annotation instance from which to retrieve the default value annotation, String the name of the attribute value to retrieve attributeName)Retrieve the default value of a named attribute, given an annotation instance. |
| public static Object | Returns: the default value, ornull if not foundthe annotation type for which the default value should be retrieved annotationType)Retrieve the default value of the |
| public static Object | Returns: the default value of the named attribute, ornull if not foundthe annotation type for which the default value should be retrieved annotationType, String the name of the attribute value to retrieve. attributeName)Retrieve the default value of a named attribute, given the
|
| private static Map | |
| public static <A extends Annotation> Set | Returns: the annotations found or an empty set (nevernull)the element to look for annotations on annotatedElement, Class<A> the annotation type to look for annotationType)
Deprecated
as of 5.2 since it is superseded by the
MergedAnnotations API
Get the repeatable annotations of
|
| public static <A extends Annotation> Set | Returns: the annotations found or an empty set (nevernull)the element to look for annotations on annotatedElement, Class<A> the annotation type to look for annotationType, Class<? extends Annotation> the type of the container that holds
the annotations; may be containerAnnotationType)null if a container is not supported
or if it should be looked up via @java.
when running on Java 8 or higher
Deprecated
as of 5.2 since it is superseded by the
MergedAnnotations API
Get the repeatable annotations of
|
| public static Object | Returns: the attribute value, ornull if not found unless the attribute
value cannot be retrieved due to an AnnotationConfigurationException,
in which case such an exception will be rethrownthe annotation instance from which to retrieve the value annotation)Retrieve the value of the |
| public static Object | Returns: the attribute value, ornull if not found unless the attribute
value cannot be retrieved due to an AnnotationConfigurationException,
in which case such an exception will be rethrownthe annotation instance from which to retrieve the value annotation, String the name of the attribute value to retrieve attributeName)Retrieve the value of a named attribute, given an annotation instance. |
| pack-priv static void | handleIntrospectionFailure(AnnotatedElement
the element that we tried to introspect annotations on element, Throwable the exception that we encountered ex)Handle the supplied annotation introspection exception. |
| private static void | handleValueRetrievalFailure(Annotation
the annotation instance from which to retrieve the value annotation, Throwable the exception that we encountered ex)Handle the supplied value retrieval exception. |
| pack-priv static Object | Returns: the value returned from the method invocationthe method to invoke method, Object the annotation on which to invoke the method annotation)Invoke the supplied annotation attribute |
| public static boolean | Returns: true if an annotation of the specified annotationType
is directly presentthe annotation type to look for annotationType, Class<?> the class to check for the annotation on clazz)Determine whether an annotation of the specified |
| public static boolean | Returns: true if an annotation of the specified annotationType
is present and inheritedthe annotation type to look for annotationType, Class<?> the class to check for the annotation on clazz)
Deprecated
as of 5.2 since it is superseded by the
MergedAnnotations API
Determine whether an annotation of the specified |
| public static boolean | Returns: true if such an annotation is meta-presentthe annotation type to search on annotationType, Class<? extends Annotation> the type of meta-annotation to search for metaAnnotationType)
Deprecated
as of 5.2 since it is superseded by the
MergedAnnotations API
Determine if an annotation of type |
| public static boolean | Returns: false if the class is known to have no such annotations at any level;
true otherwise. Callers will usually perform full method/field introspection
if true is being returned here.the class to introspect clazz, Collection<Class<? extends Annotation>> the searchable annotation types annotationTypes)Determine whether the given class is a candidate for carrying one of the specified annotations (at type, method or field level). |
| public static boolean | Returns: false if the class is known to have no such annotations at any level;
true otherwise. Callers will usually perform full method/field introspection
if true is being returned here.the class to introspect clazz, Class<? extends Annotation> the searchable annotation type annotationType)Determine whether the given class is a candidate for carrying the specified annotation (at type, method or field level). |
| public static boolean | Returns: false if the class is known to have no such annotations at any level;
true otherwise. Callers will usually perform full method/field introspection
if true is being returned here.the class to introspect clazz, String the fully-qualified name of the searchable annotation type annotationName)Determine whether the given class is a candidate for carrying the specified annotation (at type, method or field level). |
| public static boolean | Returns: true if the annotation is in the java.lang.annotation packagethe annotation to check annotation)Determine if the supplied |
| public static boolean | Returns: true if the annotation is in the java.lang.annotation packagethe name of the annotation type to check annotationType)Determine if the |
| private static <A extends Annotation> boolean | |
| public static boolean | Returns: true if the supplied annotation is a synthesized annotationthe annotation to check annotation)Determine if the supplied |
| public static void | postProcessAnnotationAttributes(Object
the element that is annotated with an annotation or
annotation hierarchy from which the supplied attributes were created;
may be annotatedElement, AnnotationAttributes null if unknownthe annotation attributes to post-process attributes, boolean whether to convert Class references into Strings (for
compatibility with classValuesAsString)org.)
or to preserve them as Class referencesPost-process the supplied |
| public static void | registerDefaultValues(AnnotationAttributes
the annotation attributes to process attributes)Register the annotation-declared default values for the given attributes, if available. |
| pack-priv static void | rethrowAnnotationConfigurationException(Throwable
the throwable to inspect ex)If the supplied throwable is an |
| public static <A extends Annotation> A | Returns: the synthesized annotation if the supplied annotation is synthesizable;null if the supplied annotation is
null; otherwise the supplied annotation unmodifiedthe annotation to synthesize annotation, AnnotatedElement the element that is annotated with the supplied
annotation; may be annotatedElement)null if unknownSynthesize an annotation from the supplied |
| public static <A extends Annotation> A | Returns: the synthesized annotationthe type of annotation to synthesize annotationType)Synthesize an annotation from its default attributes values. |
| public static <A extends Annotation> A | Returns: the synthesized annotationthe map of annotation attributes to synthesize attributes, Class<A> the type of annotation to synthesize annotationType, AnnotatedElement the element that is annotated with the annotation
corresponding to the supplied attributes; may be annotatedElement)null if unknownSynthesize an annotation from the supplied map of annotation
attributes by wrapping the map in a dynamic proxy that implements an
annotation of the specified |
| pack-priv static Annotation[] | Returns: a new array of synthesized annotations, ornull if
the supplied array is nullthe array of annotations to synthesize annotations, AnnotatedElement the element that is annotated with the supplied
array of annotations; may be annotatedElement)null if unknownSynthesize an array of annotations from the supplied array
of |
| public static void | validateAnnotation(Annotation
the annotation to validate annotation)Check the declared attributes of the given annotation, in particular covering
Google App Engine's late arrival of |