Interface AnnotatedElementContext
- All Known Subinterfaces:
ParameterContext
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 TypeMethodDescriptiondefault <A extends Annotation>
Optional<A>findAnnotation(Class<A> annotationType) Find the first annotation ofannotationTypethat is either present or meta-present on theAnnotatedElementfor this context.default <A extends Annotation>
List<A>findRepeatableAnnotations(Class<A> annotationType) Find all repeatable annotations ofannotationTypethat are either present or meta-present on theAnnotatedElementfor this context.Get theAnnotatedElementfor this context.default booleanisAnnotated(Class<? extends Annotation> annotationType) Determine if an annotation ofannotationTypeis either present or meta-present on theAnnotatedElementfor this context.
-
Method Details
-
getAnnotatedElement
AnnotatedElement getAnnotatedElement()Get theAnnotatedElementfor this context.WARNING
When searching for annotations on the annotated element in this context, favor
isAnnotated(Class),findAnnotation(Class), andfindRepeatableAnnotations(Class)over methods in theAnnotatedElementAPI due to a bug injavacon JDK versions prior to JDK 9.- Returns:
- the annotated element; never
null
-
isAnnotated
Determine if an annotation ofannotationTypeis either present or meta-present on theAnnotatedElementfor this context.WARNING
Favor the use of this method over directly invoking
AnnotatedElement.isAnnotationPresent(Class)due to a bug injavacon JDK versions prior to JDK 9.- Parameters:
annotationType- the annotation type to search for; nevernull- Returns:
trueif the annotation is present or meta-present- See Also:
-
findAnnotation
Find the first annotation ofannotationTypethat is either present or meta-present on theAnnotatedElementfor this context.WARNING
Favor the use of this method over directly invoking annotation lookup methods in the
AnnotatedElementAPI due to a bug injavacon JDK versions prior to JDK 9.- Type Parameters:
A- the annotation type- Parameters:
annotationType- the annotation type to search for; nevernull- Returns:
- an
Optionalcontaining the annotation; nevernullbut potentially empty - See Also:
-
findRepeatableAnnotations
Find all repeatable annotations ofannotationTypethat are either present or meta-present on theAnnotatedElementfor this context.WARNING
Favor the use of this method over directly invoking annotation lookup methods in the
AnnotatedElementAPI due to a bug injavacon 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
nullnor mutable, but potentially empty - See Also:
-