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)
      Retrieves all AnnotationMirror instances of the specified annotated type name from the given ProcessingEnvironment.
      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)
      Retrieves all AnnotationMirror instances of the specified annotated type from the given ProcessingEnvironment.
      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)
      Retrieves all AnnotationMirror instances from the given Element, applying the specified annotation filters to narrow down the results.
      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)
      Retrieves all AnnotationMirror instances from the given TypeMirror, applying the specified annotation filters to narrow down the results.
      static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
      Retrieves the first AnnotationMirror of the specified annotation class name from the given Element.
      static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      Retrieves the first AnnotationMirror of the specified annotation class from the given Element.
      static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)
      Retrieves the first AnnotationMirror of the specified annotation class name from the given TypeMirror.
      static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.type.TypeMirror type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      Retrieves the first AnnotationMirror of the specified annotation class from the given TypeMirror.
      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)
      Retrieves all AnnotationMirror instances from the given AnnotatedConstruct that match the provided annotation filters.
      static javax.lang.model.element.AnnotationMirror findMetaAnnotation​(javax.lang.model.element.Element annotatedConstruct, java.lang.CharSequence metaAnnotationClassName)
      Retrieves the first meta-annotation of the specified meta-annotation class name from the given annotated element.
      static javax.lang.model.element.AnnotationMirror findMetaAnnotation​(javax.lang.model.element.Element annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationClass)
      Retrieves the first meta-annotation of the specified annotation class from the given annotated element.
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.reflect.Type annotatedType)
      Retrieves all AnnotationMirror instances of the specified annotated type from the given ProcessingEnvironment.
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.element.Element element)
      Retrieves all AnnotationMirror instances from the given Element.
      static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
      Retrieves all AnnotationMirror instances of the specified annotation class name from the given Element.
      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)
      Retrieves all AnnotationMirror instances of the specified annotation class from the given Element.
      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)
      Retrieves all AnnotationMirror instances of the specified annotation class name from the given TypeMirror.
      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)
      Retrieves all AnnotationMirror instances of the specified annotation class from the given TypeMirror.
      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)
      Retrieves the value of the specified attribute from the provided entry containing the attribute method and its corresponding annotation value.
      static <T> T getAttribute​(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName)
      Retrieves the value of the specified attribute from the given annotation.
      static <T> T getAttribute​(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName, boolean withDefault)
      Retrieves the value of the specified attribute from the given annotation, optionally including the default value.
      static java.lang.String getAttributeName​(javax.lang.model.element.ExecutableElement attributeMethod)
      Retrieves the name of the attribute method from the given ExecutableElement.
      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)
      Get the attributes map from the specified annotation
      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)
      Retrieves the attribute method and its corresponding annotation value from the specified element values map based on the given attribute name.
      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)
      Retrieves the attribute method and its corresponding annotation value from the specified annotation based on the given attribute name.
      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)
      Retrieves the map of annotation attribute methods to their corresponding values from the specified AnnotatedConstruct and annotation class.
      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)
      Retrieves the map of annotation attribute methods to their corresponding values from the specified AnnotatedConstruct and annotation class.
      static java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValues​(javax.lang.model.element.AnnotationMirror annotation)
      Retrieves a map of annotation attribute methods to their corresponding values from the specified AnnotationMirror.
      static java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValues​(javax.lang.model.element.AnnotationMirror annotation, boolean withDefault)
      Retrieves a map of annotation attribute methods to their corresponding values from the specified AnnotationMirror.
      static <T> T getValue​(javax.lang.model.element.AnnotationMirror annotation)
      Retrieves the value of the specified annotation by accessing the default attribute method named "value".
      static boolean isAnnotationPresent​(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
      Checks if the specified annotation (by class name) is present on the given element, either directly or as a meta-annotation.
      static boolean isAnnotationPresent​(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      Checks if the specified annotation is present on the given element, either directly or as a meta-annotation.
      static boolean matchesAnnotationType​(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.reflect.Type annotationType)
      Checks if the given annotation mirror has the same type as the specified Type.
      static boolean matchesAnnotationTypeName​(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.CharSequence annotationTypeName)
      Checks if the given annotation mirror has the same type as the specified annotation class name.
      static boolean matchesAttributeMethod​(javax.lang.model.element.ExecutableElement attributeMethod, java.lang.String attributeName)
      Checks if the provided executable element represents an annotation attribute method with the specified name.
      static boolean matchesAttributeValue​(javax.lang.model.element.AnnotationValue annotationValue, java.lang.Object attributeValue)
      Checks if the value of the given AnnotationValue matches the specified attribute value.
    • 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)
        Retrieves all AnnotationMirror instances from the given Element. If the element is null, this method returns an empty list.

        This method is designed to provide a consistent way of retrieving annotations across different constructs in the annotation processing framework.

        Parameters:
        element - the annotated element 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.type.TypeMirror type,
                                                                                           java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
        Retrieves all AnnotationMirror instances of the specified annotation class from the given TypeMirror. If either the type or the annotation class is null, this method returns an empty list.
        Parameters:
        type - the type mirror 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
      • 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)
        Retrieves all AnnotationMirror instances of the specified annotation class from the given Element. If either the element or the annotation class is null, this method returns an empty list.
        Parameters:
        element - the annotated element 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
      • getAllAnnotations

        static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations​(javax.lang.model.type.TypeMirror type,
                                                                                           java.lang.CharSequence annotationClassName)
        Retrieves all AnnotationMirror instances of the specified annotation class name from the given TypeMirror. If either the type or the annotation class name is null, this method returns an empty list.
        Parameters:
        type - the type mirror 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.element.Element element,
                                                                                           java.lang.CharSequence annotationClassName)
        Retrieves all AnnotationMirror instances of the specified annotation class name from the given Element. If either the element or the annotation class name is null, this method returns an empty list.
        Parameters:
        element - the annotated element 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.annotation.processing.ProcessingEnvironment processingEnv,
                                                                                           java.lang.reflect.Type annotatedType)
        Retrieves all AnnotationMirror instances of the specified annotated type from the given ProcessingEnvironment. If either the processing environment or the annotated type is null, this method returns an empty list.
        Parameters:
        processingEnv - the processing environment used to retrieve annotations, may be null
        annotatedType - the annotated type to search for annotations, may be null
        Returns:
        a non-null immutable list of AnnotationMirror instances; never null
      • findAnnotation

        static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.type.TypeMirror type,
                                                                        java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
        Retrieves the first AnnotationMirror of the specified annotation class from the given TypeMirror. If either the type or the annotation class is null, this method returns null.
        Parameters:
        type - the type mirror 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
      • findAnnotation

        static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.type.TypeMirror type,
                                                                        java.lang.CharSequence annotationClassName)
        Retrieves the first AnnotationMirror of the specified annotation class name from the given TypeMirror. If either the type or the annotation class name is null, this method returns null.
        Parameters:
        type - the type mirror 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
      • findAnnotation

        static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.element.Element element,
                                                                        java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
        Retrieves the first AnnotationMirror of the specified annotation class from the given Element. If either the element or the annotation class is null, this method returns null.
        Parameters:
        element - the annotated element 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
      • findAnnotation

        static javax.lang.model.element.AnnotationMirror findAnnotation​(javax.lang.model.element.Element element,
                                                                        java.lang.CharSequence annotationClassName)
        Retrieves the first AnnotationMirror of the specified annotation class name from the given Element. If either the element or the annotation class name is null, this method returns null.
        Parameters:
        element - the annotated element 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
      • findMetaAnnotation

        static javax.lang.model.element.AnnotationMirror findMetaAnnotation​(javax.lang.model.element.Element annotatedConstruct,
                                                                            java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationClass)
        Retrieves the first meta-annotation of the specified annotation class from the given annotated element. A meta-annotation is an annotation that is present on another annotation. If either the annotated element or the meta-annotation class is null, this method returns null.
        Parameters:
        annotatedConstruct - the annotated element to search for meta-annotations, may be null
        metaAnnotationClass - the annotation class to look for as a meta-annotation, may be null
        Returns:
        the first matching meta-AnnotationMirror, or null if none found
      • findMetaAnnotation

        static javax.lang.model.element.AnnotationMirror findMetaAnnotation​(javax.lang.model.element.Element annotatedConstruct,
                                                                            java.lang.CharSequence metaAnnotationClassName)
        Retrieves the first meta-annotation of the specified meta-annotation class name from the given annotated element. A meta-annotation is an annotation that is present on another annotation. If either the annotated element or the meta-annotation class name is null, this method returns null.
        Parameters:
        annotatedConstruct - the annotated element to search for meta-annotations, may be null
        metaAnnotationClassName - the fully qualified class name of the meta-annotation to look for, may be null
        Returns:
        the first matching meta-AnnotationMirror, or null if none found
      • isAnnotationPresent

        static boolean isAnnotationPresent​(javax.lang.model.element.Element element,
                                           java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
        Checks if the specified annotation is present on the given element, either directly or as a meta-annotation.
        Parameters:
        element - the element to check for the presence of the annotation; may be null
        annotationClass - the annotation class to look for; may be null
        Returns:
        true if the annotation is present (either directly or as a meta-annotation), false otherwise or if either parameter is null
      • isAnnotationPresent

        static boolean isAnnotationPresent​(javax.lang.model.element.Element element,
                                           java.lang.CharSequence annotationClassName)
        Checks if the specified annotation (by class name) is present on the given element, either directly or as a meta-annotation.
        Parameters:
        element - the element to check for the presence of the annotation; may be null
        annotationClassName - the fully qualified class name of the annotation to look for; may be null
        Returns:
        true if the annotation is present (either directly or as a meta-annotation), false otherwise or if either parameter is null
      • 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)
        Retrieves all AnnotationMirror instances from the given AnnotatedConstruct that match the provided annotation filters.

        If the annotated construct is null, this method returns an empty list. If no annotation filters are provided, all annotations present on the construct are returned. Otherwise, only annotations that satisfy all the provided predicates are included in the result.

        Parameters:
        annotatedConstruct - the annotated construct to search for annotations, may be null
        annotationFilters - a varargs array of predicates used to filter annotations; may be empty or null
        Returns:
        a non-null immutable list of matching AnnotationMirror instances; never null
      • 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)
        Retrieves all AnnotationMirror instances from the given TypeMirror, applying the specified annotation filters to narrow down the results. If the type mirror is null, this method returns an empty list.

        This method delegates to findAllAnnotations(TypeElement, Predicate[]) after converting the TypeMirror to a TypeElement using #ofTypeElement(TypeMirror).

        Parameters:
        type - the type mirror to search for annotations, may be null
        annotationFilters - a varargs array of predicates used to filter annotations; may be empty or null
        Returns:
        a non-null immutable list of matching AnnotationMirror instances; never null
      • 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)
        Retrieves all AnnotationMirror instances from the given Element, applying the specified annotation filters to narrow down the results. If the element is null, this method returns an empty list.

        This method attempts to resolve the element into a TypeElement. If successful, it delegates to findAllAnnotations(TypeElement, Predicate[]) to retrieve annotations from the type hierarchy. Otherwise, it falls back to using findAnnotations(AnnotatedConstruct, Predicate[]) directly on the element.

        Parameters:
        element - the annotated element to search for annotations, may be null
        annotationFilters - a varargs array of predicates used to filter annotations; may be empty or null
        Returns:
        a non-null immutable list of matching AnnotationMirror instances; never null
      • 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)
        Retrieves all AnnotationMirror instances of the specified annotated type from the given ProcessingEnvironment. If either the processing environment or the annotated type is null, this method returns an empty list.

        This method uses the fully qualified type name of the provided Type to locate the corresponding annotations. It delegates to the overloaded method that accepts a CharSequence for the type name.

        Parameters:
        processingEnv - the processing environment used to retrieve annotations, may be null
        annotatedType - the annotated type to search for annotations, may be null
        annotationFilters - a varargs array of predicates used to filter annotations; may be empty or null
        Returns:
        a non-null immutable list of AnnotationMirror instances; never null
      • 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)
        Retrieves all AnnotationMirror instances of the specified annotated type name from the given ProcessingEnvironment. If either the processing environment or the annotated type name is null, this method returns an empty list.

        This method resolves the annotated type by delegating to #getTypeElement(ProcessingEnvironment, CharSequence), and then uses the resolved type to find annotations with the provided filters.

        Parameters:
        processingEnv - the processing environment used to retrieve annotations, may be null
        annotatedTypeName - the fully qualified class name of the annotation to look for, may be null
        annotationFilters - a varargs array of predicates used to filter annotations; may be empty or null
        Returns:
        a non-null immutable list of matching AnnotationMirror instances; never null
      • matchesAnnotationType

        static boolean matchesAnnotationType​(javax.lang.model.element.AnnotationMirror annotationMirror,
                                             java.lang.reflect.Type annotationType)
        Checks if the given annotation mirror has the same type as the specified Type.

        This method compares the fully qualified name of the annotation mirror's type with the provided type's name. Returns false if either parameter is null.

        Parameters:
        annotationMirror - the annotation mirror to compare; may be null
        annotationType - the target type to match against; may be null
        Returns:
        true if both parameters are non-null and their types match by name; false otherwise
      • matchesAnnotationTypeName

        static boolean matchesAnnotationTypeName​(javax.lang.model.element.AnnotationMirror annotationMirror,
                                                 java.lang.CharSequence annotationTypeName)
        Checks if the given annotation mirror has the same type as the specified annotation class name.

        This method compares the fully qualified name of the annotation mirror's type with the provided annotation class name. Returns false if either parameter is null.

        Parameters:
        annotationMirror - the annotation mirror to compare; may be null
        annotationTypeName - the target annotation class name to match against; may be null
        Returns:
        true if both parameters are non-null and their types match by name; false otherwise
      • getAttributeName

        static java.lang.String getAttributeName​(javax.lang.model.element.ExecutableElement attributeMethod)
        Retrieves the name of the attribute method from the given ExecutableElement.

        This method is typically used to extract the attribute name from an annotation method declaration. The returned name corresponds to the method's simple name as defined in the annotation interface.

        Parameters:
        attributeMethod - the executable element representing the annotation attribute method, may be null
        Returns:
        the name of the attribute method, or null if the provided element is null
      • matchesAttributeMethod

        static boolean matchesAttributeMethod​(javax.lang.model.element.ExecutableElement attributeMethod,
                                              java.lang.String attributeName)
        Checks if the provided executable element represents an annotation attribute method with the specified name.
        Parameters:
        attributeMethod - the executable element to check, may be null
        attributeName - the expected name of the attribute method, may be null
        Returns:
        true if the method is not null and its name matches the given attribute name; false otherwise
      • matchesAttributeValue

        static boolean matchesAttributeValue​(javax.lang.model.element.AnnotationValue annotationValue,
                                             java.lang.Object attributeValue)
        Checks if the value of the given AnnotationValue matches the specified attribute value.

        This method compares the actual value extracted from the annotation value with the provided attribute value. Returns false if either parameter is null or if the values do not match.

        Parameters:
        annotationValue - the annotation value to compare; may be null
        attributeValue - the target value to match against; may be null
        Returns:
        true if both parameters are non-null and their values match; false otherwise
      • 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)
        Get the attributes map from the specified annotation
        Parameters:
        annotatedConstruct - the annotated construct
        annotationClass - the class of annotation
        Returns:
        non-null read-only Map
      • 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)
        Retrieves the map of annotation attribute methods to their corresponding values from the specified AnnotatedConstruct and annotation class. This method finds the first matching annotation on the construct and returns all its declared attribute values, including default values if enabled.

        If the annotated construct is null or the annotation class is not present, an empty map is returned.

        Parameters:
        annotatedConstruct - the annotated construct (e.g., a class, method, or field) that may contain the annotation, may be null
        annotationClass - the annotation class used to locate the annotation on the construct, must not be null
        Returns:
        a non-null immutable map of executable elements (attribute methods) to their annotation values; never null, returns an empty map if no annotation is found or if the construct is null
      • 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)
        Retrieves the map of annotation attribute methods to their corresponding values from the specified AnnotatedConstruct and annotation class. This method finds the first matching annotation on the construct and returns all its declared attribute values, including default values if enabled.

        If the annotated construct is null or the annotation class is not present, an empty map is returned.

        Parameters:
        annotatedConstruct - the annotated construct (e.g., a class, method, or field) that may contain the annotation, may be null
        annotationClass - the annotation class used to locate the annotation on the construct, must not be null
        withDefault - flag indicating whether to include default values for attributes that are not explicitly set; if true, default values will be included where applicable
        Returns:
        a non-null immutable map of executable elements (attribute methods) to their annotation values; never null, returns an empty map if no annotation is found or if the construct is null
      • getElementValues

        static java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValues​(javax.lang.model.element.AnnotationMirror annotation)
        Retrieves a map of annotation attribute methods to their corresponding values from the specified AnnotationMirror. This method includes both explicitly set values and default values for attributes.

        If the provided annotation is null, an empty map is returned.

        Parameters:
        annotation - the annotation mirror to extract attribute values from, may be null
        Returns:
        a non-null immutable map of executable elements (attribute methods) to their annotation values; never null, returns an empty map if the annotation is null
      • getElementValues

        static java.util.Map<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> getElementValues​(javax.lang.model.element.AnnotationMirror annotation,
                                                                                                                                         boolean withDefault)
        Retrieves a map of annotation attribute methods to their corresponding values from the specified AnnotationMirror. This method includes both explicitly set values and default values for attributes if the withDefault flag is set to true.

        If the provided annotation is null, an empty map is returned.

        Parameters:
        annotation - the annotation mirror to extract attribute values from, may be null
        withDefault - flag indicating whether to include default values for attributes that are not explicitly set; if true, default values will be included where applicable
        Returns:
        a non-null immutable map of executable elements (attribute methods) to their annotation values; never null, returns an empty map if the annotation is null
      • 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)
        Retrieves the attribute method and its corresponding annotation value from the specified annotation based on the given attribute name. If no explicit value is found and withDefault is true, it attempts to find and return the default value for the attribute.

        If the provided annotation is null or the attribute name is blank, this method returns null.

        Parameters:
        annotation - the annotation mirror to extract the attribute value from, may be null
        attributeName - the name of the attribute method to look for, may be blank
        withDefault - flag indicating whether to include the default value if the attribute is not explicitly set; if true, the method will attempt to find and return the default value
        Returns:
        an entry containing the executable element (attribute method) and its corresponding annotation value; returns null if the annotation is null, the attribute name is blank, or the attribute method cannot be found
      • 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)
        Retrieves the attribute method and its corresponding annotation value from the specified element values map based on the given attribute name.

        This method searches through the provided map of executable elements (attribute methods) to their annotation values to find a matching attribute by name. If no match is found, it returns null.

        Parameters:
        elementValues - the map of executable elements (attribute methods) to their annotation values; may be null or empty
        attributeName - the name of the attribute method to look for; may be null or blank
        Returns:
        an entry containing the executable element (attribute method) and its corresponding annotation value; returns null if the element values map is empty, the attribute name is blank, or no matching attribute is found
      • getAttribute

        static <T> T getAttribute​(javax.lang.model.element.AnnotationMirror annotation,
                                  java.lang.String attributeName)
        Retrieves the value of the specified attribute from the given annotation.

        This method attempts to find the attribute by name in the provided annotation. If the attribute is not explicitly set, it will attempt to retrieve the default value associated with that attribute, depending on the implementation's behavior.

        Type Parameters:
        T - the type of the attribute value to return
        Parameters:
        annotation - the annotation mirror to extract the attribute value from; may be null
        attributeName - the name of the attribute method to look for; may be blank or null
        Returns:
        the value of the specified attribute if found, or the default value if available; returns null if the annotation is null, the attribute name is blank, or the attribute cannot be resolved
      • getAttribute

        static <T> T getAttribute​(javax.lang.model.element.AnnotationMirror annotation,
                                  java.lang.String attributeName,
                                  boolean withDefault)
        Retrieves the value of the specified attribute from the given annotation, optionally including the default value.

        This method attempts to find the attribute by name in the provided annotation. If the attribute is not explicitly set, and the withDefault flag is set to true, it will attempt to retrieve the default value associated with that attribute. If the attribute cannot be resolved or no value is found, this method returns null.

        Type Parameters:
        T - the type of the attribute value to return
        Parameters:
        annotation - the annotation mirror to extract the attribute value from; may be null
        attributeName - the name of the attribute method to look for; may be blank or null
        withDefault - flag indicating whether to include the default value if the attribute is not explicitly set; if true, the method will attempt to find and return the default value
        Returns:
        the value of the specified attribute if found, or the default value if available; returns null if the annotation is null, the attribute name is blank, or the attribute cannot be resolved
      • getAttribute

        static <T> T getAttribute​(java.util.Map.Entry<javax.lang.model.element.ExecutableElement,​javax.lang.model.element.AnnotationValue> elementValue)
        Retrieves the value of the specified attribute from the provided entry containing the attribute method and its corresponding annotation value.

        If the entry is null or either the attribute method or annotation value is unresolved, this method returns null. Otherwise, it delegates to the default AnnotationValueVisitor to extract the attribute value.

        Type Parameters:
        T - the expected type of the attribute value
        Parameters:
        elementValue - an entry containing the attribute method and its corresponding annotation value; may be null
        Returns:
        the resolved value of the attribute if found; returns null if the entry is null, or if either the attribute method or annotation value is unresolved
      • getValue

        static <T> T getValue​(javax.lang.model.element.AnnotationMirror annotation)
        Retrieves the value of the specified annotation by accessing the default attribute method named "value".

        This method delegates to getAttribute(AnnotationMirror, String) to obtain the value of the annotation's value() method. If the annotation is null or the value cannot be resolved, this method returns null.

        Type Parameters:
        T - the expected type of the attribute value
        Parameters:
        annotation - the annotation mirror to extract the value from; may be null
        Returns:
        the resolved value of the annotation's value() method if found; returns null if the annotation is null or the value cannot be resolved
      • 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