Class AnnotationUtils

  • All Implemented Interfaces:
    Utils

    public abstract class AnnotationUtils
    extends java.lang.Object
    implements Utils
    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.lang.annotation.Annotation[] EMPTY_ANNOTATION_ARRAY
      An empty immutable Annotation array
      static java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> NATIVE_ANNOTATION_TYPES
      A list of annotation types that are considered native to the Java language.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean exists​(java.lang.annotation.Annotation[] annotations, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Checks whether any annotation in the provided array matches the specified annotation type.
      static boolean exists​(java.lang.Iterable<java.lang.annotation.Annotation> annotations, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Checks whether any annotation in the provided Iterable matches the specified annotation type.
      static boolean exists​(java.util.Collection<java.lang.annotation.Annotation> annotations, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Checks whether any annotation in the provided collection matches the specified annotation type.
      static java.util.List<java.lang.annotation.Annotation> filterAnnotations​(java.lang.annotation.Annotation[] annotations, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)
      Filters the given array of annotations based on the provided predicates.
      static java.util.List<java.lang.annotation.Annotation> filterAnnotations​(java.util.List<java.lang.annotation.Annotation> annotations, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)
      Filters the given list of annotations based on the provided predicates.
      static java.util.List<java.lang.annotation.Annotation> findAllDeclaredAnnotations​(java.lang.Class<?> type, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)
      Retrieves all declared annotations from the specified Class, including those from its hierarchy, but excluding meta-annotations (annotations on annotations).
      static java.util.List<java.lang.annotation.Annotation> findAllDeclaredAnnotations​(java.lang.reflect.AnnotatedElement annotatedElement, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)
      Retrieves all declared annotations from the specified AnnotatedElement, including those from its hierarchy, but excluding meta-annotations (annotations on annotations).
      static <A extends java.lang.annotation.Annotation>
      A
      findAnnotation​(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType)
      Finds the annotation of the specified type that is directly or indirectly present on the given AnnotatedElement.
      static <A extends java.lang.annotation.Annotation>
      A
      findAnnotation​(java.lang.reflect.AnnotatedElement annotatedElement, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationFilters)
      Finds the first annotation of the specified AnnotatedElement that matches all the given filters.
      static java.util.Map<java.lang.String,​java.lang.Object> findAttributesMap​(java.lang.annotation.Annotation annotation, java.lang.String... attributeNamesToFilter)
      Retrieves a map of attributes from the specified annotation, filtering by attribute names.
      static java.util.Map<java.lang.String,​java.lang.Object> findAttributesMap​(java.lang.annotation.Annotation annotation, java.util.function.Predicate<? super java.lang.reflect.Method>... attributesToFilter)
      Find the attributes map from the specified annotation by the attribute method
      static <T> T findAttributeValue​(java.lang.annotation.Annotation[] annotations, java.lang.String attributeName)
      Finds the value of the specified attribute from the given array of annotations.
      static java.util.List<java.lang.annotation.Annotation> findDeclaredAnnotations​(java.lang.reflect.AnnotatedElement annotatedElement, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)
      Retrieves the annotations that are directly declared on the specified AnnotatedElement.
      static java.util.List<java.lang.annotation.Annotation> getAllDeclaredAnnotations​(java.lang.reflect.AnnotatedElement annotatedElement)
      Retrieves all declared annotations from the specified AnnotatedElement, including those from its hierarchy, but excluding meta-annotations (annotations on annotations).
      static java.util.Map<java.lang.String,​java.lang.Object> getAttributesMap​(java.lang.annotation.Annotation annotation)
      Retrieves a map of attribute names to their corresponding values from the specified annotation.
      static <T> T getAttributeValue​(java.lang.annotation.Annotation annotation, java.lang.String attributeName)
      Retrieves the value of the specified attribute from the given annotation.
      static java.util.List<java.lang.annotation.Annotation> getDeclaredAnnotations​(java.lang.reflect.AnnotatedElement annotatedElement)
      Retrieves the annotations that are directly declared on the specified AnnotatedElement.
      static boolean isAnnotationInterfaceMethod​(java.lang.reflect.Method attributeMethod)
      Checks whether the specified method is declared by the Annotation interface.
      static boolean isAnnotationPresent​(java.lang.annotation.Annotation annotation, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Checks whether the specified annotation is directly present on the given annotation type.
      static boolean isAnnotationPresent​(java.lang.annotation.Annotation annotation, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
      Checks whether all specified annotation types are directly present on the given Annotation.
      static boolean isAnnotationPresent​(java.lang.reflect.AnnotatedElement[] annotatedElements, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Checks whether any of the specified AnnotatedElement instances contains the given annotation type.
      static boolean isAnnotationPresent​(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Checks whether the specified AnnotatedElement has an annotation of the given type directly present on it.
      static boolean isAnnotationPresent​(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
      Checks whether all specified annotation types are directly present on the given AnnotatedElement.
      static boolean isCallerSensitivePresent()
      Checks whether the jdk.internal.reflect.CallerSensitive annotation is present in the current runtime environment.
      static boolean isMetaAnnotation​(java.lang.annotation.Annotation annotation, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationType)
      Checks whether the specified annotation is a meta-annotation targeting a specific type.
      static boolean isMetaAnnotation​(java.lang.annotation.Annotation annotation, java.lang.Class<? extends java.lang.annotation.Annotation>... metaAnnotationTypes)
      Checks whether the specified annotation is a meta-annotation, which means it's used to annotate other annotations.
      static boolean isMetaAnnotation​(java.lang.annotation.Annotation annotation, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> metaAnnotationTypes)
      Checks whether the specified annotation is a meta-annotation, which means it's used to annotate other annotations.
      static boolean isMetaAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationType)
      Checks whether the specified annotation type is a meta-annotation.
      static boolean isMetaAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation>... metaAnnotationTypes)
      Checks whether the specified annotation type is a meta-annotation, which means it's used to annotate other annotations.
      static boolean isMetaAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> metaAnnotationTypes)
      Checks whether the specified annotation type is a meta-annotation, which means it's used to annotate other annotations.
      static boolean isSameType​(java.lang.annotation.Annotation annotation, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Checks whether the specified annotation is of the given annotation type.
      static boolean isType​(java.lang.reflect.AnnotatedElement annotatedElement)
      Checks whether the given AnnotatedElement is a Class type.
      • Methods inherited from class java.lang.Object

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

      • NATIVE_ANNOTATION_TYPES

        @Nonnull
        public static final java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> NATIVE_ANNOTATION_TYPES
        A list of annotation types that are considered native to the Java language.

        These annotations are defined by the Java platform and are commonly used for structural or metadata purposes. They include:

        • Target
        • Retention
        • Documented
        • Inherited
        • Native
        • Repeatable
      • 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
      • EMPTY_ANNOTATION_ARRAY

        public static final java.lang.annotation.Annotation[] EMPTY_ANNOTATION_ARRAY
        An empty immutable Annotation array
    • Method Detail

      • isType

        public static boolean isType​(java.lang.reflect.AnnotatedElement annotatedElement)
        Checks whether the given AnnotatedElement is a Class type.

        This method is useful when determining if an element corresponds to a class, which can be important in annotation processing or reflection-based operations.

        Example Usage

        
         Class<?> clazz = String.class;
         boolean result = AnnotationUtils.isType(clazz); // true
         
        Parameters:
        annotatedElement - the annotated element to check
        Returns:
        true if the element is a Class, otherwise false
        See Also:
        ElementType.TYPE
      • isSameType

        public static boolean isSameType​(java.lang.annotation.Annotation annotation,
                                         java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
        Checks whether the specified annotation is of the given annotation type.

        This method compares the type of the provided annotation with the expected annotation type.

        Example Usage

        {@code
        Parameters:
        annotation - the annotation to check
        annotationType - the expected annotation type
        Returns:
        true if the annotation is of the specified type; false otherwise
      • findAnnotation

        @Nullable
        public static <A extends java.lang.annotation.Annotation> A findAnnotation​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                                                   java.lang.Class<A> annotationType)
        Finds the annotation of the specified type that is directly or indirectly present on the given AnnotatedElement.

        This method searches for an annotation of the specified type, considering both direct annotations and meta-annotations (annotations on annotations).

        Example Usage

        {@code
        Type Parameters:
        A - the type of the annotation to find
        Parameters:
        annotatedElement - the element to search for annotations on
        annotationType - the type of annotation to look for
        Returns:
        the first matching annotation of the specified type, or null if none is found
      • findAnnotation

        @Nullable
        public static <A extends java.lang.annotation.Annotation> A findAnnotation​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                                                   java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationFilters)
        Finds the first annotation of the specified AnnotatedElement that matches all the given filters.

        This method is useful when searching for specific annotations based on custom filtering logic. The search includes directly declared annotations but does not include meta-annotations.

        Example Usage

        {@code
         // Example 1: Find an annotation by type using a predicate
        Type Parameters:
        A - the type of the annotation to find
        Parameters:
        annotatedElement - the element to search for annotations on
        annotationFilters - one or more predicates used to filter the annotations; if no filters are provided, the first available annotation will be returned
        Returns:
        the first matching annotation based on the provided filters, or null if none match
      • isMetaAnnotation

        public static boolean isMetaAnnotation​(java.lang.annotation.Annotation annotation,
                                               java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationType)
        Checks whether the specified annotation is a meta-annotation targeting a specific type.

        A meta-annotation is an annotation that applies to another annotation type rather than directly to Java elements like classes or methods. This method checks if the provided annotation is used as a meta-annotation on its annotation type.

        Example Usage

        {@code
        Parameters:
        annotation - the annotation to check
        metaAnnotationType - the expected meta-annotation type
        Returns:
        true if the annotation's type is annotated with the specified meta-annotation; otherwise, false
      • isMetaAnnotation

        public static boolean isMetaAnnotation​(java.lang.annotation.Annotation annotation,
                                               java.lang.Class<? extends java.lang.annotation.Annotation>... metaAnnotationTypes)
        Checks whether the specified annotation is a meta-annotation, which means it's used to annotate other annotations.

        A meta-annotation is an annotation that applies to another annotation type rather than directly to Java elements like classes or methods.

        Example Usage

        {@code
        Parameters:
        annotation - the annotation to check
        metaAnnotationTypes - optional types of annotations to consider as meta-annotations; if none are provided, all annotations will be considered
        Returns:
        true if the specified annotation is a meta-annotation; otherwise, false
      • isMetaAnnotation

        public static boolean isMetaAnnotation​(java.lang.annotation.Annotation annotation,
                                               java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> metaAnnotationTypes)
        Checks whether the specified annotation is a meta-annotation, which means it's used to annotate other annotations.

        A meta-annotation is an annotation that applies to another annotation type rather than directly to Java elements like classes or methods.

        Example Usage

        {@code
         // Example 1: Checking if @Target is a meta-annotation
         boolean result = AnnotationUtils.isMetaAnnotation(Target.class);
         System.out.println(result); // false, because Target is not annotated with any meta-annotation
        
         // Example 2: Custom annotation scenario
         // Assume we have the following annotations:
        Parameters:
        annotation - the annotation to check
        metaAnnotationTypes - optional types of annotations to consider as meta-annotations; if none are provided, all annotations will be considered
        Returns:
        true if the specified annotation is a meta-annotation; otherwise, false
      • isMetaAnnotation

        public static boolean isMetaAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
                                               java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationType)
        Checks whether the specified annotation type is a meta-annotation.

        A meta-annotation is an annotation that applies to another annotation type, typically used to define composed annotations or custom structured annotations.

        Example Usage

        {@code
        Parameters:
        annotationType - the annotation type to check
        metaAnnotationType - the specific meta-annotation type to look for
        Returns:
        true if the specified annotation is a meta-annotation; otherwise, false
      • isMetaAnnotation

        public static boolean isMetaAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
                                               java.lang.Class<? extends java.lang.annotation.Annotation>... metaAnnotationTypes)
        Checks whether the specified annotation type is a meta-annotation, which means it's used to annotate other annotations.

        A meta-annotation is an annotation that applies to another annotation type rather than directly to Java elements like classes or methods.

        Example Usage

        {@code
        Parameters:
        annotationType - the annotation type to check
        metaAnnotationTypes - optional types of annotations to consider as meta-annotations; if none are provided, all annotations will be considered
        Returns:
        true if the specified annotation is a meta-annotation; otherwise, false
      • 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)
        Checks whether the specified annotation type is a meta-annotation, which means it's used to annotate other annotations.

        A meta-annotation is an annotation that applies to another annotation type rather than directly to Java elements like classes or methods.

        Example Usage

        {@code
        Parameters:
        annotationType - the annotation type to check
        metaAnnotationTypes - optional types of annotations to consider as meta-annotations; if none are provided, all annotations will be considered
        Returns:
        true if the specified annotation is a meta-annotation; otherwise, false
      • getAllDeclaredAnnotations

        @Nonnull
        public static java.util.List<java.lang.annotation.Annotation> getAllDeclaredAnnotations​(java.lang.reflect.AnnotatedElement annotatedElement)
        Retrieves all declared annotations from the specified AnnotatedElement, including those from its hierarchy, but excluding meta-annotations (annotations on annotations).

        This method is particularly useful when you need to inspect all annotations directly applied to a class, method, or field, including those inherited from superclasses.

        Example Usage

        {@code
        Parameters:
        annotatedElement - the element to retrieve annotations from
        Returns:
        a read-only list of all declared annotations, not including meta-annotations
      • getDeclaredAnnotations

        @Nonnull
        public static java.util.List<java.lang.annotation.Annotation> getDeclaredAnnotations​(java.lang.reflect.AnnotatedElement annotatedElement)
        Retrieves the annotations that are directly declared on the specified AnnotatedElement.

        This method returns only the annotations directly present on the element itself, excluding any inherited annotations or meta-annotations.

        Example Usage

        {@code
        Parameters:
        annotatedElement - the element to retrieve annotations from
        Returns:
        a read-only list of annotations directly declared on the element
      • findAllDeclaredAnnotations

        @Nonnull
        public static java.util.List<java.lang.annotation.Annotation> findAllDeclaredAnnotations​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                                                                 java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)
        Retrieves all declared annotations from the specified AnnotatedElement, including those from its hierarchy, but excluding meta-annotations (annotations on annotations).

        This method is particularly useful when you need to inspect all annotations directly applied to a class, method, or field, including those inherited from superclasses.

        Example Usage

        {@code
        Parameters:
        annotatedElement - the element to search for annotations on
        annotationsToFilter - one or more predicates used to filter the annotations; if no filters are provided, all annotations will be returned
        Returns:
        a read-only list of annotations matching the criteria
      • findAllDeclaredAnnotations

        @Nonnull
        public static java.util.List<java.lang.annotation.Annotation> findAllDeclaredAnnotations​(java.lang.Class<?> type,
                                                                                                 java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)
        Retrieves all declared annotations from the specified Class, including those from its hierarchy, but excluding meta-annotations (annotations on annotations).

        This method is particularly useful when you need to inspect all annotations directly applied to a class, including those inherited from superclasses. It ensures that each annotation is only included once, even if it appears in multiple levels of the class hierarchy.

        Example Usage

        {@code
        Parameters:
        type - the class to retrieve annotations from
        annotationsToFilter - one or more predicates used to filter the annotations; if no filters are provided, all annotations will be returned
        Returns:
        a read-only list of annotations matching the criteria
      • findDeclaredAnnotations

        @Nonnull
        public static java.util.List<java.lang.annotation.Annotation> findDeclaredAnnotations​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                                                              java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)
        Retrieves the annotations that are directly declared on the specified AnnotatedElement.

        This method returns only the annotations directly present on the element itself, excluding any inherited annotations or meta-annotations.

        Example Usage

        {@code
        Parameters:
        annotatedElement - the element to retrieve annotations from
        annotationsToFilter - one or more predicates used to filter the annotations; if no filters are provided, all directly declared annotations will be returned
        Returns:
        a read-only list of annotations directly declared on the element
      • filterAnnotations

        @Nonnull
        public static java.util.List<java.lang.annotation.Annotation> filterAnnotations​(java.lang.annotation.Annotation[] annotations,
                                                                                        java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)
        Filters the given array of annotations based on the provided predicates.

        This method converts the input array into a list and applies the filter using the filterAnnotations(List, Predicate[]) method. If the input array is empty or null, it returns an empty list.

        Example Usage

        {@code
        Parameters:
        annotations - the array of annotations to be filtered
        annotationsToFilter - one or more predicates used to filter the annotations; if no filters are provided, all annotations will be returned
        Returns:
        a read-only list of annotations matching the criteria
      • filterAnnotations

        @Nonnull
        public static java.util.List<java.lang.annotation.Annotation> filterAnnotations​(java.util.List<java.lang.annotation.Annotation> annotations,
                                                                                        java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)
        Filters the given list of annotations based on the provided predicates.

        This method applies each predicate in the array to filter the input list of annotations. If no filters are provided, it returns an unmodifiable view of the original list. If any of the filters reject an annotation, it is excluded from the result.

        {@code
        Parameters:
        annotations - the list of annotations to be filtered
        annotationsToFilter - one or more predicates used to filter the annotations; if no filters are provided, all annotations will be returned as an unmodifiable list
        Returns:
        a read-only list of annotations matching the criteria
      • findAttributeValue

        @Nullable
        public static <T> T findAttributeValue​(java.lang.annotation.Annotation[] annotations,
                                               java.lang.String attributeName)
        Finds the value of the specified attribute from the given array of annotations.

        This method iterates through the provided annotations, attempting to retrieve the value of the named attribute from each. It returns the first non-null value found.

        Example Usage

        {@code
        Type Parameters:
        T - the type of the attribute value
        Parameters:
        annotations - the array of annotations to search within
        attributeName - the name of the attribute to find
        Returns:
        the value of the attribute if found; otherwise, null
      • getAttributeValue

        @Nullable
        public static <T> T getAttributeValue​(java.lang.annotation.Annotation annotation,
                                              java.lang.String attributeName)
        Retrieves the value of the specified attribute from the given annotation.

        This method uses reflection to find the method with the matching name in the annotation's type, and then invokes it on the provided annotation instance to get the attribute value.

        Example Usage

        {@code
        Type Parameters:
        T - the expected type of the attribute value
        Parameters:
        annotation - the annotation instance to retrieve the attribute value from
        attributeName - the name of the attribute whose value is to be retrieved
        Returns:
        the value of the attribute if found; otherwise, null
      • getAttributesMap

        @Nonnull
        public static java.util.Map<java.lang.String,​java.lang.Object> getAttributesMap​(java.lang.annotation.Annotation annotation)
        Retrieves a map of attribute names to their corresponding values from the specified annotation.

        This method uses reflection to extract all declared methods in the annotation's type that are not defined in the Object or Annotation interfaces. These methods represent the attributes of the annotation, and their return values are obtained by invoking them on the provided annotation instance.

        Example Usage

        {@code
        Parameters:
        annotation - the annotation instance to retrieve the attribute map from
        Returns:
        a non-null read-only map containing attribute names as keys and their corresponding values
      • findAttributesMap

        @Nonnull
        public static java.util.Map<java.lang.String,​java.lang.Object> findAttributesMap​(java.lang.annotation.Annotation annotation,
                                                                                               java.lang.String... attributeNamesToFilter)
        Retrieves a map of attributes from the specified annotation, filtering by attribute names.

        This method extracts only the attributes whose names match those provided in the attributeNamesToFilter array. If no attribute names are provided, it returns an empty map.

        Example Usage

        {@code
        Parameters:
        annotation - the annotation instance to retrieve the attribute map from
        attributeNamesToFilter - the names of the attributes to include in the result map; if none are provided, all attributes will be included
        Returns:
        a non-null read-only map containing filtered attribute names and their corresponding values
      • findAttributesMap

        @Nonnull
        public static java.util.Map<java.lang.String,​java.lang.Object> findAttributesMap​(java.lang.annotation.Annotation annotation,
                                                                                               java.util.function.Predicate<? super java.lang.reflect.Method>... attributesToFilter)
        Find the attributes map from the specified annotation by the attribute method
        Parameters:
        annotation - the specified annotation
        attributesToFilter - the attribute methods to filter
        Returns:
        non-null read-only Map
      • exists

        public static boolean exists​(java.lang.annotation.Annotation[] annotations,
                                     java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
        Checks whether any annotation in the provided array matches the specified annotation type.

        This method is useful when verifying the presence of a specific annotation among an array, especially for processing annotations on classes, methods, or fields.

        Example Usage

        {@code
        Parameters:
        annotations - the array of annotations to check
        annotationType - the type of annotation to look for
        Returns:
        true if at least one annotation matches the specified type; otherwise, false
      • exists

        public static boolean exists​(java.util.Collection<java.lang.annotation.Annotation> annotations,
                                     java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
        Checks whether any annotation in the provided collection matches the specified annotation type.

        This method is useful when verifying the presence of a specific annotation among a collection, especially for processing annotations on classes, methods, or fields.

        Example Usage

        {@code
        Parameters:
        annotations - the collection of annotations to check
        annotationType - the type of annotation to look for
        Returns:
        true if at least one annotation matches the specified type; otherwise, false
      • exists

        public static boolean exists​(java.lang.Iterable<java.lang.annotation.Annotation> annotations,
                                     java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
        Checks whether any annotation in the provided Iterable matches the specified annotation type.

        This method is useful when verifying the presence of a specific annotation among an iterable collection, especially for processing annotations on classes, methods, or fields.

        Example Usage

        {@code
        Parameters:
        annotations - the iterable collection of annotations to check
        annotationType - the type of annotation to look for
        Returns:
        true if at least one annotation matches the specified type; otherwise, false
      • isAnnotationPresent

        public static boolean isAnnotationPresent​(java.lang.reflect.AnnotatedElement[] annotatedElements,
                                                  java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
        Checks whether any of the specified AnnotatedElement instances contains the given annotation type.

        This method is particularly useful when dealing with multiple elements (e.g., classes, methods) and you want to determine if at least one of them has a specific annotation.

        Example Usage

        {@code
        Parameters:
        annotatedElements - an array of elements to check for annotations
        annotationType - the type of annotation to look for
        Returns:
        true if at least one element contains the specified annotation; otherwise, false
      • isAnnotationPresent

        public static boolean isAnnotationPresent​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                  java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
        Checks whether the specified AnnotatedElement has an annotation of the given type directly present on it.

        This method only checks for annotations that are explicitly declared on the element and does not search meta-annotations or inherited annotations. It is useful when you need to verify if a specific annotation exists directly on a class, method, or field.

        Example Usage

        {@code
        Parameters:
        annotatedElement - the element to check for the presence of an annotation
        annotationType - the type of annotation to look for
        Returns:
        true if the annotation is directly present on the element; otherwise, false
      • isAnnotationPresent

        public static boolean isAnnotationPresent​(java.lang.annotation.Annotation annotation,
                                                  java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
        Checks whether the specified annotation is directly present on the given annotation type.

        This method is useful when determining if one annotation is used as a meta-annotation on another annotation. It only checks for direct presence and does not search through inherited or nested annotations.

        Example Usage

        {@code
        Parameters:
        annotation - the annotation to check
        annotationType - the type of annotation to look for
        Returns:
        true if the annotation is directly present on the annotation type; otherwise, false
      • isAnnotationPresent

        public static boolean isAnnotationPresent​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                  java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
        Checks whether all specified annotation types are directly present on the given AnnotatedElement.

        This method iterates through the provided collection of annotation types and verifies that each one is directly present on the element. It does not consider meta-annotations or inherited annotations.

        Example Usage

        {@code
        Parameters:
        annotatedElement - the element to check for the presence of annotations
        annotationTypes - the iterable collection of annotation types to verify
        Returns:
        true if all specified annotation types are directly present on the element; otherwise, false
      • isAnnotationPresent

        public static boolean isAnnotationPresent​(java.lang.annotation.Annotation annotation,
                                                  java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
        Checks whether all specified annotation types are directly present on the given Annotation.

        This method iterates through the provided collection of annotation types and verifies that each one is directly present on the annotation's type. It does not consider meta-annotations or inherited annotations.

        Example Usage

        {@code
        Parameters:
        annotation - the annotation to check for the presence of other annotations
        annotationTypes - the iterable collection of annotation types to verify
        Returns:
        true if all specified annotation types are directly present on the annotation; otherwise, false
      • isAnnotationInterfaceMethod

        public static boolean isAnnotationInterfaceMethod​(java.lang.reflect.Method attributeMethod)
        Checks whether the specified method is declared by the Annotation interface.

        This method is useful when determining if a given method represents an attribute of an annotation, as methods defined in the Annotation interface are common to all annotation types.

        Example Usage

        
         Method[] methods = Override.class.getMethods();
         for (Method method : methods) {
             if (AnnotationUtils.isAnnotationInterfaceMethod(method)) {
                 System.out.println(method.getName() + " is part of the Annotation interface.");
             } else {
                 System.out.println(method.getName() + " is defined by the annotation type itself.");
             }
         }
         
        Parameters:
        attributeMethod - the method to check
        Returns:
        true if the method is declared by the Annotation interface; otherwise, false
      • isCallerSensitivePresent

        public static boolean isCallerSensitivePresent()
        Checks whether the jdk.internal.reflect.CallerSensitive annotation is present in the current runtime environment.

        This method returns true if the annotation class can be resolved, indicating that the JVM supports it; otherwise, it returns false, which may suggest that the annotation is not available or not accessible.

        Example Usage

        
         boolean isPresent = AnnotationUtils.isCallerSensitivePresent();
         if (isPresent) {
             System.out.println("CallerSensitive annotation is available.");
         } else {
             System.out.println("CallerSensitive annotation is not available.");
         }
         
        Returns:
        true if the jdk.internal.reflect.CallerSensitive annotation is present; false otherwise