org.springframework.core.annotation

Class AnnotatedElementUtils

  • java.lang.Object
    • org.springframework.core.annotation.AnnotatedElementUtils


  • public abstract class AnnotatedElementUtils
    extends java.lang.Object
    General utility methods for finding annotations, meta-annotations, and repeatable annotations on AnnotatedElements.

    AnnotatedElementUtils defines the public API for Spring's meta-annotation programming model with support for annotation attribute overrides. If you do not need support for annotation attribute overrides, consider using AnnotationUtils instead.

    Note that the features of this class are not provided by the JDK's introspection facilities themselves.

    Annotation Attribute Overrides

    Support for meta-annotations with attribute overrides in composed annotations is provided by all variants of the getMergedAnnotationAttributes(), getMergedAnnotation(), getAllMergedAnnotations(), getMergedRepeatableAnnotations(), findMergedAnnotationAttributes(), findMergedAnnotation(), findAllMergedAnnotations(), and findMergedRepeatableAnnotations() methods.

    Find vs. Get Semantics

    The search algorithms used by methods in this class follow either find or get semantics. Consult the javadocs for each individual method for details on which search algorithm is used.

    Get semantics are limited to searching for annotations that are either present on an AnnotatedElement (i.e. declared locally or inherited) or declared within the annotation hierarchy above the AnnotatedElement.

    Find semantics are much more exhaustive, providing get semantics plus support for the following:

    • Searching on interfaces, if the annotated element is a class
    • Searching on superclasses, if the annotated element is a class
    • Resolving bridged methods, if the annotated element is a method
    • Searching on methods in interfaces, if the annotated element is a method
    • Searching on methods in superclasses, if the annotated element is a method

    Support for @Inherited

    Methods following get semantics will honor the contract of Java's @Inherited annotation except that locally declared annotations (including custom composed annotations) will be favored over inherited annotations. In contrast, methods following find semantics will completely ignore the presence of @Inherited since the find search algorithm manually traverses type and method hierarchies and thereby implicitly supports annotation inheritance without a need for @Inherited.

    Since:
    4.0
    Author:
    Phillip Webb, Juergen Hoeller, Sam Brannen
    See Also:
    AliasFor, AnnotationAttributes, AnnotationUtils, BridgeMethodResolver
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static <A extends java.lang.annotation.Annotation>
      java.util.Set<A>
      findAllMergedAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
      Find all annotations of the specified annotationType within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specified annotationType.
      static java.util.Set<java.lang.annotation.Annotation> findAllMergedAnnotations(java.lang.reflect.AnnotatedElement element, java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
      Find all annotations of the specified annotationTypes within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the corresponding annotationType.
      static <A extends java.lang.annotation.Annotation>
      A
      findMergedAnnotation(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
      Find the first annotation of the specified annotationType within the annotation hierarchy above the supplied element, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy, and synthesize the result back into an annotation of the specified annotationType.
      static AnnotationAttributes findMergedAnnotationAttributes(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
      Find the first annotation of the specified annotationType within the annotation hierarchy above the supplied element and merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.
      static AnnotationAttributes findMergedAnnotationAttributes(java.lang.reflect.AnnotatedElement element, java.lang.String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
      Find the first annotation of the specified annotationName within the annotation hierarchy above the supplied element and merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.
      static <A extends java.lang.annotation.Annotation>
      java.util.Set<A>
      findMergedRepeatableAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
      Find all repeatable annotations of the specified annotationType within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specified annotationType.
      static <A extends java.lang.annotation.Annotation>
      java.util.Set<A>
      findMergedRepeatableAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> containerType)
      Find all repeatable annotations of the specified annotationType within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specified annotationType.
      static java.lang.reflect.AnnotatedElement forAnnotations(java.lang.annotation.Annotation... annotations)
      Build an adapted AnnotatedElement for the given annotations, typically for use with other methods on AnnotatedElementUtils.
      static MultiValueMap<java.lang.String,java.lang.Object> getAllAnnotationAttributes(java.lang.reflect.AnnotatedElement element, java.lang.String annotationName)
      Get the annotation attributes of all annotations of the specified annotationName in the annotation hierarchy above the supplied AnnotatedElement and store the results in a MultiValueMap.
      static MultiValueMap<java.lang.String,java.lang.Object> getAllAnnotationAttributes(java.lang.reflect.AnnotatedElement element, java.lang.String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
      Get the annotation attributes of all annotations of the specified annotationName in the annotation hierarchy above the supplied AnnotatedElement and store the results in a MultiValueMap.
      static <A extends java.lang.annotation.Annotation>
      java.util.Set<A>
      getAllMergedAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
      Get all annotations of the specified annotationType within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specified annotationType.
      static java.util.Set<java.lang.annotation.Annotation> getAllMergedAnnotations(java.lang.reflect.AnnotatedElement element, java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
      Get all annotations of the specified annotationTypes within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the corresponding annotationType.
      static <A extends java.lang.annotation.Annotation>
      A
      getMergedAnnotation(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
      Get the first annotation of the specified annotationType within the annotation hierarchy above the supplied element, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy, and synthesize the result back into an annotation of the specified annotationType.
      static AnnotationAttributes getMergedAnnotationAttributes(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Get the first annotation of the specified annotationType within the annotation hierarchy above the supplied element and merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.
      static AnnotationAttributes getMergedAnnotationAttributes(java.lang.reflect.AnnotatedElement element, java.lang.String annotationName)
      Get the first annotation of the specified annotationName within the annotation hierarchy above the supplied element and merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.
      static AnnotationAttributes getMergedAnnotationAttributes(java.lang.reflect.AnnotatedElement element, java.lang.String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
      Get the first annotation of the specified annotationName within the annotation hierarchy above the supplied element and merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.
      static <A extends java.lang.annotation.Annotation>
      java.util.Set<A>
      getMergedRepeatableAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType)
      Get all repeatable annotations of the specified annotationType within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specified annotationType.
      static <A extends java.lang.annotation.Annotation>
      java.util.Set<A>
      getMergedRepeatableAnnotations(java.lang.reflect.AnnotatedElement element, java.lang.Class<A> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation> containerType)
      Get all repeatable annotations of the specified annotationType within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specified annotationType.
      static java.util.Set<java.lang.String> getMetaAnnotationTypes(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Get the fully qualified class names of all meta-annotation types present on the annotation (of the specified annotationType) on the supplied AnnotatedElement.
      static java.util.Set<java.lang.String> getMetaAnnotationTypes(java.lang.reflect.AnnotatedElement element, java.lang.String annotationName)
      Get the fully qualified class names of all meta-annotation types present on the annotation (of the specified annotationName) on the supplied AnnotatedElement.
      static boolean hasAnnotation(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Determine if an annotation of the specified annotationType is available on the supplied AnnotatedElement or within the annotation hierarchy above the specified element.
      static boolean hasMetaAnnotationTypes(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Determine if the supplied AnnotatedElement is annotated with a composed annotation that is meta-annotated with an annotation of the specified annotationType.
      static boolean hasMetaAnnotationTypes(java.lang.reflect.AnnotatedElement element, java.lang.String annotationName)
      Determine if the supplied AnnotatedElement is annotated with a composed annotation that is meta-annotated with an annotation of the specified annotationName.
      static boolean isAnnotated(java.lang.reflect.AnnotatedElement element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
      Determine if an annotation of the specified annotationType is present on the supplied AnnotatedElement or within the annotation hierarchy above the specified element.
      static boolean isAnnotated(java.lang.reflect.AnnotatedElement element, java.lang.String annotationName)
      Determine if an annotation of the specified annotationName is present on the supplied AnnotatedElement or within the annotation hierarchy above the specified element.
      • Methods inherited from class java.lang.Object

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

      • AnnotatedElementUtils

        public AnnotatedElementUtils()
    • Method Detail

      • forAnnotations

        public static java.lang.reflect.AnnotatedElement forAnnotations(java.lang.annotation.Annotation... annotations)
        Build an adapted AnnotatedElement for the given annotations, typically for use with other methods on AnnotatedElementUtils.
        Parameters:
        annotations - the annotations to expose through the AnnotatedElement
        Since:
        4.3
      • hasMetaAnnotationTypes

        public static boolean hasMetaAnnotationTypes(java.lang.reflect.AnnotatedElement element,
                                                     java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
        Determine if the supplied AnnotatedElement is annotated with a composed annotation that is meta-annotated with an annotation of the specified annotationType.

        This method follows get semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element
        annotationType - the meta-annotation type to find
        Returns:
        true if a matching meta-annotation is present
        Since:
        4.2.3
        See Also:
        getMetaAnnotationTypes(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)
      • hasMetaAnnotationTypes

        public static boolean hasMetaAnnotationTypes(java.lang.reflect.AnnotatedElement element,
                                                     java.lang.String annotationName)
        Determine if the supplied AnnotatedElement is annotated with a composed annotation that is meta-annotated with an annotation of the specified annotationName.

        This method follows get semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element
        annotationName - the fully qualified class name of the meta-annotation type to find
        Returns:
        true if a matching meta-annotation is present
        See Also:
        getMetaAnnotationTypes(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)
      • isAnnotated

        public static boolean isAnnotated(java.lang.reflect.AnnotatedElement element,
                                          java.lang.String annotationName)
        Determine if an annotation of the specified annotationName is present on the supplied AnnotatedElement or within the annotation hierarchy above the specified element.

        If this method returns true, then getMergedAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>) will return a non-null value.

        This method follows get semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element
        annotationName - the fully qualified class name of the annotation type to find
        Returns:
        true if a matching annotation is present
      • getMergedAnnotationAttributes

        @Nullable
        public static AnnotationAttributes getMergedAnnotationAttributes(java.lang.reflect.AnnotatedElement element,
                                                                                   java.lang.String annotationName,
                                                                                   boolean classValuesAsString,
                                                                                   boolean nestedAnnotationsAsMap)
        Get the first annotation of the specified annotationName within the annotation hierarchy above the supplied element and merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.

        Attributes from lower levels in the annotation hierarchy override attributes of the same name from higher levels, and @AliasFor semantics are fully supported, both within a single annotation and within the annotation hierarchy.

        In contrast to getAllAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.String), the search algorithm used by this method will stop searching the annotation hierarchy once the first annotation of the specified annotationName has been found. As a consequence, additional annotations of the specified annotationName will be ignored.

        This method follows get semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element
        annotationName - the fully qualified class name of the annotation type to find
        classValuesAsString - whether to convert Class references into Strings or to preserve them as Class references
        nestedAnnotationsAsMap - whether to convert nested Annotation instances into AnnotationAttributes maps or to preserve them as Annotation instances
        Returns:
        the merged AnnotationAttributes, or null if not found
        Since:
        4.2
        See Also:
        findMergedAnnotation(AnnotatedElement, Class), findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean), getAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
      • getAllMergedAnnotations

        public static <A extends java.lang.annotation.Annotation> java.util.Set<A> getAllMergedAnnotations(java.lang.reflect.AnnotatedElement element,
                                                                                                           java.lang.Class<A> annotationType)
        Get all annotations of the specified annotationType within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specified annotationType.

        @AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies.

        This method follows get semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element (never null)
        annotationType - the annotation type to find (never null)
        Returns:
        the set of all merged, synthesized Annotations found, or an empty set if none were found
        Since:
        4.3
        See Also:
        getMergedAnnotation(AnnotatedElement, Class), getAllAnnotationAttributes(AnnotatedElement, String), findAllMergedAnnotations(AnnotatedElement, Class)
      • getAllMergedAnnotations

        public static java.util.Set<java.lang.annotation.Annotation> getAllMergedAnnotations(java.lang.reflect.AnnotatedElement element,
                                                                                             java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
        Get all annotations of the specified annotationTypes within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the corresponding annotationType.

        @AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies.

        This method follows get semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element (never null)
        annotationTypes - the annotation types to find
        Returns:
        the set of all merged, synthesized Annotations found, or an empty set if none were found
        Since:
        5.1
        See Also:
        getAllMergedAnnotations(AnnotatedElement, Class)
      • getMergedRepeatableAnnotations

        public static <A extends java.lang.annotation.Annotation> java.util.Set<A> getMergedRepeatableAnnotations(java.lang.reflect.AnnotatedElement element,
                                                                                                                  java.lang.Class<A> annotationType)
        Get all repeatable annotations of the specified annotationType within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specified annotationType.

        The container type that holds the repeatable annotations will be looked up via Repeatable.

        @AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies.

        This method follows get semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element (never null)
        annotationType - the annotation type to find (never null)
        Returns:
        the set of all merged repeatable Annotations found, or an empty set if none were found
        Throws:
        java.lang.IllegalArgumentException - if the element or annotationType is null, or if the container type cannot be resolved
        Since:
        4.3
        See Also:
        getMergedAnnotation(AnnotatedElement, Class), getAllMergedAnnotations(AnnotatedElement, Class), getMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
      • getMergedRepeatableAnnotations

        public static <A extends java.lang.annotation.Annotation> java.util.Set<A> getMergedRepeatableAnnotations(java.lang.reflect.AnnotatedElement element,
                                                                                                                  java.lang.Class<A> annotationType,
                                                                                                                  @Nullable
                                                                                                                  java.lang.Class<? extends java.lang.annotation.Annotation> containerType)
        Get all repeatable annotations of the specified annotationType within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specified annotationType.

        @AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies.

        This method follows get semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element (never null)
        annotationType - the annotation type to find (never null)
        containerType - the type of the container that holds the annotations; may be null if the container type should be looked up via Repeatable
        Returns:
        the set of all merged repeatable Annotations found, or an empty set if none were found
        Throws:
        java.lang.IllegalArgumentException - if the element or annotationType is null, or if the container type cannot be resolved
        AnnotationConfigurationException - if the supplied containerType is not a valid container annotation for the supplied annotationType
        Since:
        4.3
        See Also:
        getMergedAnnotation(AnnotatedElement, Class), getAllMergedAnnotations(AnnotatedElement, Class)
      • getAllAnnotationAttributes

        @Nullable
        public static MultiValueMap<java.lang.String,java.lang.Object> getAllAnnotationAttributes(java.lang.reflect.AnnotatedElement element,
                                                                                                            java.lang.String annotationName,
                                                                                                            boolean classValuesAsString,
                                                                                                            boolean nestedAnnotationsAsMap)
        Get the annotation attributes of all annotations of the specified annotationName in the annotation hierarchy above the supplied AnnotatedElement and store the results in a MultiValueMap.

        Note: in contrast to getMergedAnnotationAttributes(AnnotatedElement, String), this method does not support attribute overrides.

        This method follows get semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element
        annotationName - the fully qualified class name of the annotation type to find
        classValuesAsString - whether to convert Class references into Strings or to preserve them as Class references
        nestedAnnotationsAsMap - whether to convert nested Annotation instances into AnnotationAttributes maps or to preserve them as Annotation instances
        Returns:
        a MultiValueMap keyed by attribute name, containing the annotation attributes from all annotations found, or null if not found
      • findMergedAnnotationAttributes

        @Nullable
        public static AnnotationAttributes findMergedAnnotationAttributes(java.lang.reflect.AnnotatedElement element,
                                                                                    java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
                                                                                    boolean classValuesAsString,
                                                                                    boolean nestedAnnotationsAsMap)
        Find the first annotation of the specified annotationType within the annotation hierarchy above the supplied element and merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.

        Attributes from lower levels in the annotation hierarchy override attributes of the same name from higher levels, and @AliasFor semantics are fully supported, both within a single annotation and within the annotation hierarchy.

        In contrast to getAllAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.String), the search algorithm used by this method will stop searching the annotation hierarchy once the first annotation of the specified annotationType has been found. As a consequence, additional annotations of the specified annotationType will be ignored.

        This method follows find semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element
        annotationType - the annotation type to find
        classValuesAsString - whether to convert Class references into Strings or to preserve them as Class references
        nestedAnnotationsAsMap - whether to convert nested Annotation instances into AnnotationAttributes maps or to preserve them as Annotation instances
        Returns:
        the merged AnnotationAttributes, or null if not found
        Since:
        4.2
        See Also:
        findMergedAnnotation(AnnotatedElement, Class), getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
      • findMergedAnnotationAttributes

        @Nullable
        public static AnnotationAttributes findMergedAnnotationAttributes(java.lang.reflect.AnnotatedElement element,
                                                                                    java.lang.String annotationName,
                                                                                    boolean classValuesAsString,
                                                                                    boolean nestedAnnotationsAsMap)
        Find the first annotation of the specified annotationName within the annotation hierarchy above the supplied element and merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.

        Attributes from lower levels in the annotation hierarchy override attributes of the same name from higher levels, and @AliasFor semantics are fully supported, both within a single annotation and within the annotation hierarchy.

        In contrast to getAllAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.String), the search algorithm used by this method will stop searching the annotation hierarchy once the first annotation of the specified annotationName has been found. As a consequence, additional annotations of the specified annotationName will be ignored.

        This method follows find semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element
        annotationName - the fully qualified class name of the annotation type to find
        classValuesAsString - whether to convert Class references into Strings or to preserve them as Class references
        nestedAnnotationsAsMap - whether to convert nested Annotation instances into AnnotationAttributes maps or to preserve them as Annotation instances
        Returns:
        the merged AnnotationAttributes, or null if not found
        Since:
        4.2
        See Also:
        findMergedAnnotation(AnnotatedElement, Class), getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
      • findAllMergedAnnotations

        public static <A extends java.lang.annotation.Annotation> java.util.Set<A> findAllMergedAnnotations(java.lang.reflect.AnnotatedElement element,
                                                                                                            java.lang.Class<A> annotationType)
        Find all annotations of the specified annotationType within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specified annotationType.

        @AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies.

        This method follows find semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element (never null)
        annotationType - the annotation type to find (never null)
        Returns:
        the set of all merged, synthesized Annotations found, or an empty set if none were found
        Since:
        4.3
        See Also:
        findMergedAnnotation(AnnotatedElement, Class), getAllMergedAnnotations(AnnotatedElement, Class)
      • findAllMergedAnnotations

        public static java.util.Set<java.lang.annotation.Annotation> findAllMergedAnnotations(java.lang.reflect.AnnotatedElement element,
                                                                                              java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
        Find all annotations of the specified annotationTypes within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the corresponding annotationType.

        @AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies.

        This method follows find semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element (never null)
        annotationTypes - the annotation types to find
        Returns:
        the set of all merged, synthesized Annotations found, or an empty set if none were found
        Since:
        5.1
        See Also:
        findAllMergedAnnotations(AnnotatedElement, Class)
      • findMergedRepeatableAnnotations

        public static <A extends java.lang.annotation.Annotation> java.util.Set<A> findMergedRepeatableAnnotations(java.lang.reflect.AnnotatedElement element,
                                                                                                                   java.lang.Class<A> annotationType)
        Find all repeatable annotations of the specified annotationType within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specified annotationType.

        The container type that holds the repeatable annotations will be looked up via Repeatable.

        @AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies.

        This method follows find semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element (never null)
        annotationType - the annotation type to find (never null)
        Returns:
        the set of all merged repeatable Annotations found, or an empty set if none were found
        Throws:
        java.lang.IllegalArgumentException - if the element or annotationType is null, or if the container type cannot be resolved
        Since:
        4.3
        See Also:
        findMergedAnnotation(AnnotatedElement, Class), findAllMergedAnnotations(AnnotatedElement, Class), findMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
      • findMergedRepeatableAnnotations

        public static <A extends java.lang.annotation.Annotation> java.util.Set<A> findMergedRepeatableAnnotations(java.lang.reflect.AnnotatedElement element,
                                                                                                                   java.lang.Class<A> annotationType,
                                                                                                                   @Nullable
                                                                                                                   java.lang.Class<? extends java.lang.annotation.Annotation> containerType)
        Find all repeatable annotations of the specified annotationType within the annotation hierarchy above the supplied element; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specified annotationType.

        @AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies.

        This method follows find semantics as described in the class-level javadoc.

        Parameters:
        element - the annotated element (never null)
        annotationType - the annotation type to find (never null)
        containerType - the type of the container that holds the annotations; may be null if the container type should be looked up via Repeatable
        Returns:
        the set of all merged repeatable Annotations found, or an empty set if none were found
        Throws:
        java.lang.IllegalArgumentException - if the element or annotationType is null, or if the container type cannot be resolved
        AnnotationConfigurationException - if the supplied containerType is not a valid container annotation for the supplied annotationType
        Since:
        4.3
        See Also:
        findMergedAnnotation(AnnotatedElement, Class), findAllMergedAnnotations(AnnotatedElement, Class)