@API(value=Internal) public final class AnnotationUtils extends 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 | Method and Description |
---|---|
static List<Method> |
findAnnotatedMethods(Class<?> clazz,
Class<? extends Annotation> annotationType,
ReflectionUtils.HierarchyTraversalMode traversalMode) |
static <A extends Annotation> |
findAnnotation(AnnotatedElement element,
Class<A> annotationType) |
static <A extends Annotation> |
findAnnotation(Optional<? extends AnnotatedElement> element,
Class<A> annotationType)
Find the first annotation of
annotationType that is either
present or meta-present on the supplied optional
element . |
static List<Field> |
findPublicAnnotatedFields(Class<?> clazz,
Class<?> fieldType,
Class<? extends Annotation> annotationType) |
static <A extends Annotation> |
findRepeatableAnnotations(AnnotatedElement element,
Class<A> annotationType) |
static <T> Optional<T> |
getDefaultValue(Annotation annotation,
String attributeName,
Class<T> attributeType)
Get the default value of the named attribute from the supplied
Annotation . |
static boolean |
isAnnotated(AnnotatedElement element,
Class<? extends Annotation> annotationType)
Determine if an annotation of
annotationType is either
present or meta-present on the supplied
element . |
static boolean |
isAnnotated(Optional<? extends AnnotatedElement> element,
Class<? extends Annotation> annotationType)
Determine if an annotation of
annotationType is either
present or meta-present on the supplied optional
element . |
public static <T> Optional<T> getDefaultValue(Annotation annotation, String attributeName, 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(Optional<? extends AnnotatedElement> element, Class<? extends Annotation> annotationType)
annotationType
is either
present or meta-present on the supplied optional
element
.findAnnotation(Optional, Class)
public static boolean isAnnotated(AnnotatedElement element, Class<? extends Annotation> annotationType)
annotationType
is either
present or meta-present on the supplied
element
.public static <A extends Annotation> Optional<A> findAnnotation(Optional<? extends AnnotatedElement> element, Class<A> annotationType)
annotationType
that is either
present or meta-present on the supplied optional
element
.findAnnotation(AnnotatedElement, Class)
public static <A extends Annotation> Optional<A> findAnnotation(AnnotatedElement element, Class<A> annotationType)
public static <A extends Annotation> List<A> findRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType)
public static List<Field> findPublicAnnotatedFields(Class<?> clazz, Class<?> fieldType, Class<? extends Annotation> annotationType)
public static List<Method> findAnnotatedMethods(Class<?> clazz, Class<? extends Annotation> annotationType, ReflectionUtils.HierarchyTraversalMode traversalMode)