Top Description Inners Fields Methods
org.springframework.core.annotation

public Interface MergedAnnotation<A extends Annotation>

Known Direct Implementers
org.springframework.core.annotation.AbstractMergedAnnotation
Type Parameters
<A>
the annotation type
Imports
java.lang.annotation.Annotation, .Inherited, java.lang.reflect.AnnotatedElement, java.util.EnumSet, .List, .Map, .NoSuchElementException, .Optional, .Set, java.util.function.Function, .Predicate, org.springframework.core.annotation.MergedAnnotations.SearchStrategy, org.springframework.lang.Nullable

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 java.lang.annotation.Annotation.

Authors
Phillip Webb, Juergen Hoeller, Sam Brannen
Since
5.2
See Also
MergedAnnotations, MergedAnnotationPredicates

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
MergedAnnotation.Adapt

Adaptations that can be applied to attribute values when creating Maps or AnnotationAttributes.

Field Summary

Modifier and TypeField and Description
public static final String
VALUE

The attribute name for annotations with a single element.

Method Summary

Modifier and TypeMethod and Description
public AnnotationAttributes

Returns:

an immutable map containing the attributes and values
asAnnotationAttributes
(MergedAnnotation.Adapt...
the adaptations that should be applied to the annotation values
adaptations
)

Create a new mutable AnnotationAttributes instance from this merged annotation.

public Map<String, Object>

Returns:

an immutable map containing the attributes and values
asMap
(MergedAnnotation.Adapt...
the adaptations that should be applied to the annotation values
adaptations
)

Get an immutable Map that contains all the annotation attributes.

public <T extends Map<String, Object>> T

Returns:

a map containing the attributes and values
asMap
(Function<MergedAnnotation<?>, T>
a map factory
factory
,
MergedAnnotation.Adapt...
the adaptations that should be applied to the annotation values
adaptations
)

Create a new Map instance of the given type that contains all the annotation attributes.

public MergedAnnotation<A>

Returns:

a filtered view of the annotation
filterAttributes
(Predicate<String>
a predicate used to filter attribute names
predicate
)

Create a new view of the annotation with only attributes that match the given predicate.

public MergedAnnotation<A>

Returns:

a filtered view of the annotation without any attributes that have a default value
filterDefaultValues
()

Create a new view of the annotation with all attributes that have default values removed.

public static <A extends Annotation> MergedAnnotation<A>

Returns:

a MergedAnnotation instance containing the annotation
from
(A
the annotation to include
annotation
)

Create a new MergedAnnotation instance from the specified annotation.

public static <A extends Annotation> MergedAnnotation<A>

Returns:

a MergedAnnotation instance for the annotation
from
(Object
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.
source
,
A
the annotation to include
annotation
)

Create a new MergedAnnotation instance from the specified annotation.

public int

Returns:

the aggregate index (starting at 0) or -1 if the annotation is missing
getAggregateIndex
()

Get the index of the aggregate collection containing this annotation.

public <T extends Annotation> MergedAnnotation<T>

Returns:

the value as a MergedAnnotation
getAnnotation
(String
the attribute name
attributeName
,
Class<T>
the annotation type
type
)

Get a required annotation attribute value from the annotation.

public <T extends Annotation> MergedAnnotation<T>[]

Returns:

the value as a MergedAnnotation array
getAnnotationArray
(String
the attribute name
attributeName
,
Class<T>
the annotation type
type
)

Get a required annotation array attribute value from the annotation.

public boolean

Returns:

the value as a boolean
getBoolean
(String
the attribute name
attributeName
)

Get a required boolean attribute value from the annotation.

public boolean[]

Returns:

the value as a boolean array
getBooleanArray
(String
the attribute name
attributeName
)

Get a required boolean array attribute value from the annotation.

public byte

Returns:

the value as a byte
getByte
(String
the attribute name
attributeName
)

Get a required byte attribute value from the annotation.

public byte[]

Returns:

the value as a byte array
getByteArray
(String
the attribute name
attributeName
)

Get a required byte array attribute value from the annotation.

public char

Returns:

the value as a char
getChar
(String
the attribute name
attributeName
)

Get a required char attribute value from the annotation.

public char[]

Returns:

the value as a char array
getCharArray
(String
the attribute name
attributeName
)

Get a required char array attribute value from the annotation.

public Class<?>

Returns:

the value as a class
getClass
(String
the attribute name
attributeName
)

Get a required class attribute value from the annotation.

public Class<?>[]

Returns:

the value as a class array
getClassArray
(String
the attribute name
attributeName
)

Get a required class array attribute value from the annotation.

public Optional<Object>

Returns:

an optional of the default value or Optional#empty() if there is no matching attribute or no defined default
getDefaultValue
(String
the attribute name
attributeName
)

Get the default attribute value from the annotation as specified in the annotation declaration.

public <T> Optional<T>

Returns:

an optional of the default value or Optional#empty() if there is no matching attribute or no defined default
getDefaultValue
(String
the attribute name
attributeName
,
Class<T>
the attribute type. Must be compatible with the underlying attribute type or Object.class.
type
)

Get the default attribute value from the annotation as specified in the annotation declaration.

public int

Returns:

the annotation distance or -1 if the annotation is missing
getDistance
()

Get the distance of this annotation related to its use as a meta-annotation.

public double

Returns:

the value as a double
getDouble
(String
the attribute name
attributeName
)

Get a required double attribute value from the annotation.

public double[]

Returns:

the value as a double array
getDoubleArray
(String
the attribute name
attributeName
)

Get a required double array attribute value from the annotation.

public <E extends Enum<E>> E

Returns:

the value as an enum
getEnum
(String
the attribute name
attributeName
,
Class<E>
the enum type
type
)

Get a required enum attribute value from the annotation.

public <E extends Enum<E>> E[]

Returns:

the value as an enum array
getEnumArray
(String
the attribute name
attributeName
,
Class<E>
the enum type
type
)

Get a required enum array attribute value from the annotation.

public float

Returns:

the value as a float
getFloat
(String
the attribute name
attributeName
)

Get a required float attribute value from the annotation.

public float[]

Returns:

the value as a float array
getFloatArray
(String
the attribute name
attributeName
)

Get a required float array attribute value from the annotation.

public int

Returns:

the value as an int
getInt
(String
the attribute name
attributeName
)

Get a required int attribute value from the annotation.

public int[]

Returns:

the value as an int array
getIntArray
(String
the attribute name
attributeName
)

Get a required int array attribute value from the annotation.

public long

Returns:

the value as a long
getLong
(String
the attribute name
attributeName
)

Get a required long attribute value from the annotation.

public long[]

Returns:

the value as a long array
getLongArray
(String
the attribute name
attributeName
)

Get a required long array attribute value from the annotation.

public MergedAnnotation<?>

Returns:

the meta-annotation source or null
getMetaSource
()

Get the source of the meta-annotation, or null if the annotation is not meta-present.

public List<Class<? extends Annotation>>

Returns:

the meta types for the annotation
getMetaTypes
()

Get the complete list of annotation types within the annotation hierarchy from this annotation to the root.

public MergedAnnotation<?>

Returns:

the root annotation
getRoot
()

Get the root annotation, i.e. the distance 0 annotation as directly declared on the source.

public short

Returns:

the value as a short
getShort
(String
the attribute name
attributeName
)

Get a required short attribute value from the annotation.

public short[]

Returns:

the value as a short array
getShortArray
(String
the attribute name
attributeName
)

Get a required short array attribute value from the annotation.

public Object

Returns:

the source, or null
getSource
()

Get the source that ultimately declared the root annotation, or null if the source is not known.

public String

Returns:

the value as a string
getString
(String
the attribute name
attributeName
)

Get a required string attribute value from the annotation.

public String[]

Returns:

the value as a string array
getStringArray
(String
the attribute name
attributeName
)

Get a required string array attribute value from the annotation.

public Class<A>

Returns:

the annotation type
getType
()

Get the Class reference for the actual annotation type.

public Optional<Object>

Returns:

an optional value or Optional#empty() if there is no matching attribute
getValue
(String
the attribute name
attributeName
)

Get an optional attribute value from the annotation.

public <T> Optional<T>

Returns:

an optional value or Optional#empty() if there is no matching attribute
getValue
(String
the attribute name
attributeName
,
Class<T>
the attribute type. Must be compatible with the underlying attribute type or Object.class.
type
)

Get an optional attribute value from the annotation.

public boolean

Returns:

true if the attribute value is the same as the default value
hasDefaultValue
(String
the attribute name
attributeName
)

Determine if the specified attribute name has a default value when compared to the annotation declaration.

public boolean

Returns:

true if the attribute value is different from the default value
hasNonDefaultValue
(String
the attribute name
attributeName
)

Determine if the specified attribute name has a non-default value when compared to the annotation declaration.

public boolean

Returns:

true if the annotation is directly present
isDirectlyPresent
()

Determine if the annotation is directly present on the source.

public boolean

Returns:

true if the annotation is meta-present
isMetaPresent
()

Determine if the annotation is meta-present on the source.

public boolean

Returns:

true if the annotation is present
isPresent
()

Determine if the annotation is present on the source.

public static <A extends Annotation> MergedAnnotation<A>

Returns:

an instance representing a missing annotation
missing
()

Create a MergedAnnotation that represents a missing annotation (i.e. one that is not present).

public static <A extends Annotation> MergedAnnotation<A>

Returns:

a MergedAnnotation instance for the annotation
of
(Class<A>
the annotation type
annotationType
)

Create a new MergedAnnotation instance of the specified annotation type.

public static <A extends Annotation> MergedAnnotation<A>

Returns:

a MergedAnnotation instance for the annotation and attributes
of
(Class<A>
the annotation type
annotationType
,
Map<String, ?>
the annotation attributes or null if just default values should be used
attributes
)

Create a new MergedAnnotation instance of the specified annotation type with attribute values supplied by a map.

public static <A extends Annotation> MergedAnnotation<A>

Returns:

a MergedAnnotation instance for the annotation and attributes
of
(AnnotatedElement
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.
source
,
Class<A>
the annotation type
annotationType
,
Map<String, ?>
the annotation attributes or null if just default values should be used
attributes
)

Create a new MergedAnnotation instance of the specified annotation type with attribute values supplied by a map.

public static <A extends Annotation> MergedAnnotation<A>

Returns:

a MergedAnnotation instance for the annotation and attributes
of
(ClassLoader
the class loader used to resolve class attributes
classLoader
,
Object
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.
source
,
Class<A>
the annotation type
annotationType
,
Map<String, ?>
the annotation attributes or null if just default values should be used
attributes
)

Create a new MergedAnnotation instance of the specified annotation type with attribute values supplied by a map.

public A

Returns:

a synthesized version of the annotation or the original annotation unmodified
synthesize
()

Create a type-safe synthesized version of this merged annotation that can be used directly in code.

public Optional<A>

Returns:

an optional containing the synthesized version of the annotation or an empty optional if the condition doesn't match
synthesize
(Predicate<? super MergedAnnotation<A>>
the test to determine if the annotation can be synthesized
condition
)

Optionally create a type-safe synthesized version of this annotation based on a condition predicate.

public MergedAnnotation<A>

Returns:

a non-merged view of the annotation
withNonMergedAttributes
()

Create a new view of the annotation that exposes non-merged attribute values.