@API(status=INTERNAL,
since="1.0")
public final class AnnotationUtils
extends java.lang.Object
These utilities are intended solely for usage within the JUnit framework itself. Any usage by external parties is not supported. Use at your own risk!
Some utilities are published via the maintained AnnotationSupport
class.
Annotation
,
AnnotatedElement
,
AnnotationSupport
Modifier and Type | Class and Description |
---|---|
private static class |
AnnotationUtils.AnnotationCacheKey |
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<AnnotationUtils.AnnotationCacheKey,java.lang.annotation.Annotation> |
annotationCache |
Modifier | Constructor and Description |
---|---|
private |
AnnotationUtils() |
Modifier and Type | Method and Description |
---|---|
static java.util.List<java.lang.reflect.Method> |
findAnnotatedMethods(java.lang.Class<?> clazz,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
ReflectionUtils.HierarchyTraversalMode traversalMode) |
static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.reflect.AnnotatedElement element,
java.lang.Class<A> annotationType) |
private static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.reflect.AnnotatedElement element,
java.lang.Class<A> annotationType,
java.util.Set<java.lang.annotation.Annotation> visited) |
static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.util.Optional<? extends java.lang.reflect.AnnotatedElement> element,
java.lang.Class<A> annotationType)
Find the first annotation of
annotationType that is either
present or meta-present on the supplied optional
element . |
private static <A extends java.lang.annotation.Annotation> |
findMetaAnnotation(java.lang.Class<A> annotationType,
java.lang.annotation.Annotation[] candidates,
AnnotationUtils.AnnotationCacheKey key,
java.util.Set<java.lang.annotation.Annotation> visited) |
static java.util.List<java.lang.reflect.Field> |
findPublicAnnotatedFields(java.lang.Class<?> clazz,
java.lang.Class<?> fieldType,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType) |
static <A extends java.lang.annotation.Annotation> |
findRepeatableAnnotations(java.lang.reflect.AnnotatedElement element,
java.lang.Class<A> annotationType) |
private static <A extends java.lang.annotation.Annotation> |
findRepeatableAnnotations(java.lang.reflect.AnnotatedElement element,
java.lang.Class<A> annotationType,
java.lang.Class<? extends java.lang.annotation.Annotation> containerType,
boolean inherited,
java.util.Set<A> found,
java.util.Set<java.lang.annotation.Annotation> visited) |
private static <A extends java.lang.annotation.Annotation> |
findRepeatableAnnotations(java.lang.annotation.Annotation[] candidates,
java.lang.Class<A> annotationType,
java.lang.Class<? extends java.lang.annotation.Annotation> containerType,
boolean inherited,
java.util.Set<A> found,
java.util.Set<java.lang.annotation.Annotation> visited) |
static <T> java.util.Optional<T> |
getDefaultValue(java.lang.annotation.Annotation annotation,
java.lang.String attributeName,
java.lang.Class<T> attributeType)
Get the default value of the named attribute from the supplied
Annotation . |
static boolean |
isAnnotated(java.lang.reflect.AnnotatedElement element,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if an annotation of
annotationType is either
present or meta-present on the supplied
element . |
static boolean |
isAnnotated(java.util.Optional<? extends java.lang.reflect.AnnotatedElement> element,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if an annotation of
annotationType is either
present or meta-present on the supplied optional
element . |
private static boolean |
isInJavaLangAnnotationPackage(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType) |
private static final java.util.Map<AnnotationUtils.AnnotationCacheKey,java.lang.annotation.Annotation> annotationCache
public static <T> java.util.Optional<T> getDefaultValue(java.lang.annotation.Annotation annotation, java.lang.String attributeName, java.lang.Class<T> attributeType)
Annotation
.annotation
- the annotation from which to retrieve the default
value; never null
attributeName
- the name of the attribute for which the default
value should be retrieved; never null
or emptyattributeType
- the required type of the attribute; never null
Optional
containing the default value; potentially
empty if the attribute does not have a default value.public static boolean isAnnotated(java.util.Optional<? extends java.lang.reflect.AnnotatedElement> element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
annotationType
is either
present or meta-present on the supplied optional
element
.findAnnotation(Optional, Class)
public static boolean isAnnotated(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
annotationType
is either
present or meta-present on the supplied
element
.public static <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.util.Optional<? extends java.lang.reflect.AnnotatedElement> element, java.lang.Class<A> annotationType)
annotationType
that is either
present or meta-present on the supplied optional
element
.findAnnotation(AnnotatedElement, Class)
public static <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
private static <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType, java.util.Set<java.lang.annotation.Annotation> visited)
private static <A extends java.lang.annotation.Annotation> java.util.Optional<A> findMetaAnnotation(java.lang.Class<A> annotationType, java.lang.annotation.Annotation[] candidates, AnnotationUtils.AnnotationCacheKey key, java.util.Set<java.lang.annotation.Annotation> visited)
public static <A extends java.lang.annotation.Annotation> java.util.List<A> findRepeatableAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
private static <A extends java.lang.annotation.Annotation> void findRepeatableAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> containerType, boolean inherited, java.util.Set<A> found, java.util.Set<java.lang.annotation.Annotation> visited)
private static <A extends java.lang.annotation.Annotation> void findRepeatableAnnotations(java.lang.annotation.Annotation[] candidates, java.lang.Class<A> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> containerType, boolean inherited, java.util.Set<A> found, java.util.Set<java.lang.annotation.Annotation> visited)
public static java.util.List<java.lang.reflect.Field> findPublicAnnotatedFields(java.lang.Class<?> clazz, java.lang.Class<?> fieldType, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
public static java.util.List<java.lang.reflect.Method> findAnnotatedMethods(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, ReflectionUtils.HierarchyTraversalMode traversalMode)
private static boolean isInJavaLangAnnotationPackage(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)