Class AnnotationUtils


  • public abstract class AnnotationUtils
    extends BaseUtils
    Annotation Utilities class
    Since:
    1.0.0
    Author:
    Mercy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.Class<? extends java.lang.annotation.Annotation> CALLER_SENSITIVE_ANNOTATION_CLASS
      The annotation Class of jdk.internal.reflect.CallerSensitive that may be null
      static java.lang.String CALLER_SENSITIVE_ANNOTATION_CLASS_NAME
      The annotation class name of jdk.internal.reflect.CallerSensitive
      static java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> NATIVE_ANNOTATION_TYPES  
    • Constructor Summary

      Constructors 
      Constructor Description
      AnnotationUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean contains​(java.util.Collection<java.lang.annotation.Annotation> annotations, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)  
      static boolean exists​(java.lang.annotation.Annotation[] annotations, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)  
      static boolean exists​(java.lang.Iterable<java.lang.annotation.Annotation> annotations, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)  
      static boolean existsAnnotated​(java.lang.reflect.AnnotatedElement[] annotatedElements, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)  
      static <S extends java.lang.Iterable<java.lang.annotation.Annotation>>
      java.util.Optional<java.lang.annotation.Annotation>
      filterAnnotation​(S annotations, java.util.function.Predicate<java.lang.annotation.Annotation>... annotationsToFilter)  
      static java.util.List<java.lang.annotation.Annotation> filterAnnotations​(java.lang.annotation.Annotation[] annotations, java.util.function.Predicate<java.lang.annotation.Annotation>... annotationsToFilter)  
      static <S extends java.lang.Iterable<java.lang.annotation.Annotation>>
      S
      filterAnnotations​(S annotations, java.util.function.Predicate<java.lang.annotation.Annotation>... annotationsToFilter)  
      static <A extends java.lang.annotation.Annotation>
      A
      findAnnotation​(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType)
      Find the annotation that is annotated on the specified element may be a meta-annotation
      static <A extends java.lang.annotation.Annotation>
      A
      findAnnotation​(java.lang.reflect.AnnotatedElement annotatedElement, java.util.function.Predicate<java.lang.annotation.Annotation>... annotationFilters)
      Find the annotation that is annotated on the specified element may be a meta-annotation
      static java.util.List<java.lang.annotation.Annotation> getAllDeclaredAnnotations​(java.lang.Class<?> type, java.util.function.Predicate<java.lang.annotation.Annotation>... annotationsToFilter)
      Get all directly declared annotations of the specified type and its' all hierarchical types, not including meta annotations.
      static java.util.List<java.lang.annotation.Annotation> getAllDeclaredAnnotations​(java.lang.reflect.AnnotatedElement annotatedElement, java.util.function.Predicate<java.lang.annotation.Annotation>... annotationsToFilter)
      Get all directly declared annotations of the the annotated element, not including meta annotations.
      static java.util.Map<java.lang.String,​java.lang.Object> getAttributesMap​(java.lang.annotation.Annotation annotation, java.util.function.Predicate<java.lang.reflect.Method>... attributesToFilter)  
      static <T> T getAttributeValue​(java.lang.annotation.Annotation[] annotations, java.lang.String attributeName, java.lang.Class<T> returnType)  
      static <T> T getAttributeValue​(java.lang.annotation.Annotation annotation, java.lang.String attributeName, java.lang.Class<T> returnType)  
      static java.lang.Object[] getAttributeValues​(java.lang.annotation.Annotation annotation, java.util.function.Predicate<java.lang.reflect.Method>... attributesToFilter)  
      static java.util.List<java.lang.annotation.Annotation> getDeclaredAnnotations​(java.lang.reflect.AnnotatedElement annotatedElement, java.util.function.Predicate<java.lang.annotation.Annotation>... annotationsToFilter)
      Get annotations that are directly present on this element.
      static boolean isAnnotationMethod​(java.lang.reflect.Method attributeMethod)  
      static boolean isAnnotationPresent​(java.lang.annotation.Annotation annotation, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)  
      static boolean isAnnotationPresent​(java.lang.annotation.Annotation annotation, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)  
      static boolean isAnnotationPresent​(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)  
      static boolean isAnnotationPresent​(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)  
      static boolean isCallerSensitivePresent()
      Is jdk.internal.reflect.CallerSensitive class present or not
      static boolean isMetaAnnotation​(java.lang.annotation.Annotation annotation, java.lang.Class<? extends java.lang.annotation.Annotation>... metaAnnotationTypes)  
      static boolean isMetaAnnotation​(java.lang.annotation.Annotation annotation, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> metaAnnotationTypes)  
      static boolean isMetaAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation>... metaAnnotationTypes)  
      static boolean isMetaAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> metaAnnotationTypes)  
      • Methods inherited from class java.lang.Object

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

      • NATIVE_ANNOTATION_TYPES

        public static final java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> NATIVE_ANNOTATION_TYPES
      • CALLER_SENSITIVE_ANNOTATION_CLASS_NAME

        public static final java.lang.String CALLER_SENSITIVE_ANNOTATION_CLASS_NAME
        The annotation class name of jdk.internal.reflect.CallerSensitive
        See Also:
        Constant Field Values
      • CALLER_SENSITIVE_ANNOTATION_CLASS

        public static final java.lang.Class<? extends java.lang.annotation.Annotation> CALLER_SENSITIVE_ANNOTATION_CLASS
        The annotation Class of jdk.internal.reflect.CallerSensitive that may be null
    • Constructor Detail

      • AnnotationUtils

        public AnnotationUtils()
    • Method Detail

      • findAnnotation

        public static <A extends java.lang.annotation.Annotation> A findAnnotation​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                                                   java.lang.Class<A> annotationType)
        Find the annotation that is annotated on the specified element may be a meta-annotation
        Type Parameters:
        A - the required type of annotation
        Parameters:
        annotatedElement - the annotated element
        annotationType - the type of annotation
        Returns:
        If found, return first matched-type annotation, or null
      • findAnnotation

        public static <A extends java.lang.annotation.Annotation> A findAnnotation​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                                                   java.util.function.Predicate<java.lang.annotation.Annotation>... annotationFilters)
        Find the annotation that is annotated on the specified element may be a meta-annotation
        Type Parameters:
        A - the required type of annotation
        Parameters:
        annotatedElement - the annotated element
        annotationFilters - the filters of annotations
        Returns:
        If found, return first matched-type annotation, or null
      • isMetaAnnotation

        public static boolean isMetaAnnotation​(java.lang.annotation.Annotation annotation,
                                               java.lang.Class<? extends java.lang.annotation.Annotation>... metaAnnotationTypes)
      • isMetaAnnotation

        public static boolean isMetaAnnotation​(java.lang.annotation.Annotation annotation,
                                               java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> metaAnnotationTypes)
      • isMetaAnnotation

        public static boolean isMetaAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
                                               java.lang.Class<? extends java.lang.annotation.Annotation>... metaAnnotationTypes)
      • isMetaAnnotation

        public static boolean isMetaAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
                                               java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> metaAnnotationTypes)
      • getAllDeclaredAnnotations

        public static java.util.List<java.lang.annotation.Annotation> getAllDeclaredAnnotations​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                                                                java.util.function.Predicate<java.lang.annotation.Annotation>... annotationsToFilter)
        Get all directly declared annotations of the the annotated element, not including meta annotations.
        Parameters:
        annotatedElement - the annotated element
        annotationsToFilter - the annotations to filter
        Returns:
        non-null read-only List
      • filterAnnotation

        public static <S extends java.lang.Iterable<java.lang.annotation.Annotation>> java.util.Optional<java.lang.annotation.Annotation> filterAnnotation​(S annotations,
                                                                                                                                                           java.util.function.Predicate<java.lang.annotation.Annotation>... annotationsToFilter)
      • filterAnnotations

        public static java.util.List<java.lang.annotation.Annotation> filterAnnotations​(java.lang.annotation.Annotation[] annotations,
                                                                                        java.util.function.Predicate<java.lang.annotation.Annotation>... annotationsToFilter)
      • filterAnnotations

        public static <S extends java.lang.Iterable<java.lang.annotation.Annotation>> S filterAnnotations​(S annotations,
                                                                                                          java.util.function.Predicate<java.lang.annotation.Annotation>... annotationsToFilter)
      • getAllDeclaredAnnotations

        public static java.util.List<java.lang.annotation.Annotation> getAllDeclaredAnnotations​(java.lang.Class<?> type,
                                                                                                java.util.function.Predicate<java.lang.annotation.Annotation>... annotationsToFilter)
        Get all directly declared annotations of the specified type and its' all hierarchical types, not including meta annotations.
        Parameters:
        type - the specified type
        annotationsToFilter - the annotations to filter
        Returns:
        non-null read-only List
      • getDeclaredAnnotations

        public static java.util.List<java.lang.annotation.Annotation> getDeclaredAnnotations​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                                                             java.util.function.Predicate<java.lang.annotation.Annotation>... annotationsToFilter)
        Get annotations that are directly present on this element. This method ignores inherited annotations.
        Parameters:
        annotatedElement - the annotated element
        annotationsToFilter - the annotations to filter
        Returns:
        non-null read-only List
      • getAttributeValue

        public static <T> T getAttributeValue​(java.lang.annotation.Annotation[] annotations,
                                              java.lang.String attributeName,
                                              java.lang.Class<T> returnType)
      • getAttributeValue

        public static <T> T getAttributeValue​(java.lang.annotation.Annotation annotation,
                                              java.lang.String attributeName,
                                              java.lang.Class<T> returnType)
      • contains

        public static boolean contains​(java.util.Collection<java.lang.annotation.Annotation> annotations,
                                       java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      • exists

        public static boolean exists​(java.lang.Iterable<java.lang.annotation.Annotation> annotations,
                                     java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      • exists

        public static boolean exists​(java.lang.annotation.Annotation[] annotations,
                                     java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      • existsAnnotated

        public static boolean existsAnnotated​(java.lang.reflect.AnnotatedElement[] annotatedElements,
                                              java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      • isAnnotationPresent

        public static boolean isAnnotationPresent​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                  java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      • isAnnotationPresent

        public static boolean isAnnotationPresent​(java.lang.annotation.Annotation annotation,
                                                  java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      • isAnnotationPresent

        public static boolean isAnnotationPresent​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                  java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
      • isAnnotationPresent

        public static boolean isAnnotationPresent​(java.lang.annotation.Annotation annotation,
                                                  java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
      • getAttributeValues

        public static java.lang.Object[] getAttributeValues​(java.lang.annotation.Annotation annotation,
                                                            java.util.function.Predicate<java.lang.reflect.Method>... attributesToFilter)
      • getAttributesMap

        public static java.util.Map<java.lang.String,​java.lang.Object> getAttributesMap​(java.lang.annotation.Annotation annotation,
                                                                                              java.util.function.Predicate<java.lang.reflect.Method>... attributesToFilter)
      • isAnnotationMethod

        public static boolean isAnnotationMethod​(java.lang.reflect.Method attributeMethod)
      • isCallerSensitivePresent

        public static boolean isCallerSensitivePresent()
        Is jdk.internal.reflect.CallerSensitive class present or not
        Returns:
        true if jdk.internal.reflect.CallerSensitive presents
        See Also:
        CALLER_SENSITIVE_ANNOTATION_CLASS