类 AnnotatedElementUtils


  • public abstract class AnnotatedElementUtils
    extends 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.

    从以下版本开始:
    4.0
    作者:
    Phillip Webb, Juergen Hoeller, Sam Brannen
    另请参阅:
    AliasFor, AnnotationAttributes, AnnotationUtils, BridgeMethodResolver
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型方法说明
      static <A extends Annotation>
      Set<A>
      findAllMergedAnnotations​(AnnotatedElement element, 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 Set<Annotation>findAllMergedAnnotations​(AnnotatedElement element, Set<Class<? extends 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 Annotation>
      A
      findMergedAnnotation​(AnnotatedElement element, 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 AnnotationAttributesfindMergedAnnotationAttributes​(AnnotatedElement element, Class<? extends 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 AnnotationAttributesfindMergedAnnotationAttributes​(AnnotatedElement element, 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 Annotation>
      Set<A>
      findMergedRepeatableAnnotations​(AnnotatedElement element, 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 Annotation>
      Set<A>
      findMergedRepeatableAnnotations​(AnnotatedElement element, Class<A> annotationType, Class<? extends 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 AnnotatedElementforAnnotations​(Annotation... annotations)
      Build an adapted AnnotatedElement for the given annotations, typically for use with other methods on AnnotatedElementUtils.
      static MultiValueMap<String,​Object>getAllAnnotationAttributes​(AnnotatedElement element, 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<String,​Object>getAllAnnotationAttributes​(AnnotatedElement element, 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 Annotation>
      Set<A>
      getAllMergedAnnotations​(AnnotatedElement element, 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 Set<Annotation>getAllMergedAnnotations​(AnnotatedElement element, Set<Class<? extends 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 Annotation>
      A
      getMergedAnnotation​(AnnotatedElement element, 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 AnnotationAttributesgetMergedAnnotationAttributes​(AnnotatedElement element, Class<? extends 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 AnnotationAttributesgetMergedAnnotationAttributes​(AnnotatedElement element, 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 AnnotationAttributesgetMergedAnnotationAttributes​(AnnotatedElement element, 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 Annotation>
      Set<A>
      getMergedRepeatableAnnotations​(AnnotatedElement element, 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 Annotation>
      Set<A>
      getMergedRepeatableAnnotations​(AnnotatedElement element, Class<A> annotationType, Class<? extends 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 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 specified annotationType) on the supplied AnnotatedElement.
      static Set<String>getMetaAnnotationTypes​(AnnotatedElement element, 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 booleanhasAnnotation​(AnnotatedElement element, Class<? extends 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 booleanhasMetaAnnotationTypes​(AnnotatedElement element, Class<? extends 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 booleanhasMetaAnnotationTypes​(AnnotatedElement element, 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 booleanisAnnotated​(AnnotatedElement element, Class<? extends 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 booleanisAnnotated​(AnnotatedElement element, 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.