Class AnnotatedElementUtils
AnnotatedElements.
AnnotatedElementUtils defines the public API for Spring's
meta-annotation programming model with support for attribute aliases and
annotation attribute overrides configured via @AliasFor.
Note, however, that AnnotatedElementUtils is effectively a facade for
the MergedAnnotations API. For fine-grained support consider using the
MergedAnnotations API directly. If you do not need support for
@AliasFor or merged annotations, 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:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic <A extends Annotation>
 Set<A> findAllMergedAnnotations(AnnotatedElement element, Class<A> annotationType) Find all annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; 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 specifiedannotationType.static Set<Annotation> findAllMergedAnnotations(AnnotatedElement element, Set<Class<? extends Annotation>> annotationTypes) Find all annotations of the specifiedannotationTypeswithin the annotation hierarchy above the suppliedelement; 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 correspondingannotationType.static <A extends Annotation>
 @Nullable AfindMergedAnnotation(AnnotatedElement element, Class<A> annotationType) Find the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement, 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 specifiedannotationType.static @Nullable AnnotationAttributesfindMergedAnnotationAttributes(AnnotatedElement element, Class<? extends Annotation> annotationType, boolean classValuesAsString, boolean nestedAnnotationsAsMap) Find the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.static @Nullable AnnotationAttributesfindMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) Find the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.static <A extends Annotation>
 Set<A> findMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType) Find all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; 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 specifiedannotationType.static <A extends Annotation>
 Set<A> findMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType, @Nullable Class<? extends Annotation> containerType) Find all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; 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 specifiedannotationType.static AnnotatedElementforAnnotations(Annotation... annotations) Build an adaptedAnnotatedElementfor the given annotations, typically for use with other methods inAnnotatedElementUtils.static @Nullable MultiValueMap<String, @Nullable Object> getAllAnnotationAttributes(AnnotatedElement element, String annotationName) Get the annotation attributes of all annotations of the specifiedannotationNamein the annotation hierarchy above the suppliedAnnotatedElementand store the results in aMultiValueMap.static @Nullable MultiValueMap<String, @Nullable Object> getAllAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) Get the annotation attributes of all annotations of the specifiedannotationNamein the annotation hierarchy above the suppliedAnnotatedElementand store the results in aMultiValueMap.static <A extends Annotation>
 Set<A> getAllMergedAnnotations(AnnotatedElement element, Class<A> annotationType) Get all annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; 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 specifiedannotationType.static Set<Annotation> getAllMergedAnnotations(AnnotatedElement element, Set<Class<? extends Annotation>> annotationTypes) Get all annotations of the specifiedannotationTypeswithin the annotation hierarchy above the suppliedelement; 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 correspondingannotationType.static <A extends Annotation>
 @Nullable AgetMergedAnnotation(AnnotatedElement element, Class<A> annotationType) Get the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement, 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 specifiedannotationType.static @Nullable AnnotationAttributesgetMergedAnnotationAttributes(AnnotatedElement element, Class<? extends Annotation> annotationType) Get the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.static @Nullable AnnotationAttributesgetMergedAnnotationAttributes(AnnotatedElement element, String annotationName) Get the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.static @Nullable AnnotationAttributesgetMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) Get the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.static <A extends Annotation>
 Set<A> getMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType) Get all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; 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 specifiedannotationType.static <A extends Annotation>
 Set<A> getMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType, @Nullable Class<? extends Annotation> containerType) Get all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; 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 specifiedannotationType.getMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType) Get the fully qualified class names of all meta-annotation types present on the annotation (of the specifiedannotationType) on the suppliedAnnotatedElement.getMetaAnnotationTypes(AnnotatedElement element, String annotationName) Get the fully qualified class names of all meta-annotation types present on the annotation (of the specifiedannotationName) on the suppliedAnnotatedElement.static booleanhasAnnotation(AnnotatedElement element, Class<? extends Annotation> annotationType) Determine if an annotation of the specifiedannotationTypeis available on the suppliedAnnotatedElementor within the annotation hierarchy above the specified element.static booleanhasMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType) Determine if the suppliedAnnotatedElementis annotated with a composed annotation that is meta-annotated with an annotation of the specifiedannotationType.static booleanhasMetaAnnotationTypes(AnnotatedElement element, String annotationName) Determine if the suppliedAnnotatedElementis annotated with a composed annotation that is meta-annotated with an annotation of the specifiedannotationName.static booleanisAnnotated(AnnotatedElement element, Class<? extends Annotation> annotationType) Determine if an annotation of the specifiedannotationTypeis present on the suppliedAnnotatedElementor within the annotation hierarchy above the specified element.static booleanisAnnotated(AnnotatedElement element, String annotationName) Determine if an annotation of the specifiedannotationNameis present on the suppliedAnnotatedElementor within the annotation hierarchy above the specified element.
- 
Constructor Details- 
AnnotatedElementUtilspublic AnnotatedElementUtils()
 
- 
- 
Method Details- 
forAnnotationsBuild an adaptedAnnotatedElementfor the given annotations, typically for use with other methods inAnnotatedElementUtils.- Parameters:
- annotations- the annotations to expose through the- AnnotatedElement
- Since:
- 4.3
 
- 
getMetaAnnotationTypespublic static Set<String> getMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType) Get the fully qualified class names of all meta-annotation types present on the annotation (of the specifiedannotationType) on the suppliedAnnotatedElement.This method follows get semantics as described in the class-level javadoc. - Parameters:
- element- the annotated element
- annotationType- the annotation type on which to find meta-annotations
- Returns:
- the names of all meta-annotations present on the annotation, or an empty set if not found
- Since:
- 4.2
- See Also:
 
- 
getMetaAnnotationTypesGet the fully qualified class names of all meta-annotation types present on the annotation (of the specifiedannotationName) on the suppliedAnnotatedElement.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 on which to find meta-annotations
- Returns:
- the names of all meta-annotations present on the annotation, or an empty set if none found
- See Also:
 
- 
hasMetaAnnotationTypespublic static boolean hasMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType) Determine if the suppliedAnnotatedElementis annotated with a composed annotation that is meta-annotated with an annotation of the specifiedannotationType.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:
- trueif a matching meta-annotation is present
- Since:
- 4.2.3
- See Also:
 
- 
hasMetaAnnotationTypesDetermine if the suppliedAnnotatedElementis annotated with a composed annotation that is meta-annotated with an annotation of the specifiedannotationName.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:
- trueif a matching meta-annotation is present
- See Also:
 
- 
isAnnotatedpublic static boolean isAnnotated(AnnotatedElement element, Class<? extends Annotation> annotationType) Determine if an annotation of the specifiedannotationTypeis present on the suppliedAnnotatedElementor within the annotation hierarchy above the specified element.If this method returns true, thengetMergedAnnotationAttributes(AnnotatedElement, Class)will return a non-null value.This method follows get semantics as described in the class-level javadoc. - Parameters:
- element- the annotated element
- annotationType- the annotation type to find
- Returns:
- trueif a matching annotation is present
- Since:
- 4.2.3
- See Also:
 
- 
isAnnotatedDetermine if an annotation of the specifiedannotationNameis present on the suppliedAnnotatedElementor within the annotation hierarchy above the specified element.If this method returns true, thengetMergedAnnotationAttributes(AnnotatedElement, Class)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:
- trueif a matching annotation is present
 
- 
getMergedAnnotationAttributespublic static @Nullable AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, Class<? extends Annotation> annotationType) Get the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.This method delegates to getMergedAnnotationAttributes(AnnotatedElement, String).- Parameters:
- element- the annotated element
- annotationType- the annotation type to find
- Returns:
- the merged AnnotationAttributes, ornullif not found
- Since:
- 4.2
- See Also:
 
- 
getMergedAnnotationAttributespublic static @Nullable AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, String annotationName) Get the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.This method delegates to getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean), supplyingfalseforclassValuesAsStringandnestedAnnotationsAsMap.- Parameters:
- element- the annotated element
- annotationName- the fully qualified class name of the annotation type to find
- Returns:
- the merged AnnotationAttributes, ornullif not found
- Since:
- 4.2
- See Also:
 
- 
getMergedAnnotationAttributespublic static @Nullable AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) Get the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.In contrast to getAllAnnotationAttributes(AnnotatedElement, String), the search algorithm used by this method will stop searching the annotation hierarchy once the first annotation of the specifiedannotationNamehas been found. As a consequence, additional annotations of the specifiedannotationNamewill 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- AnnotationAttributesmaps or to preserve them as Annotation instances
- Returns:
- the merged AnnotationAttributes, ornullif not found
- Since:
- 4.2
- See Also:
 
- 
getMergedAnnotationpublic static <A extends Annotation> @Nullable A getMergedAnnotation(AnnotatedElement element, Class<A> annotationType) Get the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement, 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 specifiedannotationType.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.- Parameters:
- element- the annotated element
- annotationType- the annotation type to find
- Returns:
- the merged, synthesized Annotation, ornullif not found
- Since:
- 4.2
- See Also:
 
- 
getAllMergedAnnotationspublic static <A extends Annotation> Set<A> getAllMergedAnnotations(AnnotatedElement element, Class<A> annotationType) Get all annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; 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 specifiedannotationType.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.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 Annotationsfound, or an empty set if none were found
- Since:
- 4.3
- See Also:
 
- 
getAllMergedAnnotationspublic static Set<Annotation> getAllMergedAnnotations(AnnotatedElement element, Set<Class<? extends Annotation>> annotationTypes) Get all annotations of the specifiedannotationTypeswithin the annotation hierarchy above the suppliedelement; 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 correspondingannotationType.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.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 Annotationsfound, or an empty set if none were found
- Since:
- 5.1
- See Also:
 
- 
getMergedRepeatableAnnotationspublic static <A extends Annotation> Set<A> getMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType) Get all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; 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 specifiedannotationType.The container type that holds the repeatable annotations will be looked up via @Repeatable.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.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 Annotationsfound, or an empty set if none were found
- Throws:
- IllegalArgumentException- if the- elementor- annotationTypeis- null, or if the container type cannot be resolved
- Since:
- 4.3
- See Also:
 
- 
getMergedRepeatableAnnotationspublic static <A extends Annotation> Set<A> getMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType, @Nullable Class<? extends Annotation> containerType) Get all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; 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 specifiedannotationType.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.This method follows get semantics as described in the class-level javadoc. WARNING: if the supplied containerTypeis notnull, the search will be restricted to supporting only repeatable annotations whose container is the suppliedcontainerType. This prevents the search from finding repeatable annotations declared as meta-annotations on other types of repeatable annotations. If you need to support such a use case, favorgetMergedRepeatableAnnotations(AnnotatedElement, Class)over this method or alternatively use theMergedAnnotationsAPI directly in conjunction withRepeatableContainersthat are composed to support multiple repeatable annotation types — for example:RepeatableContainers.standardRepeatables() .plus(MyRepeatable1.class, MyContainer1.class) .plus(MyRepeatable2.class, MyContainer2.class);- Parameters:
- element- the annotated element (never- null)
- annotationType- the repeatable annotation type to find (never- null)
- containerType- the type of the container that holds the repeatable annotations; may be- nullif the container type should be looked up via- @Repeatable
- Returns:
- the set of all merged repeatable Annotationsfound, or an empty set if none were found
- Throws:
- IllegalArgumentException- if the- elementor- annotationTypeis- null, or if the container type cannot be resolved
- AnnotationConfigurationException- if the supplied- containerTypeis not a valid container annotation for the supplied- annotationType
- Since:
- 4.3
- See Also:
 
- 
getAllAnnotationAttributespublic static @Nullable MultiValueMap<String, @Nullable Object> getAllAnnotationAttributes(AnnotatedElement element, String annotationName) Get the annotation attributes of all annotations of the specifiedannotationNamein the annotation hierarchy above the suppliedAnnotatedElementand store the results in aMultiValueMap.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
- Returns:
- a MultiValueMapkeyed by attribute name, containing the annotation attributes from all annotations found, ornullif not found
- See Also:
 
- 
getAllAnnotationAttributespublic static @Nullable MultiValueMap<String, @Nullable Object> getAllAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) Get the annotation attributes of all annotations of the specifiedannotationNamein the annotation hierarchy above the suppliedAnnotatedElementand store the results in aMultiValueMap.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- AnnotationAttributesmaps or to preserve them as Annotation instances
- Returns:
- a MultiValueMapkeyed by attribute name, containing the annotation attributes from all annotations found, ornullif not found
 
- 
hasAnnotationpublic static boolean hasAnnotation(AnnotatedElement element, Class<? extends Annotation> annotationType) Determine if an annotation of the specifiedannotationTypeis available on the suppliedAnnotatedElementor within the annotation hierarchy above the specified element.If this method returns true, thenfindMergedAnnotationAttributes(AnnotatedElement, Class, boolean, boolean)will return a non-null value.This method follows find semantics as described in the class-level javadoc. - Parameters:
- element- the annotated element
- annotationType- the annotation type to find
- Returns:
- trueif a matching annotation is present
- Since:
- 4.3
- See Also:
 
- 
findMergedAnnotationAttributespublic static @Nullable AnnotationAttributes findMergedAnnotationAttributes(AnnotatedElement element, Class<? extends Annotation> annotationType, boolean classValuesAsString, boolean nestedAnnotationsAsMap) Find the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.In contrast to getAllAnnotationAttributes(AnnotatedElement, String), the search algorithm used by this method will stop searching the annotation hierarchy once the first annotation of the specifiedannotationTypehas been found. As a consequence, additional annotations of the specifiedannotationTypewill 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- AnnotationAttributesmaps or to preserve them as Annotation instances
- Returns:
- the merged AnnotationAttributes, ornullif not found
- Since:
- 4.2
- See Also:
 
- 
findMergedAnnotationAttributespublic static @Nullable AnnotationAttributes findMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) Find the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.In contrast to getAllAnnotationAttributes(AnnotatedElement, String), the search algorithm used by this method will stop searching the annotation hierarchy once the first annotation of the specifiedannotationNamehas been found. As a consequence, additional annotations of the specifiedannotationNamewill 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- AnnotationAttributesmaps or to preserve them as Annotation instances
- Returns:
- the merged AnnotationAttributes, ornullif not found
- Since:
- 4.2
- See Also:
 
- 
findMergedAnnotationpublic static <A extends Annotation> @Nullable A findMergedAnnotation(AnnotatedElement element, Class<A> annotationType) Find the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement, 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 specifiedannotationType.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.This method follows find semantics as described in the class-level javadoc. - Parameters:
- element- the annotated element
- annotationType- the annotation type to find
- Returns:
- the merged, synthesized Annotation, ornullif not found
- Since:
- 4.2
- See Also:
 
- 
findAllMergedAnnotationspublic static <A extends Annotation> Set<A> findAllMergedAnnotations(AnnotatedElement element, Class<A> annotationType) Find all annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; 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 specifiedannotationType.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.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 Annotationsfound, or an empty set if none were found
- Since:
- 4.3
- See Also:
 
- 
findAllMergedAnnotationspublic static Set<Annotation> findAllMergedAnnotations(AnnotatedElement element, Set<Class<? extends Annotation>> annotationTypes) Find all annotations of the specifiedannotationTypeswithin the annotation hierarchy above the suppliedelement; 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 correspondingannotationType.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.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 Annotationsfound, or an empty set if none were found
- Since:
- 5.1
- See Also:
 
- 
findMergedRepeatableAnnotationspublic static <A extends Annotation> Set<A> findMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType) Find all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; 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 specifiedannotationType.The container type that holds the repeatable annotations will be looked up via @Repeatable.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.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 Annotationsfound, or an empty set if none were found
- Throws:
- IllegalArgumentException- if the- elementor- annotationTypeis- null, or if the container type cannot be resolved
- Since:
- 4.3
- See Also:
 
- 
findMergedRepeatableAnnotationspublic static <A extends Annotation> Set<A> findMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType, @Nullable Class<? extends Annotation> containerType) Find all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; 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 specifiedannotationType.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.This method follows find semantics as described in the class-level javadoc. WARNING: if the supplied containerTypeis notnull, the search will be restricted to supporting only repeatable annotations whose container is the suppliedcontainerType. This prevents the search from finding repeatable annotations declared as meta-annotations on other types of repeatable annotations. If you need to support such a use case, favorfindMergedRepeatableAnnotations(AnnotatedElement, Class)over this method or alternatively use theMergedAnnotationsAPI directly in conjunction withRepeatableContainersthat are composed to support multiple repeatable annotation types — for example:RepeatableContainers.standardRepeatables() .plus(MyRepeatable1.class, MyContainer1.class) .plus(MyRepeatable2.class, MyContainer2.class);- Parameters:
- element- the annotated element (never- null)
- annotationType- the repeatable annotation type to find (never- null)
- containerType- the type of the container that holds the repeatable annotations; may be- nullif the container type should be looked up via- @Repeatable
- Returns:
- the set of all merged repeatable Annotationsfound, or an empty set if none were found
- Throws:
- IllegalArgumentException- if the- elementor- annotationTypeis- null, or if the container type cannot be resolved
- AnnotationConfigurationException- if the supplied- containerTypeis not a valid container annotation for the supplied- annotationType
- Since:
- 4.3
- See Also:
 
 
-