@API(status=EXPERIMENTAL,
since="5.10")
public interface AnnotatedElementContext
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.
| Modifier and Type | Method and Description |
|---|---|
default <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.Class<A> annotationType)
Find the first annotation of
annotationType that is either
present or meta-present on the AnnotatedElement for
this context. |
default <A extends java.lang.annotation.Annotation> |
findRepeatableAnnotations(java.lang.Class<A> annotationType)
Find all repeatable annotations of
annotationType that are either present or
meta-present on the AnnotatedElement for this context. |
java.lang.reflect.AnnotatedElement |
getAnnotatedElement()
Get the
AnnotatedElement for this context. |
default boolean |
isAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if an annotation of
annotationType is either
present or meta-present on the AnnotatedElement for
this context. |
java.lang.reflect.AnnotatedElement getAnnotatedElement()
AnnotatedElement for this context.
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.
nulldefault boolean isAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
annotationType is either
present or meta-present on the AnnotatedElement for
this context.
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.
annotationType - the annotation type to search for; never nulltrue if the annotation is present or meta-presentfindAnnotation(Class),
findRepeatableAnnotations(Class)default <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.lang.Class<A> annotationType)
annotationType that is either
present or meta-present on the AnnotatedElement for
this context.
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.
A - the annotation typeannotationType - the annotation type to search for; never nullOptional containing the annotation; never null but
potentially emptyisAnnotated(Class),
findRepeatableAnnotations(Class)default <A extends java.lang.annotation.Annotation> java.util.List<A> findRepeatableAnnotations(java.lang.Class<A> annotationType)
annotationType that are either present or
meta-present on the AnnotatedElement for this context.
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.
A - the annotation typeannotationType - the repeatable annotation type to search for; never
nullnull nor
mutable, but potentially emptyisAnnotated(Class),
findAnnotation(Class),
Repeatable