Top Description Methods
org.junit.jupiter.api.extension

public Interface AnnotatedElementContext

Known Direct Subinterfaces
org.junit.jupiter.api.extension.ParameterContext
Annotations
@API
status:MAINTAINED
since:5.13.3
Static Imports
org.apiguardian.api.API.Status.MAINTAINED

AnnotatedElementContext encapsulates the context in which an AnnotatedElement is declared.

For example, an AnnotatedElementContext is used in TempDirFactory to allow inspecting the field or parameter the TempDir annotation is declared on.

This interface is not intended to be implemented by clients.

Since
5.10

Method Summary

Modifier and TypeMethod and Description
public default <
the annotation type
A extends Annotation
>
Optional<A>

Returns:

an Optional containing the annotation; never null but potentially empty
findAnnotation
(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 AnnotatedElement for this context.

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

Returns:

the list of all such annotations found; neither null nor mutable, but potentially empty
findRepeatableAnnotations
(Class<A>
the repeatable annotation type to search for; never null
annotationType
)

Find all repeatable annotations of annotationType that are either present or meta-present on the AnnotatedElement for this context.

public AnnotatedElement

Returns:

the annotated element; never null
getAnnotatedElement
()

Get the AnnotatedElement for this context.

public default boolean

Returns:

true if the annotation is present or meta-present
isAnnotated
(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 AnnotatedElement for this context.

Method Detail

findAnnotationback to summary
public default <A extends Annotation> Optional<A> findAnnotation(Class<A> annotationType)

Find the first annotation of annotationType that is either present or meta-present on the AnnotatedElement for this context.

WARNING

Favor the use of this method over directly invoking annotation lookup methods in the AnnotatedElement API due to a bug in javac on JDK versions prior to JDK 9.

Parameters
<A>
the annotation type
annotationType:Class<A>

the annotation type to search for; never null

Returns:Optional<A>

an Optional containing the annotation; never null but potentially empty

See Also
isAnnotated(Class), findRepeatableAnnotations(Class)
findRepeatableAnnotationsback to summary
public default <A extends Annotation> List<A> findRepeatableAnnotations(Class<A> annotationType)

Find all repeatable annotations of annotationType that are either present or meta-present on the AnnotatedElement for this context.

WARNING

Favor the use of this method over directly invoking annotation lookup methods in the AnnotatedElement API due to a bug in javac on JDK versions prior to JDK 9.

Parameters
<A>
the annotation type
annotationType:Class<A>

the repeatable annotation type to search for; never null

Returns:List<A>

the list of all such annotations found; neither null nor mutable, but potentially empty

See Also
isAnnotated(Class), findAnnotation(Class), java.lang.annotation.Repeatable
getAnnotatedElementback to summary
public AnnotatedElement getAnnotatedElement()

Get the AnnotatedElement for this context.

WARNING

When searching for annotations on the annotated element in this context, favor isAnnotated(Class), findAnnotation(Class), and findRepeatableAnnotations(Class) over methods in the AnnotatedElement API due to a bug in javac on JDK versions prior to JDK 9.

Returns:AnnotatedElement

the annotated element; never null

isAnnotatedback to summary
public default boolean isAnnotated(Class<? extends Annotation> annotationType)

Determine if an annotation of annotationType is either present or meta-present on the AnnotatedElement for this context.

Note

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

WARNING

Favor the use of this method over directly invoking AnnotatedElement#isAnnotationPresent(Class) due to a bug in javac on JDK versions prior to JDK 9.

Parameters
annotationType:Class<? extends Annotation>

the annotation type to search for; never null

Returns:boolean

true if the annotation is present or meta-present

See Also
findAnnotation(Class), findRepeatableAnnotations(Class)