open class AnnotatedElementUtils
General utility methods for finding annotations, meta-annotations, and repeatable annotations on AnnotatedElement.
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 OverridesSupport 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.
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 java.lang.annotation.Inherited) or declared within the annotation hierarchy above the AnnotatedElement.
Find semantics are much more exhaustive, providing get semantics plus support for the following:
@Inherited
Methods following get semantics will honor the contract of Java's java.lang.annotation.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 the need for @Inherited.
Author
Phillip Webb
Author
Juergen Hoeller
Author
Sam Brannen
Since
4.0
See Also
AliasForAnnotationAttributesAnnotationUtilsBridgeMethodResolver
AnnotatedElementUtils()
General utility methods for finding annotations, meta-annotations, and repeatable annotations on AnnotatedElement.
Note that the features of this class are not provided by the JDK's introspection facilities themselves. Annotation Attribute OverridesSupport for meta-annotations with attribute overrides in composed annotations is provided by all variants of the 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 Find semantics are much more exhaustive, providing get semantics plus support for the following:
@Inherited
Methods following get semantics will honor the contract of Java's java.lang.annotation.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 |
open static fun <A : Annotation> findAllMergedAnnotations(element: AnnotatedElement, annotationType: Class<A>): MutableSet<A>
Find all annotations of the specified AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies. This method follows find semantics as described in the AnnotatedElementUtils. |
|
open static fun <A : Annotation> findMergedAnnotation(element: AnnotatedElement, annotationType: Class<A>): A
Find the first annotation of the specified AliasFor semantics are fully supported, both within a single annotation and within the annotation hierarchy. This method follows find semantics as described in the AnnotatedElementUtils. |
|
open static fun findMergedAnnotationAttributes(element: AnnotatedElement, annotationType: Class<out Annotation>, classValuesAsString: Boolean, nestedAnnotationsAsMap: Boolean): AnnotationAttributes
Find the first annotation of the specified 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 This method follows find semantics as described in the AnnotatedElementUtils. open static fun findMergedAnnotationAttributes(element: AnnotatedElement, annotationName: String, classValuesAsString: Boolean, nestedAnnotationsAsMap: Boolean): AnnotationAttributes
Find the first annotation of the specified 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 This method follows find semantics as described in the AnnotatedElementUtils. |
|
open static fun <A : Annotation> findMergedRepeatableAnnotations(element: AnnotatedElement, annotationType: Class<A>): MutableSet<A>
Find all repeatable annotations of the specified The container type that holds the repeatable annotations will be looked up via java.lang.annotation.Repeatable. AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies. This method follows find semantics as described in the AnnotatedElementUtils. open static fun <A : Annotation> findMergedRepeatableAnnotations(element: AnnotatedElement, annotationType: Class<A>, containerType: Class<out Annotation>): MutableSet<A>
Find all repeatable annotations of the specified AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies. This method follows find semantics as described in the AnnotatedElementUtils. |
|
open static fun forAnnotations(vararg annotations: Annotation): AnnotatedElement
Build an adapted AnnotatedElement for the given annotations, typically for use with other methods on AnnotatedElementUtils. |
|
open static fun getAllAnnotationAttributes(element: AnnotatedElement, annotationName: String): MultiValueMap<String, Any>open static fun getAllAnnotationAttributes(element: AnnotatedElement, annotationName: String, classValuesAsString: Boolean, nestedAnnotationsAsMap: Boolean): MultiValueMap<String, Any>
Get the annotation attributes of all annotations of the specified Note: in contrast to This method follows get semantics as described in the AnnotatedElementUtils. |
|
open static fun <A : Annotation> getAllMergedAnnotations(element: AnnotatedElement, annotationType: Class<A>): MutableSet<A>
Get all annotations of the specified AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies. This method follows get semantics as described in the AnnotatedElementUtils. |
|
open static fun <A : Annotation> getMergedAnnotation(element: AnnotatedElement, annotationType: Class<A>): A
Get the first annotation of the specified AliasFor semantics are fully supported, both within a single annotation and within the annotation hierarchy. This method delegates to |
|
open static fun getMergedAnnotationAttributes(element: AnnotatedElement, annotationType: Class<out Annotation>): AnnotationAttributes
Get the first annotation of the specified AliasFor semantics are fully supported, both within a single annotation and within the annotation hierarchy. This method delegates to open static fun getMergedAnnotationAttributes(element: AnnotatedElement, annotationName: String): AnnotationAttributes
Get the first annotation of the specified AliasFor semantics are fully supported, both within a single annotation and within the annotation hierarchy. This method delegates to open static fun getMergedAnnotationAttributes(element: AnnotatedElement, annotationName: String, classValuesAsString: Boolean, nestedAnnotationsAsMap: Boolean): AnnotationAttributes
Get the first annotation of the specified 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 This method follows get semantics as described in the AnnotatedElementUtils. |
|
open static fun <A : Annotation> getMergedRepeatableAnnotations(element: AnnotatedElement, annotationType: Class<A>): MutableSet<A>
Get all repeatable annotations of the specified The container type that holds the repeatable annotations will be looked up via java.lang.annotation.Repeatable. AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies. This method follows get semantics as described in the AnnotatedElementUtils. open static fun <A : Annotation> getMergedRepeatableAnnotations(element: AnnotatedElement, annotationType: Class<A>, containerType: Class<out Annotation>): MutableSet<A>
Get all repeatable annotations of the specified AliasFor semantics are fully supported, both within a single annotation and within annotation hierarchies. This method follows get semantics as described in the AnnotatedElementUtils. |
|
open static fun getMetaAnnotationTypes(element: AnnotatedElement, annotationType: Class<out Annotation>): MutableSet<String>
Get the fully qualified class names of all meta-annotation types present on the annotation (of the specified This method follows get semantics as described in the AnnotatedElementUtils. open static fun getMetaAnnotationTypes(element: AnnotatedElement, annotationName: String): MutableSet<String>
Get the fully qualified class names of all meta-annotation types present on the annotation (of the specified This method follows get semantics as described in the AnnotatedElementUtils. |
|
open static fun hasAnnotation(element: AnnotatedElement, annotationType: Class<out Annotation>): Boolean
Determine if an annotation of the specified If this method returns This method follows find semantics as described in the AnnotatedElementUtils. |
|
open static fun hasMetaAnnotationTypes(element: AnnotatedElement, annotationType: Class<out Annotation>): Boolean
Determine if the supplied AnnotatedElement is annotated with a composed annotation that is meta-annotated with an annotation of the specified This method follows get semantics as described in the AnnotatedElementUtils. open static fun hasMetaAnnotationTypes(element: AnnotatedElement, annotationName: String): Boolean
Determine if the supplied AnnotatedElement is annotated with a composed annotation that is meta-annotated with an annotation of the specified This method follows get semantics as described in the AnnotatedElementUtils. |
|
open static fun isAnnotated(element: AnnotatedElement, annotationType: Class<out Annotation>): Boolean
Determine if an annotation of the specified If this method returns This method follows get semantics as described in the AnnotatedElementUtils. open static fun isAnnotated(element: AnnotatedElement, annotationName: String): Boolean
Determine if an annotation of the specified If this method returns This method follows get semantics as described in the AnnotatedElementUtils. |