Top Description Constructors Methods
org.junit.platform.commons.support

public final Class AnnotationSupport

extends Object
Class Inheritance
Annotations
@API
status:MAINTAINED
since:1.0
Static Imports
org.apiguardian.api.API.Status.DEPRECATED, .API.Status.MAINTAINED

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.

Since
1.0
See Also
ClassSupport, ModifierSupport, ReflectionSupport, ResourceSupport

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static List<Field>

Returns:

the list of all such fields found; neither null nor mutable
findAnnotatedFields
(Class<?>
the class or interface in which to find the fields; never null
clazz
,
Class<? extends Annotation>
the annotation type to search for; never null
annotationType
)

Find all distinct fields of the supplied class or interface that are annotated or meta-annotated with the specified annotationType, using top-down search semantics within the type hierarchy.

public static List<Field>

Returns:

the list of all such fields found; neither null nor mutable
findAnnotatedFields
(Class<?>
the class or interface in which to find the fields; never null
clazz
,
Class<? extends Annotation>
the annotation type to search for; never null
annotationType
,
Predicate<Field>
the field filter; never null
predicate
)

Find all distinct fields of the supplied class or interface that are annotated or meta-annotated with the specified annotationType and match the specified predicate, using top-down search semantics within the type hierarchy.

public static List<Field>

Returns:

the list of all such fields found; neither null nor mutable
findAnnotatedFields
(Class<?>
the class or interface in which to find the fields; never null
clazz
,
Class<? extends Annotation>
the annotation type to search for; never null
annotationType
,
Predicate<Field>
the field filter; never null
predicate
,
HierarchyTraversalMode
the hierarchy traversal mode; never null
traversalMode
)

Find all distinct fields of the supplied class or interface that are annotated or meta-annotated with the specified annotationType and match the specified predicate, using the supplied hierarchy traversal mode.

public static List<@Nullable Object>

Returns:

the list of all such field values found; neither null nor mutable
findAnnotatedFieldValues
(Object
the instance in which to find the fields; never null
instance
,
Class<? extends Annotation>
the annotation type to search for; never null
annotationType
)

Find the values of all non-static fields of the supplied instance that are annotated or meta-annotated with the specified annotationType, using top-down search semantics within the type hierarchy.

public static List<@Nullable Object>

Returns:

the list of all such field values found; neither null nor mutable
findAnnotatedFieldValues
(Class<?>
the class or interface in which to find the fields; never null
clazz
,
Class<? extends Annotation>
the annotation type to search for; never null
annotationType
)

Find the values of all static fields of the supplied class or interface that are annotated or meta-annotated with the specified annotationType, using top-down search semantics within the type hierarchy.

public static <T extends @Nullable Object> List<T>

Returns:

the list of all such field values found; neither null nor mutable
findAnnotatedFieldValues
(Object
the instance in which to find the fields; never null
instance
,
Class<? extends Annotation>
the annotation type to search for; never null
annotationType
,
Class<T>
the declared type of fields to find; never null
fieldType
)

Find the values of all non-static fields of the supplied instance that are declared to be of the specified fieldType and are annotated or meta-annotated with the specified annotationType, using top-down search semantics within the type hierarchy.

public static <T extends @Nullable Object> List<T>

Returns:

the list of all such field values found; neither null nor mutable
findAnnotatedFieldValues
(Class<?>
the class or interface in which to find the fields; never null
clazz
,
Class<? extends Annotation>
the annotation type to search for; never null
annotationType
,
Class<T>
the declared type of fields to find; never null
fieldType
)

Find the values of all static fields of the supplied class or interface that are declared to be of the specified fieldType and are annotated or meta-annotated with the specified annotationType, using top-down search semantics within the type hierarchy.

public static List<Method>

Returns:

the list of all such methods found; neither null nor mutable
findAnnotatedMethods
(Class<?>
the class or interface in which to find the methods; never null
clazz
,
Class<? extends Annotation>
the annotation type to search for; never null
annotationType
,
HierarchyTraversalMode
the hierarchy traversal mode; never null
traversalMode
)

Find all distinct methods of the supplied class or interface that are annotated or meta-annotated with the specified annotationType.

public static <
the annotation type
A extends Annotation
>
Optional<A>

Returns:

an Optional containing the annotation; never null but potentially empty
findAnnotation
(@Nullable Optional<? extends AnnotatedElement>
an Optional containing the element on which to search for the annotation; may be null or empty
element
,
Class<A>
the annotation type to search for; never null
annotationType
)

Find the first annotation of annotationType that is either present or meta-present on the supplied optional element.

public static <
the annotation type
A extends Annotation
>
Optional<A>

Returns:

an Optional containing the annotation; never null but potentially empty
findAnnotation
(@Nullable AnnotatedElement
the element on which to search for the annotation; may be null
element
,
Class<A>
the annotation type to search for; never null
annotationType
)

Find the first annotation of annotationType that is either directly present, meta-present, or indirectly present on the supplied element.

public static <
the annotation type
A extends Annotation
>
Optional<A>

Returns:

an Optional containing the annotation; never null but potentially empty
findAnnotation
(@Nullable Class<?>
the class on which to search for the annotation; may be null
clazz
,
Class<A>
the annotation type to search for; never null
annotationType
,
SearchOption
the SearchOption to use; never null
searchOption
)
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<A>

Returns:

an Optional containing the annotation; never null but potentially empty if clazz is not an inner class
findAnnotation
(@Nullable Class<?>
the class on which to search for the annotation; may be null
clazz
,
Class<A>
the annotation type to search for; never null
annotationType
,
List<Class<?>>
the runtime types of the enclosing instances for the class, ordered from outermost to innermost, excluding clazz; never null
enclosingInstanceTypes
)

Find the first annotation of the specified type that is either directly present, meta-present, or indirectly present on the supplied class.

public static List<Field>

Returns:

the list of all such fields found; neither null nor mutable
findPublicAnnotatedFields
(Class<?>
the class or interface in which to find the fields; never null
clazz
,
Class<?>
the declared type of fields to find; never null
fieldType
,
Class<? extends Annotation>
the annotation type to search for; never null
annotationType
)

Find all public fields of the supplied class or interface that are declared to be of the specified fieldType and are annotated or meta-annotated with the specified annotationType.

public static <
the annotation type
A extends Annotation
>
List<A>

Returns:

an immutable list of all such annotations found; never null
findRepeatableAnnotations
(@Nullable Optional<? extends AnnotatedElement>
an Optional containing the element on which to search for the annotation; may be null or empty
element
,
Class<A>
the repeatable annotation type to search for; never null
annotationType
)

Find all repeatable annotations of the supplied annotationType that are either present, indirectly present, or meta-present on the supplied optional element.

public static <
the annotation type
A extends Annotation
>
List<A>

Returns:

an immutable list of all such annotations found; never null
findRepeatableAnnotations
(@Nullable AnnotatedElement
the element to search on; may be null
element
,
Class<A>
the repeatable annotation type to search for; never null
annotationType
)

Find all repeatable annotations of the supplied annotationType that are either present, indirectly present, or meta-present on the supplied AnnotatedElement.

public static boolean

Returns:

true if the annotation is present or meta-present
isAnnotated
(@Nullable Optional<? extends AnnotatedElement>
an Optional containing the element on which to search for the annotation; may be null or empty
element
,
Class<? extends Annotation>
the annotation type to search for; never null
annotationType
)

Determine if an annotation of annotationType is either present or meta-present on the supplied optional element.

public static boolean

Returns:

true if the annotation is present or meta-present
isAnnotated
(@Nullable AnnotatedElement
the element on which to search for the annotation; may be null
element
,
Class<? extends Annotation>
the annotation type to search for; never null
annotationType
)

Determine if an annotation of annotationType is either present or meta-present on the supplied element.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AnnotationSupportback to summary
private AnnotationSupport()

Method Detail

findAnnotatedFieldsback to summary
public static List<Field> findAnnotatedFields(Class<?> clazz, Class<? extends Annotation> annotationType)

Find all distinct fields of the supplied class or interface that are annotated or meta-annotated with the specified annotationType, using top-down search semantics within the type hierarchy.

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.

Parameters
clazz:Class<?>

the class or interface in which to find the fields; never null

annotationType:Class<? extends Annotation>

the annotation type to search for; never null

Returns:List<Field>

the list of all such fields found; neither null nor mutable

Annotations
@API
status:MAINTAINED
since:1.4
Since
1.4
See Also
Class#getDeclaredFields(), findPublicAnnotatedFields(Class, Class, Class), findAnnotatedFields(Class, Class, Predicate, HierarchyTraversalMode), ReflectionSupport#findFields(Class, Predicate, HierarchyTraversalMode), ReflectionSupport#tryToReadFieldValue(Field, Object)
findAnnotatedFieldsback to summary
public static List<Field> findAnnotatedFields(Class<?> clazz, Class<? extends Annotation> annotationType, Predicate<Field> predicate)

Find all distinct fields of the supplied class or interface that are annotated or meta-annotated with the specified annotationType and match the specified predicate, using top-down search semantics within the type hierarchy.

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.

Parameters
clazz:Class<?>

the class or interface in which to find the fields; never null

annotationType:Class<? extends Annotation>

the annotation type to search for; never null

predicate:Predicate<Field>

the field filter; never null

Returns:List<Field>

the list of all such fields found; neither null nor mutable

Annotations
@API
status:MAINTAINED
since:1.10
Since
1.10
See Also
Class#getDeclaredFields(), findPublicAnnotatedFields(Class, Class, Class), findAnnotatedFields(Class, Class, Predicate, HierarchyTraversalMode), ReflectionSupport#findFields(Class, Predicate, HierarchyTraversalMode), ReflectionSupport#tryToReadFieldValue(Field, Object)
findAnnotatedFieldsback to summary
public static List<Field> findAnnotatedFields(Class<?> clazz, Class<? extends Annotation> annotationType, Predicate<Field> predicate, HierarchyTraversalMode traversalMode)

Find all distinct fields of the supplied class or interface that are annotated or meta-annotated with the specified annotationType and match the specified predicate, using the supplied hierarchy traversal mode.

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.

Parameters
clazz:Class<?>

the class or interface in which to find the fields; never null

annotationType:Class<? extends Annotation>

the annotation type to search for; never null

predicate:Predicate<Field>

the field filter; never null

traversalMode:HierarchyTraversalMode

the hierarchy traversal mode; never null

Returns:List<Field>

the list of all such fields found; neither null nor mutable

Annotations
@API
status:MAINTAINED
since:1.4
Since
1.4
See Also
Class#getDeclaredFields(), findAnnotatedFields(Class, Class), ReflectionSupport#findFields(Class, Predicate, HierarchyTraversalMode), ReflectionSupport#tryToReadFieldValue(Field, Object)
findAnnotatedFieldValuesback to summary
public static List<@Nullable Object> findAnnotatedFieldValues(Object instance, Class<? extends Annotation> annotationType)

Find the values of all non-static fields of the supplied instance that are annotated or meta-annotated with the specified annotationType, using top-down search semantics within the type hierarchy.

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.

Parameters
instance:Object

the instance in which to find the fields; never null

annotationType:Class<? extends Annotation>

the annotation type to search for; never null

Returns:List<@Nullable Object>

the list of all such field values found; neither null nor mutable

Annotations
@API
status:MAINTAINED
since:1.4
Since
1.4
See Also
findAnnotatedFields(Class, Class), findAnnotatedFields(Class, Class, Predicate, HierarchyTraversalMode), ReflectionSupport#findFields(Class, Predicate, HierarchyTraversalMode), ReflectionSupport#tryToReadFieldValue(Field, Object)
findAnnotatedFieldValuesback to summary
public static List<@Nullable Object> findAnnotatedFieldValues(Class<?> clazz, Class<? extends Annotation> annotationType)

Find the values of all static fields of the supplied class or interface that are annotated or meta-annotated with the specified annotationType, using top-down search semantics within the type hierarchy.

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.

Parameters
clazz:Class<?>

the class or interface in which to find the fields; never null

annotationType:Class<? extends Annotation>

the annotation type to search for; never null

Returns:List<@Nullable Object>

the list of all such field values found; neither null nor mutable

Annotations
@API
status:MAINTAINED
since:1.4
Since
1.4
See Also
findAnnotatedFields(Class, Class), findAnnotatedFields(Class, Class, Predicate, HierarchyTraversalMode), ReflectionSupport#findFields(Class, Predicate, HierarchyTraversalMode), ReflectionSupport#tryToReadFieldValue(Field, Object)
findAnnotatedFieldValuesback to summary
public static <T extends @Nullable Object> List<T> findAnnotatedFieldValues(Object instance, Class<? extends Annotation> annotationType, Class<T> fieldType)

Find the values of all non-static fields of the supplied instance that are declared to be of the specified fieldType and are annotated or meta-annotated with the specified annotationType, using top-down search semantics within the type hierarchy.

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.

Parameters
instance:Object

the instance in which to find the fields; never null

annotationType:Class<? extends Annotation>

the annotation type to search for; never null

fieldType:Class<T>

the declared type of fields to find; never null

Returns:List<T>

the list of all such field values found; neither null nor mutable

Annotations
@SuppressWarnings:unchecked
@API
status:MAINTAINED
since:1.4
Since
1.4
See Also
Field#getType(), findAnnotatedFields(Class, Class), findAnnotatedFields(Class, Class, Predicate, HierarchyTraversalMode), ReflectionSupport#findFields(Class, Predicate, HierarchyTraversalMode), ReflectionSupport#tryToReadFieldValue(Field, Object)
findAnnotatedFieldValuesback to summary
public static <T extends @Nullable Object> List<T> findAnnotatedFieldValues(Class<?> clazz, Class<? extends Annotation> annotationType, Class<T> fieldType)

Find the values of all static fields of the supplied class or interface that are declared to be of the specified fieldType and are annotated or meta-annotated with the specified annotationType, using top-down search semantics within the type hierarchy.

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.

Parameters
clazz:Class<?>

the class or interface in which to find the fields; never null

annotationType:Class<? extends Annotation>

the annotation type to search for; never null

fieldType:Class<T>

the declared type of fields to find; never null

Returns:List<T>

the list of all such field values found; neither null nor mutable

Annotations
@SuppressWarnings:unchecked
@API
status:MAINTAINED
since:1.4
Since
1.4
See Also
Field#getType(), findAnnotatedFields(Class, Class), findAnnotatedFields(Class, Class, Predicate, HierarchyTraversalMode), ReflectionSupport#findFields(Class, Predicate, HierarchyTraversalMode), ReflectionSupport#tryToReadFieldValue(Field, Object)
findAnnotatedMethodsback to summary
public static List<Method> findAnnotatedMethods(Class<?> clazz, Class<? extends Annotation> annotationType, HierarchyTraversalMode traversalMode)

Find all distinct methods of the supplied class or interface that are annotated or meta-annotated with the specified annotationType.

Parameters
clazz:Class<?>

the class or interface in which to find the methods; never null

annotationType:Class<? extends Annotation>

the annotation type to search for; never null

traversalMode:HierarchyTraversalMode

the hierarchy traversal mode; never null

Returns:List<Method>

the list of all such methods found; neither null nor mutable

findAnnotationback to summary
public static <A extends Annotation> Optional<A> findAnnotation(@Nullable 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.

Parameters
<A>
the annotation type
element:@Nullable Optional<? extends AnnotatedElement>

an Optional containing the element on which to search for the annotation; may be null or empty

annotationType:Class<A>

the annotation type to search for; never null

Returns:Optional<A>

an Optional containing the annotation; never null but potentially empty

Annotations
@API
status:MAINTAINED
since:1.1
@SuppressWarnings:NullableOptional
Since
1.1
See Also
findAnnotation(AnnotatedElement, Class)
findAnnotationback to summary
public static <A extends Annotation> Optional<A> findAnnotation(@Nullable 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.

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.

Parameters
<A>
the annotation type
element:@Nullable AnnotatedElement

the element on which to search for the annotation; may be null

annotationType:Class<A>

the annotation type to search for; never null

Returns:Optional<A>

an Optional containing the annotation; never null but potentially empty

findAnnotationback to summary
public static <A extends Annotation> Optional<A> findAnnotation(@Nullable Class<?> clazz, Class<A> annotationType, SearchOption searchOption)

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.

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 SearchOption#INCLUDE_ENCLOSING_CLASSES is specified.

If SearchOption#DEFAULT is specified, this method has the same semantics as findAnnotation(AnnotatedElement, Class).

Parameters
<A>
the annotation type
clazz:@Nullable Class<?>

the class on which to search for the annotation; may be null

annotationType:Class<A>

the annotation type to search for; never null

searchOption:SearchOption

the SearchOption to use; never null

Returns:Optional<A>

an Optional containing the annotation; never null but potentially empty

Annotations
@Deprecated
since:1.12
@API
status:DEPRECATED
since:1.12
@SuppressWarnings:deprecation
Since
1.8
See Also
SearchOption, findAnnotation(AnnotatedElement, Class)
findAnnotationback to summary
public static <A extends Annotation> Optional<A> findAnnotation(@Nullable Class<?> clazz, Class<A> annotationType, List<Class<?>> enclosingInstanceTypes)

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 enclosingInstanceTypes).

Implementation Note

The classes supplied as enclosingInstanceTypes may differ from the classes returned from invocations of Class#getEnclosingClass() — for example, when a nested test class is inherited from a superclass.

Parameters
<A>
the annotation type
clazz:@Nullable Class<?>

the class on which to search for the annotation; may be null

annotationType:Class<A>

the annotation type to search for; never null

enclosingInstanceTypes:List<Class<?>>

the runtime types of the enclosing instances for the class, ordered from outermost to innermost, excluding clazz; never null

Returns:Optional<A>

an Optional containing the annotation; never null but potentially empty if clazz is not an inner class

Annotations
@API
status:MAINTAINED
since:1.13.3
Since
1.12
See Also
findAnnotation(AnnotatedElement, Class)
findPublicAnnotatedFieldsback to summary
public static List<Field> findPublicAnnotatedFields(Class<?> clazz, Class<?> fieldType, Class<? extends Annotation> annotationType)

Find all public fields of the supplied class or interface that are declared to be of the specified fieldType and are annotated or meta-annotated with the specified annotationType.

Consult the Javadoc for Class#getFields() for details on inheritance and ordering.

Parameters
clazz:Class<?>

the class or interface in which to find the fields; never null

fieldType:Class<?>

the declared type of fields to find; never null

annotationType:Class<? extends Annotation>

the annotation type to search for; never null

Returns:List<Field>

the list of all such fields found; neither null nor mutable

See Also
Class#getFields(), Field#getType(), findAnnotatedFields(Class, Class), findAnnotatedFields(Class, Class, Predicate, HierarchyTraversalMode), ReflectionSupport#findFields(Class, Predicate, HierarchyTraversalMode), ReflectionSupport#tryToReadFieldValue(Field, Object)
findRepeatableAnnotationsback to summary
public static <A extends Annotation> List<A> findRepeatableAnnotations(@Nullable Optional<? extends AnnotatedElement> element, Class<A> annotationType)

Find all repeatable annotations of the supplied annotationType that are either present, indirectly present, or meta-present on the supplied optional element.

See findRepeatableAnnotations(AnnotatedElement, Class) for details of the algorithm used.

Parameters
<A>
the annotation type
element:@Nullable Optional<? extends AnnotatedElement>

an Optional containing the element on which to search for the annotation; may be null or empty

annotationType:Class<A>

the repeatable annotation type to search for; never null

Returns:List<A>

an immutable list of all such annotations found; never null

Annotations
@API
status:MAINTAINED
since:1.5
@SuppressWarnings:NullableOptional
Since
1.5
See Also
java.lang.annotation.Repeatable, java.lang.annotation.Inherited, findRepeatableAnnotations(AnnotatedElement, Class)
findRepeatableAnnotationsback to summary
public static <A extends Annotation> List<A> findRepeatableAnnotations(@Nullable AnnotatedElement element, Class<A> annotationType)

Find all repeatable annotations of the supplied annotationType that are either present, indirectly present, or meta-present on the supplied AnnotatedElement.

This method extends the functionality of java.lang.reflect.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 returns an empty list.

The search algorithm will also find repeatable annotations used as meta-annotations on other repeatable annotations.

Parameters
<A>
the annotation type
element:@Nullable AnnotatedElement

the element to search on; may be null

annotationType:Class<A>

the repeatable annotation type to search for; never null

Returns:List<A>

an immutable list of all such annotations found; never null

See Also
java.lang.annotation.Repeatable, java.lang.annotation.Inherited
isAnnotatedback to summary
public static boolean isAnnotated(@Nullable 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.

Note

This method does not find repeatable annotations. To check for repeatable annotations, use findRepeatableAnnotations(Optional, Class) and verify that the returned list is not empty.

Parameters
element:@Nullable Optional<? extends AnnotatedElement>

an Optional containing the element on which to search for the annotation; may be null or empty

annotationType:Class<? extends Annotation>

the annotation type to search for; never null

Returns:boolean

true if the annotation is present or meta-present

Annotations
@API
status:MAINTAINED
since:1.3
@Contract:null, _ -> false
@SuppressWarnings:NullableOptional
Since
1.3
See Also
isAnnotated(AnnotatedElement, Class), findAnnotation(Optional, Class), findRepeatableAnnotations(Optional, Class)
isAnnotatedback to summary
public static boolean isAnnotated(@Nullable AnnotatedElement element, Class<? extends Annotation> annotationType)

Determine if an annotation of annotationType is either present or meta-present on the supplied element.

Note

This method does not find repeatable annotations. To check for repeatable annotations, use findRepeatableAnnotations(AnnotatedElement, Class) and verify that the returned list is not empty.

Parameters
element:@Nullable AnnotatedElement

the element on which to search for the annotation; may be null

annotationType:Class<? extends Annotation>

the annotation type to search for; never null

Returns:boolean

true if the annotation is present or meta-present

Annotations
@Contract:null, _ -> false
See Also
isAnnotated(Optional, Class), findAnnotation(AnnotatedElement, Class), findRepeatableAnnotations(AnnotatedElement, Class)