public abstract class MetaAnnotationUtils extends Object
MetaAnnotationUtils
is a collection of utility methods that complements
the standard support already available in AnnotationUtils
.
Whereas AnnotationUtils
provides utilities for getting or
finding an annotation, MetaAnnotationUtils
goes a step further
by providing support for determining the root class on which an
annotation is declared, either directly or indirectly via a composed
annotation. This additional information is encapsulated in an
MetaAnnotationUtils.AnnotationDescriptor
.
The additional information provided by an AnnotationDescriptor
is
required by the Spring TestContext Framework in order to be able to
support class hierarchy traversals for annotations such as
@ContextConfiguration
,
@TestExecutionListeners
,
and @ActiveProfiles
which offer support for merging and overriding various inherited
annotation attributes (e.g.
ContextConfiguration.inheritLocations()
).
AnnotationUtils
,
MetaAnnotationUtils.AnnotationDescriptor
Modifier and Type | Class and Description |
---|---|
static class |
MetaAnnotationUtils.AnnotationDescriptor<T extends Annotation>
Descriptor for an
Annotation , including the class on which the annotation is declared
as well as the actual annotation instance. |
static class |
MetaAnnotationUtils.UntypedAnnotationDescriptor
Untyped extension of
AnnotationDescriptor that is used
to describe the declaration of one of several candidate annotation types
where the actual annotation type cannot be predetermined. |
Constructor and Description |
---|
MetaAnnotationUtils() |
Modifier and Type | Method and Description |
---|---|
static <T extends Annotation> |
findAnnotationDescriptor(Class<?> clazz,
Class<T> annotationType)
Find the
MetaAnnotationUtils.AnnotationDescriptor for the supplied annotationType
on the supplied Class , traversing its annotations, interfaces, and
superclasses if no annotation can be found on the given class itself. |
static MetaAnnotationUtils.UntypedAnnotationDescriptor |
findAnnotationDescriptorForTypes(Class<?> clazz,
Class<? extends Annotation>... annotationTypes)
Find the
MetaAnnotationUtils.UntypedAnnotationDescriptor for the first Class
in the inheritance hierarchy of the specified clazz (including
the specified clazz itself) which declares at least one of the
specified annotationTypes . |
public static <T extends Annotation> MetaAnnotationUtils.AnnotationDescriptor<T> findAnnotationDescriptor(Class<?> clazz, Class<T> annotationType)
MetaAnnotationUtils.AnnotationDescriptor
for the supplied annotationType
on the supplied Class
, traversing its annotations, interfaces, and
superclasses if no annotation can be found on the given class itself.
This method explicitly handles class-level annotations which are not declared as inherited as well as meta-annotations.
The algorithm operates as follows:
AnnotationDescriptor
if found.
In this context, the term recursively means that the search process continues by returning to step #1 with the current annotation, interface, 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
AnnotationUtils.findAnnotationDeclaringClass(Class, Class)
,
findAnnotationDescriptorForTypes(Class, Class...)
public static MetaAnnotationUtils.UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(Class<?> clazz, Class<? extends Annotation>... annotationTypes)
MetaAnnotationUtils.UntypedAnnotationDescriptor
for the first Class
in the inheritance hierarchy of the specified clazz
(including
the specified clazz
itself) which declares at least one of the
specified annotationTypes
.
This method traverses the annotations, interfaces, and superclasses
of the specified clazz
if no annotation can be found on the given
class itself.
This method explicitly handles class-level annotations which are not declared as inherited as well as meta-annotations.
The algorithm operates as follows:
UntypedAnnotationDescriptor
if found.
In this context, the term recursively means that the search process continues by returning to step #1 with the current annotation, interface, or superclass as the class to look for annotations on.
clazz
- the class to look for annotations onannotationTypes
- the types of annotations to look fornull
AnnotationUtils.findAnnotationDeclaringClassForTypes(java.util.List, Class)
,
findAnnotationDescriptor(Class, Class)