AnnotationSupport provides static utility methods for common tasks
regarding annotations — for example, checking if a class, method, or
field is annotated with a particular annotation; finding annotations on a
given class, method, or field; finding fields or methods annotated with
a particular annotation, etc.
TestEngine and extension
authors are encouraged to use these supported methods in order to align with
the behavior of the JUnit Platform.
ClassSupport, ModifierSupport, ReflectionSupport, ResourceSupport
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static List | Returns: the list of all such fields found; neithernull nor mutablethe class or interface in which to find the fields; never clazz, Class<? extends Annotation> nullthe annotation type to search for; never annotationType)nullFind all distinct fields of the supplied class or
interface that are annotated or meta-annotated with the specified
|
| public static List | Returns: the list of all such fields found; neithernull nor mutablethe class or interface in which to find the fields; never clazz, Class<? extends Annotation> nullthe annotation type to search for; never annotationType, Predicate<Field> nullthe field filter; never predicate)nullFind all distinct fields of the supplied class or
interface that are annotated or meta-annotated with the specified
|
| public static List | Returns: the list of all such fields found; neithernull nor mutablethe class or interface in which to find the fields; never clazz, Class<? extends Annotation> nullthe annotation type to search for; never annotationType, Predicate<Field> nullthe field filter; never predicate, HierarchyTraversalMode nullthe hierarchy traversal mode; never traversalMode)nullFind all distinct fields of the supplied class or
interface that are annotated or meta-annotated with the specified
|
| public static List | Returns: the list of all such field values found; neithernull nor mutablethe instance in which to find the fields; never instance, Class<? extends Annotation> nullthe annotation type to search for; never annotationType)nullFind the values of all non-static fields of the supplied
|
| public static List | Returns: the list of all such field values found; neithernull nor mutablethe class or interface in which to find the fields; never clazz, Class<? extends Annotation> nullthe annotation type to search for; never annotationType)nullFind the values of all static fields of the supplied
class or interface that are annotated or meta-annotated with the
specified |
| public static <T extends @Nullable Object> List | Returns: the list of all such field values found; neithernull nor mutablethe instance in which to find the fields; never instance, Class<? extends Annotation> nullthe annotation type to search for; never annotationType, Class<T> nullthe declared type of fields to find; never fieldType)nullFind the values of all non-static fields of the supplied
|
| public static <T extends @Nullable Object> List | Returns: the list of all such field values found; neithernull nor mutablethe class or interface in which to find the fields; never clazz, Class<? extends Annotation> nullthe annotation type to search for; never annotationType, Class<T> nullthe declared type of fields to find; never fieldType)nullFind the values of all static fields of the supplied
class or interface that are declared to be of the specified
|
| public static List | Returns: the list of all such methods found; neithernull nor mutablethe class or interface in which to find the methods; never clazz, Class<? extends Annotation> nullthe annotation type to search for; never annotationType, HierarchyTraversalMode nullthe hierarchy traversal mode; never traversalMode)nullFind all distinct methods of the supplied class or
interface that are annotated or meta-annotated with the specified
|
| public static < the annotation type A extends Annotation> Optional | Returns: anOptional containing the annotation; never null but
potentially emptyan element, Class<A> Optional containing the element on which to
search for the annotation; may be null or emptythe annotation type to search for; never annotationType)nullFind the first annotation of |
| public static < the annotation type A extends Annotation> Optional | Returns: anOptional containing the annotation; never null but
potentially emptythe element on which to search for the annotation; may be
element, Class<A> nullthe annotation type to search for; never annotationType)nullFind the first annotation of |
| public static < the annotation type A extends Annotation> Optional | Returns: anOptional containing the annotation; never null but
potentially emptythe class on which to search for the annotation; may be clazz, Class<A> nullthe annotation type to search for; never annotationType, SearchOption nullthe searchOption)SearchOption to use; never null
Deprecated
since 1.12. Use
findAnnotation(AnnotatedElement, Class)
(for SearchOption.DEFAULT) or
findAnnotation(Class, Class, List) (for
SearchOption.INCLUDE_ENCLOSING_CLASSES) instead
Find the first annotation of the specified type that is either directly present, meta-present, or indirectly present on the supplied class. |
| public static < the annotation type A extends Annotation> Optional | Returns: anOptional containing the annotation; never null but
potentially empty if clazz is not an inner classthe class on which to search for the annotation; may be clazz, Class<A> nullthe annotation type to search for; never annotationType, List<Class<?>> nullthe runtime types of the enclosing
instances for the class, ordered from outermost to innermost,
excluding enclosingInstanceTypes)clazz; never nullFind the first annotation of the specified type that is either directly present, meta-present, or indirectly present on the supplied class. |
| public static List | Returns: the list of all such fields found; neithernull nor mutablethe class or interface in which to find the fields; never clazz, Class<?> nullthe declared type of fields to find; never fieldType, Class<? extends Annotation> nullthe annotation type to search for; never annotationType)nullFind all |
| public static < the annotation type A extends Annotation> List | Returns: an immutable list of all such annotations found; nevernullan element, Class<A> Optional containing the element on which to
search for the annotation; may be null or emptythe repeatable annotation type to search for; never annotationType)nullFind all repeatable annotations of the
supplied |
| public static < the annotation type A extends Annotation> List | Returns: an immutable list of all such annotations found; nevernullthe element to search on; may be element, Class<A> nullthe repeatable annotation type to search for; never annotationType)nullFind all repeatable annotations of the
supplied |
| public static boolean | Returns: true if the annotation is present or meta-presentan element, Class<? extends Annotation> Optional containing the element on which to
search for the annotation; may be null or emptythe annotation type to search for; never annotationType)nullDetermine if an annotation of |
| public static boolean | Returns: true if the annotation is present or meta-presentthe element on which to search for the annotation; may be
element, Class<? extends Annotation> nullthe annotation type to search for; never annotationType)nullDetermine if an annotation of |
| AnnotationSupport | back to summary |
|---|---|
| private AnnotationSupport() | |
| findAnnotatedFields | back to summary |
|---|---|
| public static List Find all distinct fields of the supplied class or
interface that are annotated or meta-annotated with the specified
Fields declared in the same class or interface will be ordered using an algorithm that is deterministic but intentionally nonobvious. The results will not contain fields that are hidden or synthetic.
| |
| findAnnotatedFields | back to summary |
|---|---|
| public static List Find all distinct fields of the supplied class or
interface that are annotated or meta-annotated with the specified
Fields declared in the same class or interface will be ordered using an algorithm that is deterministic but intentionally nonobvious. The results will not contain fields that are hidden or synthetic.
| |
| findAnnotatedFields | back to summary |
|---|---|
| public static List Find all distinct fields of the supplied class or
interface that are annotated or meta-annotated with the specified
Fields declared in the same class or interface will be ordered using an algorithm that is deterministic but intentionally nonobvious. The results will not contain fields that are hidden or synthetic.
| |
| findAnnotatedFieldValues | back to summary |
|---|---|
| public static List Find the values of all non-static fields of the supplied
Values from fields declared in the same class or interface will be ordered using an algorithm that is deterministic but intentionally nonobvious. The results will not contain values from fields that are hidden or synthetic.
| |
| findAnnotatedFieldValues | back to summary |
|---|---|
| public static List Find the values of all static fields of the supplied
class or interface that are annotated or meta-annotated with the
specified Values from fields declared in the same class or interface will be ordered using an algorithm that is deterministic but intentionally nonobvious. The results will not contain values from fields that are hidden or synthetic.
| |
| findAnnotatedFieldValues | back to summary |
|---|---|
| public static <T extends @Nullable Object> List Find the values of all non-static fields of the supplied
Values from fields declared in the same class or interface will be ordered using an algorithm that is deterministic but intentionally nonobvious. The results will not contain values from fields that are hidden or synthetic.
| |
| findAnnotatedFieldValues | back to summary |
|---|---|
| public static <T extends @Nullable Object> List Find the values of all static fields of the supplied
class or interface that are declared to be of the specified
Values from fields declared in the same class or interface will be ordered using an algorithm that is deterministic but intentionally nonobvious. The results will not contain values from fields that are hidden or synthetic.
| |
| findAnnotatedMethods | back to summary |
|---|---|
| public static List Find all distinct methods of the supplied class or
interface that are annotated or meta-annotated with the specified
| |
| findAnnotation | back to summary |
|---|---|
| public static <A extends Annotation> Optional Find the first annotation of
| |
| findAnnotation | back to summary |
|---|---|
| public static <A extends Annotation> Optional Find the first annotation of 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.
| |
| findAnnotation | back to summary |
|---|---|
| public static <A extends Annotation> Optional Deprecated since 1.12. Use Find the first annotation of the specified type that is either directly present, meta-present, or indirectly present on the supplied class. If the annotation is neither directly present nor meta-present on the class, this method will additionally search on interfaces implemented by the class before searching for an annotation that is indirectly present on the class (i.e., within the class inheritance hierarchy). If the annotation still has not been found, this method will optionally
search recursively through the enclosing class hierarchy if
If
| |
| findAnnotation | back to summary |
|---|---|
| public static <A extends Annotation> Optional Find the first annotation of the specified type that is either directly present, meta-present, or indirectly present on the supplied class. If the annotation is neither directly present nor meta-present on the class, this method will additionally search on interfaces implemented by the class before searching for an annotation that is indirectly present on the class (i.e., within the class inheritance hierarchy). If the annotation still has not been found, this method will optionally
search recursively through the supplied enclosing instance types, starting
at the innermost enclosing class (the last one in the supplied list of
Implementation Note The classes supplied as
| |
| findPublicAnnotatedFields | back to summary |
|---|---|
| public static List Find all Consult the Javadoc for
| |
| findRepeatableAnnotations | back to summary |
|---|---|
| public static <A extends Annotation> List Find all repeatable annotations of the
supplied See
| |
| findRepeatableAnnotations | back to summary |
|---|---|
| public static <A extends Annotation> List Find all repeatable annotations of the
supplied This method extends the functionality of
In addition, if the element is a class and the repeatable annotation
is 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 The search algorithm will also find repeatable annotations used as meta-annotations on other repeatable annotations.
| |
| isAnnotated | back to summary |
|---|---|
| public static boolean isAnnotated(@Nullable Optional<? extends AnnotatedElement> element, Class<? extends Annotation> annotationType) Determine if an annotation of Note This method does not find repeatable annotations.
To check for repeatable annotations, use
| |
| isAnnotated | back to summary |
|---|---|
| public static boolean isAnnotated(@Nullable AnnotatedElement element, Class<? extends Annotation> annotationType) Determine if an annotation of Note This method does not find repeatable annotations.
To check for repeatable annotations, use
| |