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.ObjectCollection 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
AnnotationSupportclass.- Since:
- 1.0
- See Also:
Annotation,AnnotatedElement,AnnotationSupport
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.concurrent.ConcurrentHashMap<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.Boolean>repeatableAnnotationContainerCache
-
Constructor Summary
Constructors Modifier Constructor Description privateAnnotationUtils()
-
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)Find all fields of the supplied class or interface that are annotated or meta-annotated with the specifiedannotationTypeand match the specifiedpredicate, using top-down search semantics within the type hierarchy.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 specifiedannotationTypeand 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.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)private static <A extends java.lang.annotation.Annotation>
java.util.Optional<A>findAnnotation(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType, boolean inherited, java.util.Set<java.lang.annotation.Annotation> visited)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)private static <A extends java.lang.annotation.Annotation>
java.util.Optional<A>findMetaAnnotation(java.lang.Class<A> annotationType, java.lang.annotation.Annotation[] candidates, boolean inherited, java.util.Set<java.lang.annotation.Annotation> visited)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)private static <A extends java.lang.annotation.Annotation>
voidfindRepeatableAnnotations(java.lang.annotation.Annotation[] candidates, java.lang.Class<A> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> containerType, boolean inherited, java.util.Set<A> found, java.util.Set<java.lang.annotation.Annotation> visited)static <A extends java.lang.annotation.Annotation>
java.util.List<A>findRepeatableAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)private static <A extends java.lang.annotation.Annotation>
voidfindRepeatableAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> containerType, boolean inherited, java.util.Set<A> found, java.util.Set<java.lang.annotation.Annotation> visited)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 booleanisAnnotated(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Determine if an annotation ofannotationTypeis either present or meta-present on the suppliedelement.static booleanisAnnotated(java.util.Optional<? extends java.lang.reflect.AnnotatedElement> element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Determine if an annotation ofannotationTypeis either present or meta-present on the supplied optionalelement.private static booleanisInJavaLangAnnotationPackage(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)private static booleanisRepeatableAnnotationContainer(java.lang.Class<? extends java.lang.annotation.Annotation> candidateContainerType)Determine if the supplied annotation type is a container for a repeatable annotation.
-
-
-
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 ofannotationTypeis either present or meta-present on the supplied optionalelement.
-
isAnnotated
public static boolean isAnnotated(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.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(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.AnnotatedElement element, java.lang.Class<A> annotationType)
-
findAnnotation
private static <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType, boolean inherited, java.util.Set<java.lang.annotation.Annotation> visited)
-
findMetaAnnotation
private static <A extends java.lang.annotation.Annotation> java.util.Optional<A> findMetaAnnotation(java.lang.Class<A> annotationType, java.lang.annotation.Annotation[] candidates, boolean inherited, java.util.Set<java.lang.annotation.Annotation> visited)
-
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.AnnotatedElement element, java.lang.Class<A> annotationType)
-
findRepeatableAnnotations
private static <A extends java.lang.annotation.Annotation> void findRepeatableAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> containerType, boolean inherited, java.util.Set<A> found, java.util.Set<java.lang.annotation.Annotation> visited)
-
findRepeatableAnnotations
private static <A extends java.lang.annotation.Annotation> void findRepeatableAnnotations(java.lang.annotation.Annotation[] candidates, java.lang.Class<A> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> containerType, boolean inherited, java.util.Set<A> found, java.util.Set<java.lang.annotation.Annotation> visited)
-
isRepeatableAnnotationContainer
private static boolean isRepeatableAnnotationContainer(java.lang.Class<? extends java.lang.annotation.Annotation> candidateContainerType)
Determine if the supplied annotation type is a container for a repeatable annotation.- Since:
- 1.5
-
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)Find all fields of the supplied class or interface that are annotated or meta-annotated with the specifiedannotationTypeand match the specifiedpredicate, using top-down search semantics within the type hierarchy.
-
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 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 java.util.List<java.lang.reflect.Method> findAnnotatedMethods(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, ReflectionUtils.HierarchyTraversalMode traversalMode)
-
isInJavaLangAnnotationPackage
private static boolean isInJavaLangAnnotationPackage(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
-