@API(status=MAINTAINED, since="1.0") public final class AnnotationSupport extends Object
Modifier and Type | Method and Description |
---|---|
static List<Method> |
findAnnotatedMethods(Class<?> clazz,
Class<? extends Annotation> annotationType,
HierarchyTraversalMode traversalMode)
Find all methods of the supplied class or interface
that are annotated or meta-annotated with the specified
annotationType . |
static <A extends Annotation> |
findAnnotation(AnnotatedElement element,
Class<A> annotationType)
Find the first annotation of
annotationType that is either
directly present, meta-present, or indirectly
present on the supplied element . |
static List<Field> |
findPublicAnnotatedFields(Class<?> clazz,
Class<?> fieldType,
Class<? extends Annotation> annotationType)
Find all
public fields of the supplied class
or interface that are of the specified fieldType and annotated
or meta-annotated with the specified annotationType . |
static <A extends Annotation> |
findRepeatableAnnotations(AnnotatedElement element,
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(AnnotatedElement element,
Class<? extends Annotation> annotationType)
Determine if an annotation of
annotationType is either
present or meta-present on the supplied
element . |
public static boolean isAnnotated(AnnotatedElement element, Class<? extends Annotation> annotationType)
annotationType
is either
present or meta-present on the supplied
element
.findAnnotation(AnnotatedElement, Class)
public static <A extends Annotation> Optional<A> findAnnotation(AnnotatedElement element, Class<A> annotationType)
annotationType
that is either
directly present, meta-present, or indirectly
present on the supplied element
.
If the element is a class and the annotation is neither directly present nor meta-present on the class, this method will additionally search on interfaces implemented by the class before finding an annotation that is indirectly present on the class.
public static <A extends Annotation> List<A> findRepeatableAnnotations(AnnotatedElement element, 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 element is a class and the repeatable annotation is not discovered within the class hierarchy, this method will additionally search on interfaces implemented by each class in the 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
nor mutableRepeatable
,
Inherited
public static List<Field> findPublicAnnotatedFields(Class<?> clazz, Class<?> fieldType, Class<? extends Annotation> annotationType)
public
fields of the supplied class
or interface that are of the specified fieldType
and annotated
or meta-annotated with the specified annotationType
.
Consult the Javadoc for Class.getFields()
for details on
inheritance and ordering.
clazz
- the class or interface in which to find the fields; never null
fieldType
- the type of field to find; never null
annotationType
- the annotation type to search for; never null
null
nor mutableClass.getFields()
public static List<Method> findAnnotatedMethods(Class<?> clazz, Class<? extends Annotation> annotationType, HierarchyTraversalMode traversalMode)
annotationType
.clazz
- the class or interface in which to find the methods; never null
annotationType
- the annotation type to search for; never null
traversalMode
- the hierarchy traversal mode; never null
null
nor mutable