Interface AnnotatedElementContext
-
- All Known Subinterfaces:
ParameterContext
@API(status=MAINTAINED, since="5.13.3") public interface AnnotatedElementContextAnnotatedElementContextencapsulates the context in which anAnnotatedElementis declared.For example, an
AnnotatedElementContextis used inTempDirFactoryto allow inspecting the field or parameter theTempDirannotation 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 ofannotationTypethat is either present or meta-present on theAnnotatedElementfor this context.default <A extends java.lang.annotation.Annotation>
java.util.List<A>findRepeatableAnnotations(java.lang.Class<A> annotationType)Find all repeatable annotations ofannotationTypethat are either present or meta-present on theAnnotatedElementfor this context.java.lang.reflect.AnnotatedElementgetAnnotatedElement()Get theAnnotatedElementfor this context.default booleanisAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Determine if an annotation ofannotationTypeis either present or meta-present on theAnnotatedElementfor this context.
-
-
-
Method Detail
-
getAnnotatedElement
java.lang.reflect.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
default boolean isAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if an annotation ofannotationTypeis either present or meta-present on theAnnotatedElementfor 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 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(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 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:
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 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:
isAnnotated(Class),findAnnotation(Class),Repeatable
-
-