Class AnnotationUtils

java.lang.Object
io.micronaut.test.annotation.AnnotationUtils

public final class AnnotationUtils extends Object
Common annotation utilities.
Since:
1.0.1
  • Method Details

    • findAnnotation

      public static <A extends Annotation> Optional<A> findAnnotation(Class<?> type, Class<A> annotationType)
      Finds an annotation that is directly present or meta-present on the given class or on an interface it implements. If the annotation type is @Inherited, superclasses are searched as well, including through a composed annotation that is not itself inherited.
      Type Parameters:
      A - the annotation type
      Parameters:
      type - the class to search on
      annotationType - the annotation type to search for
      Returns:
      the annotation, if there is one
      Since:
      5.2.1
    • isAnnotated

      public static boolean isAnnotated(Class<?> type, String annotationName)
      Checks whether an annotation is directly present or meta-present on the given class, for an annotation type that may not be on the classpath.
      Parameters:
      type - the class to search on
      annotationName - the fully qualified name of the annotation type
      Returns:
      true if the annotation is present
      Since:
      5.2.1
    • findRepeatableAnnotations

      public static <A extends Annotation> List<A> findRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType)
      Find all repeatable annotations of annotationType that are either present, indirectly present, or meta-present on the supplied AnnotatedElement.

      This method extends the functionality of AnnotatedElement.getAnnotationsByType(Class) with additional support for meta-annotations.

      In addition, if the element is a class and the repeatable annotation is @Inherited, this method will search on superclasses first in order to support top-down semantics. The result is that this algorithm finds repeatable annotations that would be shadowed and therefore not visible according to Java's standard semantics for inherited, repeatable annotations.

      If the element is a class and the repeatable annotation is not discovered within the class hierarchy, this method will additionally search on interfaces implemented by each class in the hierarchy.

      If the supplied element is null, this method simply returns an empty list.

      Type Parameters:
      A - the annotation instance
      Parameters:
      element - the element to search on, potentially null
      annotationType - the repeatable annotation type to search for; never null
      Returns:
      the list of all such annotations found; neither null nor mutable
      See Also: