接口 MergedAnnotation<A extends Annotation>
- 类型参数:
A
- the annotation type
public interface MergedAnnotation<A extends Annotation>
A single merged annotation returned from aMergedAnnotations
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 anint
attribute thegetInt(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 anint
. The only exception to this rule isClass
andClass[]
values which may be accessed asString
andString[]
respectively to prevent potential early class initialization.If necessary, a
MergedAnnotation
can be synthesized back into an actualAnnotation
.- 从以下版本开始:
- 5.2
- 作者:
- Phillip Webb, Juergen Hoeller, Sam Brannen
- 另请参阅:
MergedAnnotations
,MergedAnnotationPredicates
嵌套类概要
嵌套类 修饰符和类型 接口 说明 static class
MergedAnnotation.Adapt
Adaptations that can be applied to attribute values when creating Maps orAnnotationAttributes
.
方法概要
所有方法 静态方法 实例方法 抽象方法 修饰符和类型 方法 说明 AnnotationAttributes
asAnnotationAttributes(MergedAnnotation.Adapt... adaptations)
Create a new mutableAnnotationAttributes
instance from this merged annotation.<T extends Map<String,Object>>
TasMap(Function<MergedAnnotation<?>,T> factory, MergedAnnotation.Adapt... adaptations)
Create a newMap
instance of the given type that contains all the annotation attributes.Map<String,Object>
asMap(MergedAnnotation.Adapt... adaptations)
Get an immutableMap
that contains all the annotation attributes.MergedAnnotation<A>
filterAttributes(Predicate<String> predicate)
Create a new view of the annotation with only attributes that match the given predicate.MergedAnnotation<A>
filterDefaultValues()
Create a new view of the annotation with all attributes that have default values removed.static <A extends Annotation>
MergedAnnotation<A>from(A annotation)
Create a newMergedAnnotation
instance from the specified annotation.static <A extends Annotation>
MergedAnnotation<A>from(Object source, A annotation)
Create a newMergedAnnotation
instance from the specified annotation.int
getAggregateIndex()
Get the index of the aggregate collection containing this annotation.<T extends Annotation>
MergedAnnotation<T>getAnnotation(String attributeName, Class<T> type)
Get a required annotation attribute value from the annotation.<T extends Annotation>
MergedAnnotation<T>[]getAnnotationArray(String attributeName, Class<T> type)
Get a required annotation array attribute value from the annotation.boolean
getBoolean(String attributeName)
Get a required boolean attribute value from the annotation.boolean[]
getBooleanArray(String attributeName)
Get a required boolean array attribute value from the annotation.byte
getByte(String attributeName)
Get a required byte attribute value from the annotation.byte[]
getByteArray(String attributeName)
Get a required byte array attribute value from the annotation.char
getChar(String attributeName)
Get a required char attribute value from the annotation.char[]
getCharArray(String attributeName)
Get a required char array attribute value from the annotation.Class<?>
getClass(String attributeName)
Get a required class attribute value from the annotation.Class<?>[]
getClassArray(String attributeName)
Get a required class array attribute value from the annotation.Optional<Object>
getDefaultValue(String attributeName)
Get the default attribute value from the annotation as specified in the annotation declaration.<T> Optional<T>
getDefaultValue(String attributeName, Class<T> type)
Get the default attribute value from the annotation as specified in the annotation declaration.int
getDistance()
Get the distance of this annotation related to its use as a meta-annotation.double
getDouble(String attributeName)
Get a required double attribute value from the annotation.double[]
getDoubleArray(String attributeName)
Get a required double array attribute value from the annotation.<E extends Enum<E>>
EgetEnum(String attributeName, Class<E> type)
Get a required enum attribute value from the annotation.<E extends Enum<E>>
E[]getEnumArray(String attributeName, Class<E> type)
Get a required enum array attribute value from the annotation.float
getFloat(String attributeName)
Get a required float attribute value from the annotation.float[]
getFloatArray(String attributeName)
Get a required float array attribute value from the annotation.int
getInt(String attributeName)
Get a required int attribute value from the annotation.int[]
getIntArray(String attributeName)
Get a required int array attribute value from the annotation.long
getLong(String attributeName)
Get a required long attribute value from the annotation.long[]
getLongArray(String attributeName)
Get a required long array attribute value from the annotation.MergedAnnotation<?>
getMetaSource()
Get the source of the meta-annotation, ornull
if the annotation is not meta-present.List<Class<? extends Annotation>>
getMetaTypes()
Get the complete list of annotation types within the annotation hierarchy from this annotation to theroot
.MergedAnnotation<?>
getRoot()
Get the root annotation, i.e. thedistance
0
annotation as directly declared on the source.short
getShort(String attributeName)
Get a required short attribute value from the annotation.short[]
getShortArray(String attributeName)
Get a required short array attribute value from the annotation.Object
getSource()
Get the source that ultimately declared the root annotation, ornull
if the source is not known.String
getString(String attributeName)
Get a required string attribute value from the annotation.String[]
getStringArray(String attributeName)
Get a required string array attribute value from the annotation.Class<A>
getType()
Get theClass
reference for the actual annotation type.Optional<Object>
getValue(String attributeName)
Get an optional attribute value from the annotation.<T> Optional<T>
getValue(String attributeName, Class<T> type)
Get an optional attribute value from the annotation.boolean
hasDefaultValue(String attributeName)
Determine if the specified attribute name has a default value when compared to the annotation declaration.boolean
hasNonDefaultValue(String attributeName)
Determine if the specified attribute name has a non-default value when compared to the annotation declaration.boolean
isDirectlyPresent()
Determine if the annotation is directly present on the source.boolean
isMetaPresent()
Determine if the annotation is meta-present on the source.boolean
isPresent()
Determine if the annotation is present on the source.static <A extends Annotation>
MergedAnnotation<A>missing()
Create aMergedAnnotation
that represents a missing annotation (i.e. one that is not present).static <A extends Annotation>
MergedAnnotation<A>of(Class<A> annotationType)
Create a newMergedAnnotation
instance of the specified annotation type.static <A extends Annotation>
MergedAnnotation<A>of(Class<A> annotationType, Map<String,?> attributes)
Create a newMergedAnnotation
instance of the specified annotation type with attribute values supplied by a map.static <A extends Annotation>
MergedAnnotation<A>of(ClassLoader classLoader, Object source, Class<A> annotationType, Map<String,?> attributes)
Create a newMergedAnnotation
instance of the specified annotation type with attribute values supplied by a map.static <A extends Annotation>
MergedAnnotation<A>of(AnnotatedElement source, Class<A> annotationType, Map<String,?> attributes)
Create a newMergedAnnotation
instance of the specified annotation type with attribute values supplied by a map.A
synthesize()
Create a type-safe synthesized version of this merged annotation that can be used directly in code.Optional<A>
synthesize(Predicate<? super MergedAnnotation<A>> condition)
Optionally create a type-safe synthesized version of this annotation based on a condition predicate.MergedAnnotation<A>
withNonMergedAttributes()
Create a new view of the annotation that exposes non-merged attribute values.
方法详细资料
getType
Class<A> getType()
Get theClass
reference for the actual annotation type.- 返回:
- the annotation type
isPresent
boolean isPresent()
Determine if the annotation is present on the source. Considers directly present and meta-present annotations within the context of theMergedAnnotations.SearchStrategy
used.- 返回:
true
if the annotation is present
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 of1
, a meta-annotation on a meta-annotation has a distance of2
, 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, ornull
if the source is not known.If this merged annotation was created
from
anAnnotatedElement
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 sensibletoString()
. Meta-annotations will always return the same source as theroot
.- 返回:
- the source, or
null
getMetaSource
@Nullable MergedAnnotation<?> getMetaSource()
Get the source of the meta-annotation, ornull
if the annotation is not meta-present.The meta-source is the annotation that was meta-annotated with this annotation.
- 返回:
- the meta-annotation source or
null
- 另请参阅:
getRoot()
getRoot
MergedAnnotation<?> getRoot()
Get the root annotation, i.e. thedistance
0
annotation as directly declared on the source.- 返回:
- the root annotation
- 另请参阅:
getMetaSource()
getMetaTypes
List<Class<? extends Annotation>> getMetaTypes()
Get the complete list of annotation types within the annotation hierarchy from this annotation to theroot
.Provides a useful way to uniquely identify a merged annotation instance.
- 返回:
- the meta types for the annotation
- 另请参阅:
MergedAnnotationPredicates.unique(Function)
,getRoot()
,getMetaSource()
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
getByte
byte getByte(String attributeName) throws NoSuchElementException
Get a required byte attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a byte
- 抛出:
NoSuchElementException
- if there is no matching attribute
getByteArray
byte[] getByteArray(String attributeName) throws NoSuchElementException
Get a required byte array attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a byte array
- 抛出:
NoSuchElementException
- if there is no matching attribute
getBoolean
boolean getBoolean(String attributeName) throws NoSuchElementException
Get a required boolean attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a boolean
- 抛出:
NoSuchElementException
- if there is no matching attribute
getBooleanArray
boolean[] getBooleanArray(String attributeName) throws NoSuchElementException
Get a required boolean array attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a boolean array
- 抛出:
NoSuchElementException
- if there is no matching attribute
getChar
char getChar(String attributeName) throws NoSuchElementException
Get a required char attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a char
- 抛出:
NoSuchElementException
- if there is no matching attribute
getCharArray
char[] getCharArray(String attributeName) throws NoSuchElementException
Get a required char array attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a char array
- 抛出:
NoSuchElementException
- if there is no matching attribute
getShort
short getShort(String attributeName) throws NoSuchElementException
Get a required short attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a short
- 抛出:
NoSuchElementException
- if there is no matching attribute
getShortArray
short[] getShortArray(String attributeName) throws NoSuchElementException
Get a required short array attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a short array
- 抛出:
NoSuchElementException
- if there is no matching attribute
getInt
int getInt(String attributeName) throws NoSuchElementException
Get a required int attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as an int
- 抛出:
NoSuchElementException
- if there is no matching attribute
getIntArray
int[] getIntArray(String attributeName) throws NoSuchElementException
Get a required int array attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as an int array
- 抛出:
NoSuchElementException
- if there is no matching attribute
getLong
long getLong(String attributeName) throws NoSuchElementException
Get a required long attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a long
- 抛出:
NoSuchElementException
- if there is no matching attribute
getLongArray
long[] getLongArray(String attributeName) throws NoSuchElementException
Get a required long array attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a long array
- 抛出:
NoSuchElementException
- if there is no matching attribute
getDouble
double getDouble(String attributeName) throws NoSuchElementException
Get a required double attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a double
- 抛出:
NoSuchElementException
- if there is no matching attribute
getDoubleArray
double[] getDoubleArray(String attributeName) throws NoSuchElementException
Get a required double array attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a double array
- 抛出:
NoSuchElementException
- if there is no matching attribute
getFloat
float getFloat(String attributeName) throws NoSuchElementException
Get a required float attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a float
- 抛出:
NoSuchElementException
- if there is no matching attribute
getFloatArray
float[] getFloatArray(String attributeName) throws NoSuchElementException
Get a required float array attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a float array
- 抛出:
NoSuchElementException
- if there is no matching attribute
getString
String getString(String attributeName) throws NoSuchElementException
Get a required string attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a string
- 抛出:
NoSuchElementException
- if there is no matching attribute
getStringArray
String[] getStringArray(String attributeName) throws NoSuchElementException
Get a required string array attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a string array
- 抛出:
NoSuchElementException
- if there is no matching attribute
getClass
Class<?> getClass(String attributeName) throws NoSuchElementException
Get a required class attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a class
- 抛出:
NoSuchElementException
- if there is no matching attribute
getClassArray
Class<?>[] getClassArray(String attributeName) throws NoSuchElementException
Get a required class array attribute value from the annotation.- 参数:
attributeName
- the attribute name- 返回:
- the value as a class array
- 抛出:
NoSuchElementException
- if there is no matching attribute
getEnum
<E extends Enum<E>> E getEnum(String attributeName, Class<E> type) throws NoSuchElementException
Get a required enum attribute value from the annotation.- 参数:
attributeName
- the attribute nametype
- the enum type- 返回:
- the value as a enum
- 抛出:
NoSuchElementException
- if there is no matching attribute
getEnumArray
<E extends Enum<E>> E[] getEnumArray(String attributeName, Class<E> type) throws NoSuchElementException
Get a required enum array attribute value from the annotation.- 参数:
attributeName
- the attribute nametype
- the enum type- 返回:
- the value as a enum array
- 抛出:
NoSuchElementException
- if there is no matching attribute
getAnnotation
<T extends Annotation> MergedAnnotation<T> getAnnotation(String attributeName, Class<T> type) throws NoSuchElementException
Get a required annotation attribute value from the annotation.- 参数:
attributeName
- the attribute nametype
- the annotation type- 返回:
- the value as a
MergedAnnotation
- 抛出:
NoSuchElementException
- if there is no matching attribute
getAnnotationArray
<T extends Annotation> MergedAnnotation<T>[] getAnnotationArray(String attributeName, Class<T> type) throws NoSuchElementException
Get a required annotation array attribute value from the annotation.- 参数:
attributeName
- the attribute nametype
- the annotation type- 返回:
- the value as a
MergedAnnotation
array - 抛出:
NoSuchElementException
- if there is no matching attribute
getValue
Optional<Object> getValue(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 nametype
- the attribute type. Must be compatible with the underlying attribute type orObject.class
.- 返回:
- an optional value or
Optional.empty()
if there is no matching attribute
getDefaultValue
Optional<Object> getDefaultValue(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 nametype
- the attribute type. Must be compatible with the underlying attribute type orObject.class
.- 返回:
- an optional of the default value or
Optional.empty()
if there is no matching attribute or no defined default
filterDefaultValues
MergedAnnotation<A> filterDefaultValues()
Create a new view of the annotation with all attributes that have default values removed.- 返回:
- a filtered view of the annotation without any attributes that have a default value
- 另请参阅:
filterAttributes(Predicate)
filterAttributes
MergedAnnotation<A> filterAttributes(Predicate<String> predicate)
Create a new view of the annotation with only attributes that match the given predicate.- 参数:
predicate
- a predicate used to filter attribute names- 返回:
- a filtered view of the annotation
- 另请参阅:
filterDefaultValues()
,MergedAnnotationPredicates
withNonMergedAttributes
MergedAnnotation<A> withNonMergedAttributes()
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
asAnnotationAttributes
AnnotationAttributes asAnnotationAttributes(MergedAnnotation.Adapt... adaptations)
Create a new mutableAnnotationAttributes
instance from this merged annotation.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
Map<String,Object> asMap(MergedAnnotation.Adapt... adaptations)
Get an immutableMap
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 newMap
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 factoryadaptations
- 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
- The annotation declares attributes annotated with
synthesize
Optional<A> synthesize(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
missing
static <A extends Annotation> MergedAnnotation<A> missing()
Create aMergedAnnotation
that represents a missing annotation (i.e. one that is not present).- 返回:
- an instance representing a missing annotation
from
static <A extends Annotation> MergedAnnotation<A> from(A annotation)
Create a newMergedAnnotation
instance from the specified annotation.- 参数:
annotation
- the annotation to include- 返回:
- a
MergedAnnotation
instance containing the annotation
from
static <A extends Annotation> MergedAnnotation<A> from(@Nullable Object source, A annotation)
Create a newMergedAnnotation
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 Annotation> MergedAnnotation<A> of(Class<A> annotationType)
Create a newMergedAnnotation
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 Annotation> MergedAnnotation<A> of(Class<A> annotationType, @Nullable Map<String,?> attributes)
Create a newMergedAnnotation
instance of the specified annotation type with attribute values supplied by a map.- 参数:
annotationType
- the annotation typeattributes
- the annotation attributes ornull
if just default values should be used- 返回:
- a
MergedAnnotation
instance for the annotation and attributes - 另请参阅:
of(AnnotatedElement, Class, Map)
of
static <A extends Annotation> MergedAnnotation<A> of(@Nullable AnnotatedElement source, Class<A> annotationType, @Nullable Map<String,?> attributes)
Create a newMergedAnnotation
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 typeattributes
- the annotation attributes ornull
if just default values should be used- 返回:
- a
MergedAnnotation
instance for the annotation and attributes
of
static <A extends Annotation> MergedAnnotation<A> of(@Nullable ClassLoader classLoader, @Nullable Object source, Class<A> annotationType, @Nullable Map<String,?> attributes)
Create a newMergedAnnotation
instance of the specified annotation type with attribute values supplied by a map.- 参数:
classLoader
- the class loader used to resolve class attributessource
- 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 typeattributes
- the annotation attributes ornull
if just default values should be used- 返回:
- a
MergedAnnotation
instance for the annotation and attributes