接口 MergedAnnotation<A extends Annotation>

  • 类型参数:
    A - the annotation type

    public interface MergedAnnotation<A extends Annotation>
    A single merged annotation returned from a MergedAnnotations collection. Presents a view onto an annotation where attribute values may have been "merged" from different source values.

    Attribute values may be accessed using the various get methods. For example, to access an int attribute the getInt(String) method would be used.

    Note that attribute values are not converted when accessed. For example, it is not possible to call getString(String) if the underlying attribute is an int. The only exception to this rule is Class and Class[] values which may be accessed as String and String[] respectively to prevent potential early class initialization.

    If necessary, a MergedAnnotation can be synthesized back into an actual Annotation.

    从以下版本开始:
    5.2
    作者:
    Phillip Webb, Juergen Hoeller, Sam Brannen
    另请参阅:
    MergedAnnotations, MergedAnnotationPredicates
    • 字段详细资料

    • 方法详细资料

      • getType

        Class<AgetType()
        Get the Class reference for the actual annotation type.
        返回:
        the annotation type
      • isDirectlyPresent

        boolean isDirectlyPresent()
        Determine if the annotation is directly present on the source.

        A directly present annotation is one that the user has explicitly declared and not one that is meta-present or @Inherited.

        返回:
        true if the annotation is directly present
      • isMetaPresent

        boolean isMetaPresent()
        Determine if the annotation is meta-present on the source.

        A meta-present annotation is an annotation that the user hasn't explicitly declared, but has been used as a meta-annotation somewhere in the annotation hierarchy.

        返回:
        true if the annotation is meta-present
      • getDistance

        int getDistance()
        Get the distance of this annotation related to its use as a meta-annotation.

        A directly declared annotation has a distance of 0, a meta-annotation has a distance of 1, a meta-annotation on a meta-annotation has a distance of 2, etc. A missing annotation will always return a distance of -1.

        返回:
        the annotation distance or -1 if the annotation is missing
      • getAggregateIndex

        int getAggregateIndex()
        Get the index of the aggregate collection containing this annotation.

        Can be used to reorder a stream of annotations, for example, to give a higher priority to annotations declared on a superclass or interface. A missing annotation will always return an aggregate index of -1.

        返回:
        the aggregate index (starting at 0) or -1 if the annotation is missing
      • getSource

        @Nullable
        Object getSource()
        Get the source that ultimately declared the root annotation, or null if the source is not known.

        If this merged annotation was created from an AnnotatedElement then this source will be an element of the same type. If the annotation was loaded without using reflection, the source can be of any type, but should have a sensible toString(). Meta-annotations will always return the same source as the root.

        返回:
        the source, or null
      • hasNonDefaultValue

        boolean hasNonDefaultValue​(String attributeName)
        Determine if the specified attribute name has a non-default value when compared to the annotation declaration.
        参数:
        attributeName - the attribute name
        返回:
        true if the attribute value is different from the default value
      • hasDefaultValue

        boolean hasDefaultValue​(String attributeName)
                         throws NoSuchElementException
        Determine if the specified attribute name has a default value when compared to the annotation declaration.
        参数:
        attributeName - the attribute name
        返回:
        true if the attribute value is the same as the default value
        抛出:
        NoSuchElementException
      • getValue

        Optional<ObjectgetValue​(String attributeName)
        Get an optional attribute value from the annotation.
        参数:
        attributeName - the attribute name
        返回:
        an optional value or Optional.empty() if there is no matching attribute
      • getValue

        <T> Optional<T> getValue​(String attributeName,
                                 Class<T> type)
        Get an optional attribute value from the annotation.
        参数:
        attributeName - the attribute name
        type - the attribute type. Must be compatible with the underlying attribute type or Object.class.
        返回:
        an optional value or Optional.empty() if there is no matching attribute
      • getDefaultValue

        Optional<ObjectgetDefaultValue​(String attributeName)
        Get the default attribute value from the annotation as specified in the annotation declaration.
        参数:
        attributeName - the attribute name
        返回:
        an optional of the default value or Optional.empty() if there is no matching attribute or no defined default
      • getDefaultValue

        <T> Optional<T> getDefaultValue​(String attributeName,
                                        Class<T> type)
        Get the default attribute value from the annotation as specified in the annotation declaration.
        参数:
        attributeName - the attribute name
        type - the attribute type. Must be compatible with the underlying attribute type or Object.class.
        返回:
        an optional of the default value or Optional.empty() if there is no matching attribute or no defined default
      • withNonMergedAttributes

        MergedAnnotation<AwithNonMergedAttributes()
        Create a new view of the annotation that exposes non-merged attribute values.

        Methods from this view will return attribute values with only alias mirroring rules applied. Aliases to meta-source attributes will not be applied.

        返回:
        a non-merged view of the annotation
      • asMap

        Map<String,​ObjectasMap​(MergedAnnotation.Adapt... adaptations)
        Get an immutable Map that contains all the annotation attributes.

        The adaptations may be used to change the way that values are added.

        参数:
        adaptations - the adaptations that should be applied to the annotation values
        返回:
        an immutable map containing the attributes and values
      • asMap

        <T extends Map<String,​Object>> T asMap​(Function<MergedAnnotation<?>,​T> factory,
                                                     MergedAnnotation.Adapt... adaptations)
        Create a new Map instance of the given type that contains all the annotation attributes.

        The adaptations may be used to change the way that values are added.

        参数:
        factory - a map factory
        adaptations - the adaptations that should be applied to the annotation values
        返回:
        a map containing the attributes and values
      • synthesize

        A synthesize()
              throws NoSuchElementException
        Create a type-safe synthesized version of this merged annotation that can be used directly in code.

        The result is synthesized using a JDK Proxy and as a result may incur a computational cost when first invoked.

        If this merged annotation was created from an annotation instance, that annotation will be returned unmodified if it is not synthesizable. An annotation is considered synthesizable if one of the following is true.

        • The annotation declares attributes annotated with @AliasFor.
        • The annotation is a composed annotation that relies on convention-based annotation attribute overrides in meta-annotations.
        • The annotation declares attributes that are annotations or arrays of annotations that are themselves synthesizable.
        返回:
        a synthesized version of the annotation or the original annotation unmodified
        抛出:
        NoSuchElementException - on a missing annotation
      • synthesize

        Optional<Asynthesize​(Predicate<? super MergedAnnotation<A>> condition)
                        throws NoSuchElementException
        Optionally create a type-safe synthesized version of this annotation based on a condition predicate.

        The result is synthesized using a JDK Proxy and as a result may incur a computational cost when first invoked.

        Consult the documentation for synthesize() for an explanation of what is considered synthesizable.

        参数:
        condition - the test to determine if the annotation can be synthesized
        返回:
        an optional containing the synthesized version of the annotation or an empty optional if the condition doesn't match
        抛出:
        NoSuchElementException - on a missing annotation
        另请参阅:
        MergedAnnotationPredicates
      • from

        static <A extends AnnotationMergedAnnotation<A> from​(@Nullable
                                                               Object source,
                                                               A annotation)
        Create a new MergedAnnotation instance from the specified annotation.
        参数:
        source - the source for the annotation. This source is used only for information and logging. It does not need to actually contain the specified annotations, and it will not be searched.
        annotation - the annotation to include
        返回:
        a MergedAnnotation instance for the annotation
      • of

        static <A extends AnnotationMergedAnnotation<A> of​(Class<A> annotationType)
        Create a new MergedAnnotation instance of the specified annotation type. The resulting annotation will not have any attribute values but may still be used to query default values.
        参数:
        annotationType - the annotation type
        返回:
        a MergedAnnotation instance for the annotation
      • of

        static <A extends AnnotationMergedAnnotation<A> of​(@Nullable
                                                             AnnotatedElement source,
                                                             Class<A> annotationType,
                                                             @Nullable
                                                             Map<String,​?> attributes)
        Create a new MergedAnnotation instance of the specified annotation type with attribute values supplied by a map.
        参数:
        source - the source for the annotation. This source is used only for information and logging. It does not need to actually contain the specified annotations and it will not be searched.
        annotationType - the annotation type
        attributes - the annotation attributes or null if just default values should be used
        返回:
        a MergedAnnotation instance for the annotation and attributes
      • of

        static <A extends AnnotationMergedAnnotation<A> of​(@Nullable
                                                             ClassLoader classLoader,
                                                             @Nullable
                                                             Object source,
                                                             Class<A> annotationType,
                                                             @Nullable
                                                             Map<String,​?> attributes)
        Create a new MergedAnnotation instance of the specified annotation type with attribute values supplied by a map.
        参数:
        classLoader - the class loader used to resolve class attributes
        source - the source for the annotation. This source is used only for information and logging. It does not need to actually contain the specified annotations and it will not be searched.
        annotationType - the annotation type
        attributes - the annotation attributes or null if just default values should be used
        返回:
        a MergedAnnotation instance for the annotation and attributes