Interface AnnotationUtils

  • All Superinterfaces:
    Utils

    public interface AnnotationUtils
    extends Utils
    The utilities class for annotation in the package "javax.lang.model.*"
    Since:
    1.0.0
    Author:
    Mercy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static javax.lang.model.element.AnnotationValueVisitor<java.lang.Object,​javax.lang.model.element.ExecutableElement> DEFAULT_ANNOTATION_VALUE_VISITOR
      The default AnnotationValueVisitor
      static java.lang.annotation.ElementType[] EMPTY_ELEMENT_TYPE_ARRAY
      The empty ElementType array
      static java.lang.String VALUE_ATTRIBUTE_NAME
      The name of the attribute method : value()
      static boolean WITH_DEFAULT  
    • Method Summary

      Static Methods 
      Modifier and Type Method Description
      static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations​(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.CharSequence annotatedTypeName, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)  
      static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations​(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.reflect.Type annotatedType, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)  
      static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations​(javax.lang.model.element.Element element, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)  
      static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations​(javax.lang.model.element.TypeElement element, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)  
      static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations​(javax.lang.model.type.TypeMirror type, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)  
      static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)  
      static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)  
      static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)  
      static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.type.TypeMirror type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)  
      static java.util.List<javax.lang.model.element.AnnotationMirror> findAnnotations​(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)  
      static javax.lang.model.element.AnnotationMirror findMetaAnnotation​(javax.lang.model.element.Element annotatedConstruct, java.lang.CharSequence metaAnnotationClassName)  
      static javax.lang.model.element.AnnotationMirror findMetaAnnotation​(javax.lang.model.element.Element annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationClass)  
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.reflect.Type annotatedType)  
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.element.Element element)  
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)  
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)  
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.type.TypeMirror type)
      Retrieves all AnnotationMirror instances from the given TypeMirror.
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)  
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.type.TypeMirror type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)  
      static javax.lang.model.element.AnnotationMirror getAnnotation​(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.CharSequence annotationClassName)
      Retrieves the first AnnotationMirror of the specified annotation class name from the given AnnotatedConstruct.
      static javax.lang.model.element.AnnotationMirror getAnnotation​(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      Retrieves the first AnnotationMirror of the specified annotation class from the given AnnotatedConstruct.
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAnnotations​(javax.lang.model.AnnotatedConstruct annotatedConstruct)
      Retrieves all AnnotationMirror instances from the given AnnotatedConstruct.
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAnnotations​(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.CharSequence annotationClassName)
      Retrieves all AnnotationMirror instances of the specified annotation class name from the given AnnotatedConstruct.
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAnnotations​(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      Retrieves all AnnotationMirror instances of the specified annotation class from the given AnnotatedConstruct.
      static <T> T getAttribute​(java.util.Map.Entry<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> elementValue)  
      static <T> T getAttribute​(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName)  
      static <T> T getAttribute​(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName, boolean withDefault)  
      static java.lang.String getAttributeName​(javax.lang.model.element.ExecutableElement attributeMethod)  
      static java.util.Map<java.lang.String,​java.lang.Object> getAttributesMap​(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)  
      static java.util.Map<java.lang.String,​java.lang.Object> getAttributesMap​(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, boolean withDefault)
      Get the attributes map from the specified annotation
      static java.util.Map<java.lang.String,​java.lang.Object> getAttributesMap​(javax.lang.model.element.AnnotationMirror annotation)
      Get the attributes map from the specified annotation
      static java.util.Map<java.lang.String,​java.lang.Object> getAttributesMap​(javax.lang.model.element.AnnotationMirror annotation, boolean withDefault)
      Get the attributes map from the specified annotation
      static java.lang.annotation.ElementType[] getElementTypes​(javax.lang.model.element.AnnotationMirror annotation)
      Retrieves the ElementType array from the specified annotation.
      static java.lang.annotation.ElementType[] getElementTypes​(javax.lang.model.type.DeclaredType annotationType)
      Retrieves the ElementType array from the specified annotation type by checking the Target annotation associated with it.
      static java.util.Map.Entry<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValue​(java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> elementValues, java.lang.String attributeName)  
      static java.util.Map.Entry<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValue​(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName, boolean withDefault)  
      static java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValues​(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)  
      static java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValues​(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, boolean withDefault)  
      static java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValues​(javax.lang.model.element.AnnotationMirror annotation)  
      static java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValues​(javax.lang.model.element.AnnotationMirror annotation, boolean withDefault)  
      static <T> T getValue​(javax.lang.model.element.AnnotationMirror annotation)  
      static boolean isAnnotationPresent​(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)  
      static boolean isAnnotationPresent​(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)  
      static boolean matchesAnnotationType​(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.reflect.Type annotationType)  
      static boolean matchesAnnotationTypeName​(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.CharSequence annotationTypeName)  
      static boolean matchesAttributeMethod​(javax.lang.model.element.ExecutableElement attributeMethod, java.lang.String attributeName)  
      static boolean matchesAttributeValue​(javax.lang.model.element.AnnotationValue annotationValue, java.lang.Object attributeValue)  
    • Field Detail

      • VALUE_ATTRIBUTE_NAME

        static final java.lang.String VALUE_ATTRIBUTE_NAME
        The name of the attribute method : value()
        See Also:
        Constant Field Values
      • DEFAULT_ANNOTATION_VALUE_VISITOR

        static final javax.lang.model.element.AnnotationValueVisitor<java.lang.Object,​javax.lang.model.element.ExecutableElement> DEFAULT_ANNOTATION_VALUE_VISITOR
        The default AnnotationValueVisitor
      • EMPTY_ELEMENT_TYPE_ARRAY

        static final java.lang.annotation.ElementType[] EMPTY_ELEMENT_TYPE_ARRAY
        The empty ElementType array
    • Method Detail

      • getAnnotation

        static javax.lang.model.element.AnnotationMirror getAnnotation​(javax.lang.model.AnnotatedConstruct annotatedConstruct,
                                                                       java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
        Retrieves the first AnnotationMirror of the specified annotation class from the given AnnotatedConstruct. If either the construct or the annotation class is null, this method returns null.
        Parameters:
        annotatedConstruct - the annotated construct to search for annotations, may be null
        annotationClass - the annotation class to look for, may be null
        Returns:
        the first matching AnnotationMirror, or null if none found
      • getAnnotation

        static javax.lang.model.element.AnnotationMirror getAnnotation​(javax.lang.model.AnnotatedConstruct annotatedConstruct,
                                                                       java.lang.CharSequence annotationClassName)
        Retrieves the first AnnotationMirror of the specified annotation class name from the given AnnotatedConstruct. If either the construct or the annotation class name is null, this method returns null.
        Parameters:
        annotatedConstruct - the annotated construct to search for annotations, may be null
        annotationClassName - the fully qualified class name of the annotation to look for, may be null
        Returns:
        the first matching AnnotationMirror, or null if none found
      • getAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> getAnnotations​(javax.lang.model.AnnotatedConstruct annotatedConstruct)
        Retrieves all AnnotationMirror instances from the given AnnotatedConstruct. If the annotated construct is null, this method returns an empty list.
        Parameters:
        annotatedConstruct - the annotated construct to search for annotations, may be null
        Returns:
        a non-null immutable list of AnnotationMirror instances; never null
      • getAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> getAnnotations​(javax.lang.model.AnnotatedConstruct annotatedConstruct,
                                                                                        java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
        Retrieves all AnnotationMirror instances of the specified annotation class from the given AnnotatedConstruct. If either the construct or the annotation class is null, this method returns an empty list.
        Parameters:
        annotatedConstruct - the annotated construct to search for annotations, may be null
        annotationClass - the annotation class to look for, may be null
        Returns:
        a non-null immutable list of AnnotationMirror instances; never null
      • getAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> getAnnotations​(javax.lang.model.AnnotatedConstruct annotatedConstruct,
                                                                                        java.lang.CharSequence annotationClassName)
        Retrieves all AnnotationMirror instances of the specified annotation class name from the given AnnotatedConstruct. If either the construct or the annotation class name is null, this method returns an empty list.
        Parameters:
        annotatedConstruct - the annotated construct to search for annotations, may be null
        annotationClassName - the fully qualified class name of the annotation to look for, may be null
        Returns:
        a non-null immutable list of AnnotationMirror instances; never null
      • getAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.type.TypeMirror type)
        Retrieves all AnnotationMirror instances from the given TypeMirror. If the type mirror is null, this method returns an empty list.
        Parameters:
        type - the type mirror to search for annotations, may be null
        Returns:
        a non-null immutable list of AnnotationMirror instances; never null
      • getAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.element.Element element)
      • getAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.type.TypeMirror type,
                                                                                           java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      • getAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.element.Element element,
                                                                                           java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      • getAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.type.TypeMirror type,
                                                                                           java.lang.CharSequence annotationClassName)
      • getAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.element.Element element,
                                                                                           java.lang.CharSequence annotationClassName)
      • getAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.annotation.processing.ProcessingEnvironment processingEnv,
                                                                                           java.lang.reflect.Type annotatedType)
      • findAnnotation

        static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.type.TypeMirror type,
                                                                        java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      • findAnnotation

        static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.type.TypeMirror type,
                                                                        java.lang.CharSequence annotationClassName)
      • findAnnotation

        static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.element.Element element,
                                                                        java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      • findAnnotation

        static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.element.Element element,
                                                                        java.lang.CharSequence annotationClassName)
      • findMetaAnnotation

        static javax.lang.model.element.AnnotationMirror findMetaAnnotation​(javax.lang.model.element.Element annotatedConstruct,
                                                                            java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationClass)
      • findMetaAnnotation

        static javax.lang.model.element.AnnotationMirror findMetaAnnotation​(javax.lang.model.element.Element annotatedConstruct,
                                                                            java.lang.CharSequence metaAnnotationClassName)
      • isAnnotationPresent

        static boolean isAnnotationPresent​(javax.lang.model.element.Element element,
                                           java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      • isAnnotationPresent

        static boolean isAnnotationPresent​(javax.lang.model.element.Element element,
                                           java.lang.CharSequence annotationClassName)
      • findAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> findAnnotations​(javax.lang.model.AnnotatedConstruct annotatedConstruct,
                                                                                         java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
      • findAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations​(javax.lang.model.type.TypeMirror type,
                                                                                            java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
      • findAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations​(javax.lang.model.element.TypeElement element,
                                                                                            java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
      • findAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations​(javax.lang.model.element.Element element,
                                                                                            java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
      • findAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations​(javax.annotation.processing.ProcessingEnvironment processingEnv,
                                                                                            java.lang.reflect.Type annotatedType,
                                                                                            java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
      • findAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations​(javax.annotation.processing.ProcessingEnvironment processingEnv,
                                                                                            java.lang.CharSequence annotatedTypeName,
                                                                                            java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
      • matchesAnnotationType

        static boolean matchesAnnotationType​(javax.lang.model.element.AnnotationMirror annotationMirror,
                                             java.lang.reflect.Type annotationType)
      • matchesAnnotationTypeName

        static boolean matchesAnnotationTypeName​(javax.lang.model.element.AnnotationMirror annotationMirror,
                                                 java.lang.CharSequence annotationTypeName)
      • getAttributeName

        static java.lang.String getAttributeName​(javax.lang.model.element.ExecutableElement attributeMethod)
      • matchesAttributeMethod

        static boolean matchesAttributeMethod​(javax.lang.model.element.ExecutableElement attributeMethod,
                                              java.lang.String attributeName)
      • matchesAttributeValue

        static boolean matchesAttributeValue​(javax.lang.model.element.AnnotationValue annotationValue,
                                             java.lang.Object attributeValue)
      • getAttributesMap

        static java.util.Map<java.lang.String,​java.lang.Object> getAttributesMap​(javax.lang.model.AnnotatedConstruct annotatedConstruct,
                                                                                       java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      • getAttributesMap

        static java.util.Map<java.lang.String,​java.lang.Object> getAttributesMap​(javax.lang.model.AnnotatedConstruct annotatedConstruct,
                                                                                       java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                                                                       boolean withDefault)
        Get the attributes map from the specified annotation
        Parameters:
        annotatedConstruct - the annotated construct
        annotationClass - the class of annotation
        withDefault - with default attribute value
        Returns:
        non-null read-only Map
      • getAttributesMap

        static java.util.Map<java.lang.String,​java.lang.Object> getAttributesMap​(javax.lang.model.element.AnnotationMirror annotation)
        Get the attributes map from the specified annotation
        Parameters:
        annotation - the specified annotation
        Returns:
        non-null read-only Map
      • getAttributesMap

        static java.util.Map<java.lang.String,​java.lang.Object> getAttributesMap​(javax.lang.model.element.AnnotationMirror annotation,
                                                                                       boolean withDefault)
        Get the attributes map from the specified annotation
        Parameters:
        annotation - the specified annotation
        withDefault - with default attribute value
        Returns:
        non-null read-only Map
      • getElementValues

        static java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValues​(javax.lang.model.AnnotatedConstruct annotatedConstruct,
                                                                                                                                         java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      • getElementValues

        static java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValues​(javax.lang.model.AnnotatedConstruct annotatedConstruct,
                                                                                                                                         java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                                                                                                                         boolean withDefault)
      • getElementValues

        static java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValues​(javax.lang.model.element.AnnotationMirror annotation)
      • getElementValues

        static java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValues​(javax.lang.model.element.AnnotationMirror annotation,
                                                                                                                                         boolean withDefault)
      • getElementValue

        static java.util.Map.Entry<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValue​(javax.lang.model.element.AnnotationMirror annotation,
                                                                                                                                              java.lang.String attributeName,
                                                                                                                                              boolean withDefault)
      • getElementValue

        static java.util.Map.Entry<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValue​(java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> elementValues,
                                                                                                                                              java.lang.String attributeName)
      • getAttribute

        static <T> T getAttribute​(javax.lang.model.element.AnnotationMirror annotation,
                                  java.lang.String attributeName)
      • getAttribute

        static <T> T getAttribute​(javax.lang.model.element.AnnotationMirror annotation,
                                  java.lang.String attributeName,
                                  boolean withDefault)
      • getAttribute

        static <T> T getAttribute​(java.util.Map.Entry<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> elementValue)
      • getValue

        static <T> T getValue​(javax.lang.model.element.AnnotationMirror annotation)
      • getElementTypes

        static java.lang.annotation.ElementType[] getElementTypes​(javax.lang.model.element.AnnotationMirror annotation)
        Retrieves the ElementType array from the specified annotation.
        Parameters:
        annotation - the specified annotation, may be null
        Returns:
        a non-null array of ElementType; never null, returns an empty array if the annotation is null
      • getElementTypes

        static java.lang.annotation.ElementType[] getElementTypes​(javax.lang.model.type.DeclaredType annotationType)
        Retrieves the ElementType array from the specified annotation type by checking the Target annotation associated with it. If the annotation type does not have a Target annotation, an empty array is returned.
        Parameters:
        annotationType - the declared type of the annotation
        Returns:
        a non-null array of ElementType; never null, returns an empty array if no Target annotation is present