类 TestContextAnnotationUtils
TestContextAnnotationUtils is a collection of utility methods that
complements the standard support already available in AnnotationUtils
and AnnotatedElementUtils, while transparently honoring
@NestedTestConfiguration semantics.
Mainly for internal use within the TestContext Framework.
Whereas AnnotationUtils and AnnotatedElementUtils provide
utilities for getting or finding annotations,
TestContextAnnotationUtils 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 TestContextAnnotationUtils.AnnotationDescriptor.
The additional information provided by an AnnotationDescriptor is
required by the TestContext Framework in order to be able to
support class inheritance and enclosing class hierarchy traversals for
annotations such as @ContextConfiguration,
@TestExecutionListeners, and
@ActiveProfiles which offer support for merging and
overriding various inherited annotation attributes — for
example, ContextConfiguration.inheritLocations().
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Harry Yang
- 另请参阅:
-
AnnotationUtilsAnnotatedElementUtilsTestContextAnnotationUtils.AnnotationDescriptor
-
嵌套类概要
嵌套类修饰符和类型类说明static classDescriptor for anAnnotation, including the class on which the annotation is declared as well as the merged annotation instance.static classUntyped extension ofTestContextAnnotationUtils.AnnotationDescriptorthat is used to describe the declaration of one of several candidate annotation types where the actual annotation type cannot be predetermined. -
字段概要
字段修饰符和类型字段说明private static final cn.taketoday.util.ConcurrentLruCache<Class<?>,NestedTestConfiguration.EnclosingConfiguration> private static NestedTestConfiguration.EnclosingConfiguration -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private static voidassertNonEmptyAnnotationTypeArray(Class<?>[] annotationTypes, String message) (专用程序包) static voidstatic <T extends Annotation>
TestContextAnnotationUtils.AnnotationDescriptor<T>findAnnotationDescriptor(Class<?> clazz, Class<T> annotationType) Find theTestContextAnnotationUtils.AnnotationDescriptorfor the suppliedannotationTypeon the suppliedClass, traversing its annotations, interfaces, superclasses, and enclosing classes if no annotation can be found on the given class itself.private static <T extends Annotation>
TestContextAnnotationUtils.AnnotationDescriptor<T>findAnnotationDescriptor(Class<?> clazz, Class<T> annotationType, Predicate<Class<?>> searchEnclosingClass, Set<Annotation> visited) Perform the search algorithm forfindAnnotationDescriptor(Class, Class), avoiding endless recursion by tracking which annotations have already been visited.findAnnotationDescriptorForTypes(Class<?> clazz, Class<? extends Annotation>... annotationTypes) Find theTestContextAnnotationUtils.UntypedAnnotationDescriptorfor the firstClassin the inheritance hierarchy of the specifiedclazz(including the specifiedclazzitself) which declares at least one of the specifiedannotationTypes.private static TestContextAnnotationUtils.UntypedAnnotationDescriptorfindAnnotationDescriptorForTypes(Class<?> clazz, Class<? extends Annotation>[] annotationTypes, Set<Annotation> visited) Perform the search algorithm forfindAnnotationDescriptorForTypes(Class, Class...), avoiding endless recursion by tracking which annotations have already been visited.static <T extends Annotation>
TfindMergedAnnotation(Class<?> clazz, Class<T> annotationType) Find the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the supplied class, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy, and synthesize the result back into an annotation of the specifiedannotationType.private static <T extends Annotation>
TfindMergedAnnotation(Class<?> clazz, Class<T> annotationType, Predicate<Class<?>> searchEnclosingClass) private static NestedTestConfiguration.EnclosingConfigurationprivate static NestedTestConfiguration.EnclosingConfigurationgetEnclosingConfiguration(Class<?> clazz) Get theNestedTestConfiguration.EnclosingConfigurationmode for the supplied class.static <T extends Annotation>
Set<T>getMergedRepeatableAnnotations(Class<?> clazz, Class<T> annotationType) Get all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the supplied class; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.static booleanhasAnnotation(Class<?> clazz, Class<? extends Annotation> annotationType) Determine if an annotation of the specifiedannotationTypeis present or meta-present on the suppliedClassaccording to the search algorithm used infindMergedAnnotation(Class, Class).private static NestedTestConfiguration.EnclosingConfigurationlookUpEnclosingConfiguration(Class<?> clazz) static booleansearchEnclosingClass(Class<?> clazz) Determine if annotations on the enclosing class of the supplied class should be searched by annotation search algorithms within the Infra TestContext Framework.
-
字段详细资料
-
cachedEnclosingConfigurationModes
private static final cn.taketoday.util.ConcurrentLruCache<Class<?>,NestedTestConfiguration.EnclosingConfiguration> cachedEnclosingConfigurationModes -
defaultEnclosingConfigurationMode
@Nullable private static volatile NestedTestConfiguration.EnclosingConfiguration defaultEnclosingConfigurationMode
-
-
构造器详细资料
-
TestContextAnnotationUtils
public TestContextAnnotationUtils()
-
-
方法详细资料
-
hasAnnotation
Determine if an annotation of the specifiedannotationTypeis present or meta-present on the suppliedClassaccording to the search algorithm used infindMergedAnnotation(Class, Class).If this method returns
true, thenfindMergedAnnotation(...)will return a non-null value.- 参数:
clazz- the class to look for annotations onannotationType- the type of annotation to look for- 返回:
trueif a matching annotation is present- 另请参阅:
-
findMergedAnnotation
@Nullable public static <T extends Annotation> T findMergedAnnotation(Class<?> clazz, Class<T> annotationType) Find the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the supplied class, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy, and synthesize the result back into an annotation of the specifiedannotationType.In the context of this method, the term "above" means within the superclass hierarchy or within the enclosing class hierarchy of the supplied class. The enclosing class hierarchy will only be searched according to
@NestedTestConfigurationsemantics.@AliasForsemantics are fully supported, both within a single annotation and within annotation hierarchies.- 参数:
clazz- the class to look for annotations onannotationType- the type of annotation to look for- 返回:
- the merged, synthesized
Annotation, ornullif not found - 另请参阅:
-
AnnotatedElementUtils.findMergedAnnotation(java.lang.reflect.AnnotatedElement, Class)findAnnotationDescriptor(Class, Class)searchEnclosingClass(Class)
-
findMergedAnnotation
@Nullable private static <T extends Annotation> T findMergedAnnotation(Class<?> clazz, Class<T> annotationType, Predicate<Class<?>> searchEnclosingClass) -
getMergedRepeatableAnnotations
public static <T extends Annotation> Set<T> getMergedRepeatableAnnotations(Class<?> clazz, Class<T> annotationType) Get all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the supplied class; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.This method will find
@Inheritedannotations declared on superclasses if the supplied class does not have any local declarations of the repeatable annotation. If no inherited annotations are found, this method will search within the enclosing class hierarchy of the supplied class. The enclosing class hierarchy will only be searched according to@NestedTestConfigurationsemantics.The container type that holds the repeatable annotations will be looked up via
Repeatable.@AliasForsemantics are fully supported, both within a single annotation and within annotation hierarchies.- 参数:
clazz- the class on which to search for annotations (nevernull)annotationType- the annotation type to find (nevernull)- 返回:
- the set of all merged repeatable annotations found, or an empty set if none were found
- 另请参阅:
-
AnnotatedElementUtils.getMergedRepeatableAnnotations(java.lang.reflect.AnnotatedElement, Class)searchEnclosingClass(Class)
-
findAnnotationDescriptor
@Nullable public static <T extends Annotation> TestContextAnnotationUtils.AnnotationDescriptor<T> findAnnotationDescriptor(Class<?> clazz, Class<T> annotationType) Find theTestContextAnnotationUtils.AnnotationDescriptorfor the suppliedannotationTypeon the suppliedClass, traversing its annotations, interfaces, superclasses, and enclosing classes 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:
- Search for the annotation on the given class and return a corresponding
AnnotationDescriptorif 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.
- Recursively search through the enclosing class hierarchy of the given class
if appropriate according to
@NestedTestConfigurationsemantics.
In this context, the term recursively means that the search process continues by returning to step #1 with the current annotation, interface, superclass, or enclosing class 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 - 另请参阅:
- Search for the annotation on the given class and return a corresponding
-
findAnnotationDescriptor
@Nullable private static <T extends Annotation> TestContextAnnotationUtils.AnnotationDescriptor<T> findAnnotationDescriptor(@Nullable Class<?> clazz, Class<T> annotationType, Predicate<Class<?>> searchEnclosingClass, Set<Annotation> visited) Perform the search algorithm forfindAnnotationDescriptor(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 forsearchEnclosingClass- a predicate which evaluates totrueif a search should be performed on the enclosing classvisited- the set of annotations that have already been visited- 返回:
- the corresponding annotation descriptor if the annotation was found;
otherwise
null
-
findAnnotationDescriptorForTypes
@Nullable public static TestContextAnnotationUtils.UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(Class<?> clazz, Class<? extends Annotation>... annotationTypes) Find theTestContextAnnotationUtils.UntypedAnnotationDescriptorfor the firstClassin the inheritance hierarchy of the specifiedclazz(including the specifiedclazzitself) which declares at least one of the specifiedannotationTypes.This method traverses the annotations, interfaces, superclasses, and enclosing classes of the specified
clazzif 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:
- Search for a local declaration of one of the annotation types on the
given class and return a corresponding
UntypedAnnotationDescriptorif 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.
- Recursively search through the enclosing class hierarchy of the given class
if appropriate according to
@NestedTestConfigurationsemantics.
In this context, the term recursively means that the search process continues by returning to step #1 with the current annotation, interface, superclass, or enclosing class 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 - 另请参阅:
- Search for a local declaration of one of the annotation types on the
given class and return a corresponding
-
findAnnotationDescriptorForTypes
@Nullable private static TestContextAnnotationUtils.UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(@Nullable Class<?> clazz, Class<? extends Annotation>[] annotationTypes, Set<Annotation> visited) Perform the search algorithm forfindAnnotationDescriptorForTypes(Class, Class...), avoiding endless recursion by tracking which annotations have already been visited.- 参数:
clazz- the class to look for annotations onannotationTypes- the types of annotations to look forvisited- the set of annotations that have already been visited- 返回:
- the corresponding annotation descriptor if one of the annotations
was found; otherwise
null
-
searchEnclosingClass
Determine if annotations on the enclosing class of the supplied class should be searched by annotation search algorithms within the Infra TestContext Framework.- 参数:
clazz- the class whose enclosing class should potentially be searched- 返回:
trueif the supplied class is an inner class whose enclosing class should be searched- 另请参阅:
-
ClassUtils.isInnerClass(Class)@NestedTestConfiguration
-
clearCaches
static void clearCaches() -
getEnclosingConfiguration
private static NestedTestConfiguration.EnclosingConfiguration getEnclosingConfiguration(Class<?> clazz) Get theNestedTestConfiguration.EnclosingConfigurationmode for the supplied class.- 参数:
clazz- the class for which the enclosing configuration mode should be resolved- 返回:
- the resolved enclosing configuration mode
-
lookUpEnclosingConfiguration
private static NestedTestConfiguration.EnclosingConfiguration lookUpEnclosingConfiguration(Class<?> clazz) -
getDefaultEnclosingConfigurationMode
private static NestedTestConfiguration.EnclosingConfiguration getDefaultEnclosingConfigurationMode() -
assertNonEmptyAnnotationTypeArray
-