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

    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 specified annotationType and match the specified predicate, 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 specified annotationType and match the specified predicate.
    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)  
    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.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 of annotationType is either present or meta-present on the supplied element.
    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 of annotationType is either present or meta-present on the supplied optional element.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • 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 of annotationType is either present or meta-present on the supplied optional element.
      See Also:
      findAnnotation(Optional, Class), AnnotationSupport.isAnnotated(Optional, Class)
    • isAnnotated

      public static boolean isAnnotated​(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Determine if an annotation of annotationType is either present or meta-present on the supplied element.
      Parameters:
      element - the element on which to search for the annotation; may be null
      annotationType - the annotation type to search for; never null
      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)
      See Also:
      AnnotationSupport.findAnnotation(Optional, 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)
      See Also:
      AnnotationSupport.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.AnnotatedElement element, java.lang.Class<A> annotationType)
      See Also:
      AnnotationSupport.findRepeatableAnnotations(AnnotatedElement, Class)
    • 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)
      See Also:
      AnnotationSupport.findPublicAnnotatedFields(Class, Class, Class)
    • 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 specified annotationType and match the specified predicate, using top-down search semantics within the type hierarchy.
      See Also:
      findAnnotatedFields(Class, Class, Predicate, HierarchyTraversalMode)
    • 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 specified annotationType and match the specified predicate.
      Parameters:
      clazz - the class or interface in which to find the fields; never null
      annotationType - the annotation type to search for; never null
      predicate - the field filter; never null
      traversalMode - the hierarchy traversal mode; never null
      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)
      See Also:
      AnnotationSupport.findAnnotatedMethods(Class, Class, org.junit.platform.commons.support.HierarchyTraversalMode)