类 MetaAnnotationUtils
- java.lang.Object
- org.springframework.test.util.MetaAnnotationUtils
public abstract class MetaAnnotationUtils extends Object
MetaAnnotationUtils
is a collection of utility methods that complements the standard support already available inAnnotationUtils
.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 anMetaAnnotationUtils.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()
).- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen
- 另请参阅:
AnnotationUtils
,MetaAnnotationUtils.AnnotationDescriptor
嵌套类概要
嵌套类 修饰符和类型 类 说明 static class
MetaAnnotationUtils.AnnotationDescriptor<T extends Annotation>
Descriptor for anAnnotation
, including the class on which the annotation is declared as well as the actual annotation instance.static class
MetaAnnotationUtils.UntypedAnnotationDescriptor
Untyped extension ofAnnotationDescriptor
that is used to describe the declaration of one of several candidate annotation types where the actual annotation type cannot be predetermined.
构造器概要
构造器 构造器 说明 MetaAnnotationUtils()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static <T extends Annotation>
MetaAnnotationUtils.AnnotationDescriptor<T>findAnnotationDescriptor(Class<?> clazz, Class<T> annotationType)
Find theMetaAnnotationUtils.AnnotationDescriptor
for the suppliedannotationType
on the suppliedClass
, 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 theMetaAnnotationUtils.UntypedAnnotationDescriptor
for the firstClass
in the inheritance hierarchy of the specifiedclazz
(including the specifiedclazz
itself) which declares at least one of the specifiedannotationTypes
.
构造器详细资料
MetaAnnotationUtils
public MetaAnnotationUtils()
方法详细资料
findAnnotationDescriptor
public static <T extends Annotation> MetaAnnotationUtils.AnnotationDescriptor<T> findAnnotationDescriptor(Class<?> clazz, Class<T> annotationType)
Find theMetaAnnotationUtils.AnnotationDescriptor
for the suppliedannotationType
on the suppliedClass
, 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 inheritedas well as meta-annotations.
The algorithm operates as follows:
- Search for the annotation on the given class and return a corresponding
AnnotationDescriptor
if found. - Recursively search through all annotations that the given class declares.
- Recursively search through all interfaces implemented by the given class.
- Recursively search through the superclass hierarchy of the given class.
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 for- 返回:
- the corresponding annotation descriptor if the annotation was found; otherwise
null
- 另请参阅:
AnnotationUtils.findAnnotationDeclaringClass(Class, Class)
,findAnnotationDescriptorForTypes(Class, Class...)
- Search for the annotation on the given class and return a corresponding
findAnnotationDescriptorForTypes
public static MetaAnnotationUtils.UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(Class<?> clazz, Class<? extends Annotation>... annotationTypes)
Find theMetaAnnotationUtils.UntypedAnnotationDescriptor
for the firstClass
in the inheritance hierarchy of the specifiedclazz
(including the specifiedclazz
itself) which declares at least one of the specifiedannotationTypes
.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 inheritedas well as meta-annotations.
The algorithm operates as follows:
- Search for a local declaration of one of the annotation types on the given class and return a corresponding
UntypedAnnotationDescriptor
if found. - Recursively search through all annotations that the given class declares.
- Recursively search through all interfaces implemented by the given class.
- Recursively search through the superclass hierarchy of the given class.
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 for- 返回:
- the corresponding annotation descriptor if one of the annotations was found; otherwise
null
- 另请参阅:
AnnotationUtils.findAnnotationDeclaringClassForTypes(java.util.List, Class)
,findAnnotationDescriptor(Class, Class)
- Search for a local declaration of one of the annotation types on the given class and return a corresponding