Class Annotations


  • public class Annotations
    extends java.lang.Object
    Utilities for working with annotations.
    • Constructor Summary

      Constructors 
      Constructor Description
      Annotations()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Set<java.lang.annotation.Annotation> findAnnotations​(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Finds all annotations of the given type recursively from the given AnnotatedElement.
      static java.util.Set<java.lang.annotation.Annotation> findDirectlyMetaAnnotatedAnnotations​(java.lang.reflect.AnnotatedElement element, java.lang.annotation.Annotation metaAnnotation)
      Recursively finds annotations directly annotated by a given meta annotation, starting from the given AnnotatedElement.
      static java.util.Set<java.lang.annotation.Annotation> findDirectlyMetaAnnotatedAnnotations​(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotation)
      Recursively finds annotations directly annotated by a given meta annotation class, starting from the given AnnotatedElement.
      static java.util.List<java.lang.annotation.Annotation> findMetaAnnotatedAnnotations​(java.lang.reflect.AnnotatedElement element, java.lang.annotation.Annotation metaAnnotation)
      Returns Annotations on the given AnnotatedElement which are annotated with the given meta annotation directly or indirectly.
      static boolean isMetaAnnotated​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.annotation.Annotation metaAnnotation)
      Returns true if the given annotation Class is directly or indirectly meta annotated with the given meta annotation.
      static <A extends java.lang.annotation.Annotation>
      A
      of​(java.lang.Class<A> annotationClass)
      Creates an Annotation without parameters.
      static <A extends java.lang.annotation.Annotation>
      A
      of​(java.lang.Class<A> annotationClass, java.util.Map<java.lang.String,​java.lang.Object> values)
      Creates an Annotation with parameters.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Annotations

        public Annotations()
    • Method Detail

      • of

        public static <A extends java.lang.annotation.Annotation> A of​(java.lang.Class<A> annotationClass,
                                                                       java.util.Map<java.lang.String,​java.lang.Object> values)
        Creates an Annotation with parameters.
        Type Parameters:
        A - the annotation type
        Parameters:
        annotationClass - a Class which extends Annotation, cannot be null
        values - a map of values for the annotations parameters, cannot be null
        Returns:
        an Annotation, never null
        Throws:
        java.lang.IllegalArgumentException - when the given parameters could not be converted to an annotation
      • of

        public static <A extends java.lang.annotation.Annotation> A of​(java.lang.Class<A> annotationClass)
        Creates an Annotation without parameters.
        Type Parameters:
        A - the annotation type
        Parameters:
        annotationClass - a Class which extends Annotation, cannot be null
        Returns:
        an Annotation, never null
        Throws:
        java.lang.IllegalArgumentException - when the given parameters could not be converted to an annotation
      • findAnnotations

        public static java.util.Set<java.lang.annotation.Annotation> findAnnotations​(java.lang.reflect.AnnotatedElement element,
                                                                                     java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
        Finds all annotations of the given type recursively from the given AnnotatedElement.
        Parameters:
        element - an AnnotatedElement, cannot be null
        annotationType - a Class which extends Annotation, cannot be null
        Returns:
        a set of Annotations that were found directly or indirectly on the given element, never null and never contains nulls
      • findDirectlyMetaAnnotatedAnnotations

        public static java.util.Set<java.lang.annotation.Annotation> findDirectlyMetaAnnotatedAnnotations​(java.lang.reflect.AnnotatedElement element,
                                                                                                          java.lang.annotation.Annotation metaAnnotation)
        Recursively finds annotations directly annotated by a given meta annotation, starting from the given AnnotatedElement. The annotations returned are not necessarily direct annotations on the given element, but can be meta annotations which are annotated with the given meta annotation.
        Parameters:
        element - an AnnotatedElement, cannot be null
        metaAnnotation - an Annotation, cannot be null
        Returns:
        a mutable set of Annotations directly annotated with the given meta annotation, never null and never contains nulls
      • findDirectlyMetaAnnotatedAnnotations

        public static java.util.Set<java.lang.annotation.Annotation> findDirectlyMetaAnnotatedAnnotations​(java.lang.reflect.AnnotatedElement element,
                                                                                                          java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotation)
        Recursively finds annotations directly annotated by a given meta annotation class, starting from the given AnnotatedElement. The annotations returned are not necessarily direct annotations on the given element, but can be meta annotations which are annotated with the given meta annotation.
        Parameters:
        element - an AnnotatedElement, cannot be null
        metaAnnotation - an Annotation, cannot be null
        Returns:
        a mutable set of Annotations directly annotated with the given meta annotation, never null and never contains nulls
      • findMetaAnnotatedAnnotations

        public static java.util.List<java.lang.annotation.Annotation> findMetaAnnotatedAnnotations​(java.lang.reflect.AnnotatedElement element,
                                                                                                   java.lang.annotation.Annotation metaAnnotation)
        Returns Annotations on the given AnnotatedElement which are annotated with the given meta annotation directly or indirectly.
        Parameters:
        element - an AnnotatedElement, cannot be null
        metaAnnotation - an Annotation, cannot be null
        Returns:
        Annotations on the given AnnotatedElement which are annotated with the given meta annotation directly or indirectly, never null and never contains nulls
      • isMetaAnnotated

        public static boolean isMetaAnnotated​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
                                              java.lang.annotation.Annotation metaAnnotation)
        Returns true if the given annotation Class is directly or indirectly meta annotated with the given meta annotation.
        Parameters:
        annotationType - a Class which extends Annotation to check, cannot be null
        metaAnnotation - a meta Annotation to search for, cannot be null
        Returns:
        true if the given Annotation is directly or indirectly meta annotated with the given meta annotation, otherwise false