Package org.junit.platform.commons.util
Class AnnotationUtils
- java.lang.Object
-
- org.junit.platform.commons.util.AnnotationUtils
-
@API(status=INTERNAL, since="1.0") public final class AnnotationUtils extends java.lang.Object
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:
Annotation
,AnnotatedElement
,AnnotationSupport
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<java.lang.reflect.Field>
findAnnotatedFields(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.util.function.Predicate<java.lang.reflect.Field> predicate)
static java.util.List<java.lang.reflect.Field>
findAnnotatedFields(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.util.function.Predicate<java.lang.reflect.Field> predicate, ReflectionUtils.HierarchyTraversalMode traversalMode)
Find all fields of the supplied class or interface that are annotated or meta-annotated with the specifiedannotationType
and match the specifiedpredicate
.static java.util.List<java.lang.reflect.Method>
findAnnotatedMethods(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, ReflectionUtils.HierarchyTraversalMode traversalMode)
static <A extends java.lang.annotation.Annotation>
java.util.Optional<A>findAnnotation(java.lang.Class<?> clazz, java.lang.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 java.lang.annotation.Annotation>
java.util.Optional<A>findAnnotation(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
static <A extends java.lang.annotation.Annotation>
java.util.Optional<A>findAnnotation(java.lang.reflect.Parameter parameter, int index, java.lang.Class<A> annotationType)
static <A extends java.lang.annotation.Annotation>
java.util.Optional<A>findAnnotation(java.util.Optional<? extends java.lang.reflect.AnnotatedElement> element, java.lang.Class<A> annotationType)
static java.util.List<java.lang.reflect.Field>
findPublicAnnotatedFields(java.lang.Class<?> clazz, java.lang.Class<?> fieldType, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
static <A extends java.lang.annotation.Annotation>
java.util.List<A>findRepeatableAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
static <A extends java.lang.annotation.Annotation>
java.util.List<A>findRepeatableAnnotations(java.lang.reflect.Parameter parameter, int index, java.lang.Class<A> annotationType)
static <A extends java.lang.annotation.Annotation>
java.util.List<A>findRepeatableAnnotations(java.util.Optional<? extends java.lang.reflect.AnnotatedElement> element, java.lang.Class<A> annotationType)
static boolean
isAnnotated(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if an annotation ofannotationType
is either present or meta-present on the suppliedelement
.static boolean
isAnnotated(java.lang.reflect.Parameter parameter, int index, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
static boolean
isAnnotated(java.util.Optional<? extends java.lang.reflect.AnnotatedElement> element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if an annotation ofannotationType
is either present or meta-present on the supplied optionalelement
.
-
-
-
Method Detail
-
isAnnotated
public static boolean isAnnotated(java.util.Optional<? extends java.lang.reflect.AnnotatedElement> element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if an annotation ofannotationType
is either present or meta-present on the supplied optionalelement
.
-
isAnnotated
public static boolean isAnnotated(java.lang.reflect.Parameter parameter, int index, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
- Since:
- 1.8
- See Also:
findAnnotation(Parameter, int, Class)
-
isAnnotated
public static boolean isAnnotated(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if an annotation ofannotationType
is either present or meta-present on the suppliedelement
.- Parameters:
element
- the element on which to search for the annotation; may benull
annotationType
- the annotation type to search for; nevernull
- Returns:
true
if the annotation is present or meta-present- See Also:
findAnnotation(AnnotatedElement, Class)
,AnnotationSupport.isAnnotated(AnnotatedElement, Class)
-
findAnnotation
public static <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.util.Optional<? extends java.lang.reflect.AnnotatedElement> element, java.lang.Class<A> annotationType)
-
findAnnotation
public static <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.lang.reflect.Parameter parameter, int index, java.lang.Class<A> annotationType)
- Since:
- 1.8
- See Also:
findAnnotation(AnnotatedElement, Class)
-
findAnnotation
public static <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
-
findAnnotation
public static <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.lang.Class<?> clazz, java.lang.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 benull
annotationType
- the annotation type to search for; nevernull
searchEnclosingClasses
- whether the enclosing class hierarchy should be searched- Returns:
- an
Optional
containing the annotation; nevernull
but potentially empty - Since:
- 1.8
- See Also:
findAnnotation(AnnotatedElement, Class)
-
findRepeatableAnnotations
public static <A extends java.lang.annotation.Annotation> java.util.List<A> findRepeatableAnnotations(java.util.Optional<? extends java.lang.reflect.AnnotatedElement> element, java.lang.Class<A> annotationType)
- Since:
- 1.5
- See Also:
AnnotationSupport.findRepeatableAnnotations(Optional, Class)
-
findRepeatableAnnotations
public static <A extends java.lang.annotation.Annotation> java.util.List<A> findRepeatableAnnotations(java.lang.reflect.Parameter parameter, int index, java.lang.Class<A> annotationType)
- Since:
- 1.8
- See Also:
findRepeatableAnnotations(AnnotatedElement, Class)
-
findRepeatableAnnotations
public static <A extends java.lang.annotation.Annotation> java.util.List<A> findRepeatableAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
-
findPublicAnnotatedFields
public static java.util.List<java.lang.reflect.Field> findPublicAnnotatedFields(java.lang.Class<?> clazz, java.lang.Class<?> fieldType, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
findAnnotatedFields
public static java.util.List<java.lang.reflect.Field> findAnnotatedFields(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.util.function.Predicate<java.lang.reflect.Field> predicate)
-
findAnnotatedFields
public static java.util.List<java.lang.reflect.Field> findAnnotatedFields(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.util.function.Predicate<java.lang.reflect.Field> predicate, ReflectionUtils.HierarchyTraversalMode traversalMode)
Find all fields of the supplied class or interface that are annotated or meta-annotated with the specifiedannotationType
and match the specifiedpredicate
.- Parameters:
clazz
- the class or interface in which to find the fields; nevernull
annotationType
- the annotation type to search for; nevernull
predicate
- the field filter; nevernull
traversalMode
- the hierarchy traversal mode; nevernull
- Returns:
- the list of all such fields found; neither
null
nor mutable
-
findAnnotatedMethods
public static java.util.List<java.lang.reflect.Method> findAnnotatedMethods(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, ReflectionUtils.HierarchyTraversalMode traversalMode)
-
-