Interface AnnotatedElementContext
-
- All Known Subinterfaces:
ParameterContext
@API(status=EXPERIMENTAL, since="5.10") public interface AnnotatedElementContext
AnnotatedElementContext
encapsulates the context in which anAnnotatedElement
is declared.For example, an
AnnotatedElementContext
is used inTempDirFactory
to allow inspecting the field or parameter theTempDir
annotation is declared on.This interface is not intended to be implemented by clients.
- Since:
- 5.10
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <A extends java.lang.annotation.Annotation>
java.util.Optional<A>findAnnotation(java.lang.Class<A> annotationType)
Find the first annotation ofannotationType
that is either present or meta-present on theAnnotatedElement
for this context.default <A extends java.lang.annotation.Annotation>
java.util.List<A>findRepeatableAnnotations(java.lang.Class<A> annotationType)
Find all repeatable annotations ofannotationType
that are either present or meta-present on theAnnotatedElement
for this context.java.lang.reflect.AnnotatedElement
getAnnotatedElement()
Get theAnnotatedElement
for this context.default boolean
isAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if an annotation ofannotationType
is either present or meta-present on theAnnotatedElement
for this context.
-
-
-
Method Detail
-
getAnnotatedElement
java.lang.reflect.AnnotatedElement getAnnotatedElement()
Get theAnnotatedElement
for this context.WARNING
When searching for annotations on the annotated element in this context, favor
isAnnotated(Class)
,findAnnotation(Class)
, andfindRepeatableAnnotations(Class)
over methods in theAnnotatedElement
API due to a bug injavac
on JDK versions prior to JDK 9.- Returns:
- the annotated element; never
null
-
isAnnotated
default boolean isAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if an annotation ofannotationType
is either present or meta-present on theAnnotatedElement
for this context.WARNING
Favor the use of this method over directly invoking
AnnotatedElement.isAnnotationPresent(Class)
due to a bug injavac
on JDK versions prior to JDK 9.- Parameters:
annotationType
- the annotation type to search for; nevernull
- Returns:
true
if the annotation is present or meta-present- See Also:
findAnnotation(Class)
,findRepeatableAnnotations(Class)
-
findAnnotation
default <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.lang.Class<A> annotationType)
Find the first annotation ofannotationType
that is either present or meta-present on theAnnotatedElement
for this context.WARNING
Favor the use of this method over directly invoking annotation lookup methods in the
AnnotatedElement
API due to a bug injavac
on JDK versions prior to JDK 9.- Type Parameters:
A
- the annotation type- Parameters:
annotationType
- the annotation type to search for; nevernull
- Returns:
- an
Optional
containing the annotation; nevernull
but potentially empty - See Also:
isAnnotated(Class)
,findRepeatableAnnotations(Class)
-
findRepeatableAnnotations
default <A extends java.lang.annotation.Annotation> java.util.List<A> findRepeatableAnnotations(java.lang.Class<A> annotationType)
Find all repeatable annotations ofannotationType
that are either present or meta-present on theAnnotatedElement
for this context.WARNING
Favor the use of this method over directly invoking annotation lookup methods in the
AnnotatedElement
API due to a bug injavac
on JDK versions prior to JDK 9.- Type Parameters:
A
- the annotation type- Parameters:
annotationType
- the repeatable annotation type to search for; nevernull
- Returns:
- the list of all such annotations found; neither
null
nor mutable, but potentially empty - See Also:
isAnnotated(Class)
,findAnnotation(Class)
,Repeatable
-
-