Class AnnotationUtils
java.lang.Object
org.junit.platform.commons.util.AnnotationUtils
Collection of utilities for working with annotations.
DISCLAIMER
These utilities are intended solely for usage within the JUnit framework itself. Any usage by external parties is not supported. Use at your own risk!
Some utilities are published via the maintained AnnotationSupport
class.
- Since:
- 1.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionfindAnnotatedFields(Class<?> clazz, Class<? extends Annotation> annotationType, Predicate<Field> predicate) findAnnotatedFields(Class<?> clazz, Class<? extends Annotation> annotationType, Predicate<Field> predicate, ReflectionUtils.HierarchyTraversalMode traversalMode) Find all fields of the supplied class or interface that are annotated or meta-annotated with the specifiedannotationTypeand match the specifiedpredicate.findAnnotatedMethods(Class<?> clazz, Class<? extends Annotation> annotationType, ReflectionUtils.HierarchyTraversalMode traversalMode) static <A extends Annotation>
Optional<A> findAnnotation(@Nullable Class<?> clazz, Class<A> annotationType, boolean searchEnclosingClasses) Find the first annotation of the specified type that is either directly present, meta-present, or indirectly present on the supplied class, optionally searching recursively through the enclosing class hierarchy if not found on the supplied class.static <A extends Annotation>
Optional<A> findAnnotation(@Nullable AnnotatedElement element, Class<A> annotationType) static <A extends Annotation>
Optional<A> findAnnotation(Parameter parameter, int index, Class<A> annotationType) static <A extends Annotation>
Optional<A> findAnnotation(@Nullable Optional<? extends AnnotatedElement> element, Class<A> annotationType) findPublicAnnotatedFields(Class<?> clazz, Class<?> fieldType, Class<? extends Annotation> annotationType) static <A extends Annotation>
List<A> findRepeatableAnnotations(@Nullable AnnotatedElement element, Class<A> annotationType) static <A extends Annotation>
List<A> findRepeatableAnnotations(Parameter parameter, int index, Class<A> annotationType) static <A extends Annotation>
List<A> findRepeatableAnnotations(@Nullable Optional<? extends AnnotatedElement> element, Class<A> annotationType) static booleanisAnnotated(@Nullable AnnotatedElement element, Class<? extends Annotation> annotationType) Determine if an annotation ofannotationTypeis either present or meta-present on the suppliedelement.static booleanisAnnotated(Parameter parameter, int index, Class<? extends Annotation> annotationType) static booleanisAnnotated(@Nullable Optional<? extends AnnotatedElement> element, Class<? extends Annotation> annotationType) Determine if an annotation ofannotationTypeis either present or meta-present on the supplied optionalelement.
-
Method Details
-
isAnnotated
@Contract("null, _ -> false") public static boolean isAnnotated(@Nullable Optional<? extends AnnotatedElement> element, Class<? extends Annotation> annotationType) Determine if an annotation ofannotationTypeis either present or meta-present on the supplied optionalelement.- See Also:
-
isAnnotated
public static boolean isAnnotated(Parameter parameter, int index, Class<? extends Annotation> annotationType) - Since:
- 1.8
- See Also:
-
isAnnotated
@Contract("null, _ -> false") public static boolean isAnnotated(@Nullable AnnotatedElement element, Class<? extends Annotation> annotationType) Determine if an annotation ofannotationTypeis either present or meta-present on the suppliedelement.- Parameters:
element- the element on which to search for the annotation; may benullannotationType- the annotation type to search for; nevernull- Returns:
trueif the annotation is present or meta-present- See Also:
-
findAnnotation
public static <A extends Annotation> Optional<A> findAnnotation(@Nullable Optional<? extends AnnotatedElement> element, Class<A> annotationType) - See Also:
-
findAnnotation
public static <A extends Annotation> Optional<A> findAnnotation(Parameter parameter, int index, Class<A> annotationType) - Since:
- 1.8
- See Also:
-
findAnnotation
public static <A extends Annotation> Optional<A> findAnnotation(@Nullable AnnotatedElement element, Class<A> annotationType) - See Also:
-
findAnnotation
public static <A extends Annotation> Optional<A> findAnnotation(@Nullable Class<?> clazz, Class<A> annotationType, boolean searchEnclosingClasses) Find the first annotation of the specified type that is either directly present, meta-present, or indirectly present on the supplied class, optionally searching recursively through the enclosing class hierarchy if not found on the supplied class.The enclosing class hierarchy will only be searched above an inner class (i.e., a non-static member class).
- Type Parameters:
A- the annotation type- Parameters:
clazz- the class on which to search for the annotation; may benullannotationType- the annotation type to search for; nevernullsearchEnclosingClasses- whether the enclosing class hierarchy should be searched- Returns:
- an
Optionalcontaining the annotation; nevernullbut potentially empty - Since:
- 1.8
- See Also:
-
findRepeatableAnnotations
public static <A extends Annotation> List<A> findRepeatableAnnotations(@Nullable Optional<? extends AnnotatedElement> element, Class<A> annotationType) - Since:
- 1.5
- See Also:
-
findRepeatableAnnotations
public static <A extends Annotation> List<A> findRepeatableAnnotations(Parameter parameter, int index, Class<A> annotationType) - Since:
- 1.8
- See Also:
-
findRepeatableAnnotations
public static <A extends Annotation> List<A> findRepeatableAnnotations(@Nullable AnnotatedElement element, Class<A> annotationType) - See Also:
-
findPublicAnnotatedFields
-
findAnnotatedFields
-
findAnnotatedFields
public static List<Field> findAnnotatedFields(Class<?> clazz, Class<? extends Annotation> annotationType, Predicate<Field> predicate, ReflectionUtils.HierarchyTraversalMode traversalMode) Find all fields of the supplied class or interface that are annotated or meta-annotated with the specifiedannotationTypeand match the specifiedpredicate.- Parameters:
clazz- the class or interface in which to find the fields; nevernullannotationType- the annotation type to search for; nevernullpredicate- the field filter; nevernulltraversalMode- the hierarchy traversal mode; nevernull- Returns:
- the list of all such fields found; neither
nullnor mutable
-
findAnnotatedMethods
public static List<Method> findAnnotatedMethods(Class<?> clazz, Class<? extends Annotation> annotationType, ReflectionUtils.HierarchyTraversalMode traversalMode) - See Also:
-