@API(value=Internal) 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!
Annotation
,
AnnotatedElement
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.MethodSortOrder sortOrder) |
static <A extends java.lang.annotation.Annotation> |
findAnnotation(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 element . |
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 . |
static <A extends java.lang.annotation.Annotation> |
findRepeatableAnnotations(java.lang.reflect.AnnotatedElement element,
java.lang.Class<A> annotationType)
Find all repeatable annotations of
annotationType that are either present, indirectly
present, or meta-present on the supplied AnnotatedElement . |
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 . |
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
.findAnnotation(AnnotatedElement, Class)
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)
annotationType
that is either present or meta-present on
the supplied element
.public static <A extends java.lang.annotation.Annotation> java.util.List<A> findRepeatableAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
annotationType
that are either present, indirectly
present, or meta-present on the supplied AnnotatedElement
.
This method extends the functionality of
AnnotatedElement.getAnnotationsByType(Class)
with additional support for meta-annotations.
In addition, if the element is a class and the repeatable annotation
is @Inherited
, this method will search on superclasses
first in order to support top-down semantics. The result is that this
algorithm finds repeatable annotations that would be shadowed
and therefore not visible according to Java's standard semantics for
inherited, repeatable annotations, but most developers will naturally
assume that all repeatable annotations in JUnit are discovered regardless
of whether they are declared stand-alone, in a container, or as a
meta-annotation (e.g., multiple declarations of @ExtendWith
within a test class hierarchy).
If the supplied element
is null
, this method simply
returns an empty list.
element
- the element to search on, potentially null
annotationType
- the repeatable annotation type to search for; never null
null
Repeatable
,
Inherited
public static java.util.List<java.lang.reflect.Method> findAnnotatedMethods(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, ReflectionUtils.MethodSortOrder sortOrder)