A
- the annotation typepublic interface MergedAnnotation<A extends java.lang.annotation.Annotation>
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
.
MergedAnnotations
,
MergedAnnotationPredicates
Modifier and Type | Interface and Description |
---|---|
static class |
MergedAnnotation.Adapt
Adaptations that can be applied to attributes values when creating
Maps or
AnnotationAttributes . |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
VALUE
The attribute name for annotations with a single element.
|
Modifier and Type | Method and Description |
---|---|
AnnotationAttributes |
asAnnotationAttributes(MergedAnnotation.Adapt... adaptations)
Create a new mutable
AnnotationAttributes instance from this
merged annotation. |
<T extends java.util.Map<java.lang.String,java.lang.Object>> |
asMap(java.util.function.Function<MergedAnnotation<?>,T> factory,
MergedAnnotation.Adapt... adaptations)
Create a new
Map instance of the given type that contains all the annotation
attributes. |
java.util.Map<java.lang.String,java.lang.Object> |
asMap(MergedAnnotation.Adapt... adaptations)
Return an immutable
Map that contains all the annotation attributes. |
MergedAnnotation<A> |
filterAttributes(java.util.function.Predicate<java.lang.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 java.lang.annotation.Annotation> |
from(A annotation)
Create a new
MergedAnnotation instance from the specified
annotation. |
static <A extends java.lang.annotation.Annotation> |
from(java.lang.reflect.AnnotatedElement source,
java.lang.Class<A> annotationType,
java.util.Map<java.lang.String,?> attributes)
Create a new
MergedAnnotation instance from the specified
annotation type and attributes map. |
static <A extends java.lang.annotation.Annotation> |
from(java.lang.Class<A> annotationType)
Create a new
MergedAnnotation instance from the specified
annotation type. |
static <A extends java.lang.annotation.Annotation> |
from(java.lang.Class<A> annotationType,
java.util.Map<java.lang.String,?> attributes)
Create a new
MergedAnnotation instance from the specified
annotation type and attributes map. |
static <A extends java.lang.annotation.Annotation> |
from(java.lang.Object source,
A annotation)
Create a new
MergedAnnotation instance from the specified
annotation. |
int |
getAggregateIndex()
Get the index of the aggregate collection containing this annotation.
|
<T extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.String attributeName,
java.lang.Class<T> type)
Get a required annotation attribute value from the annotation.
|
<T extends java.lang.annotation.Annotation> |
getAnnotationArray(java.lang.String attributeName,
java.lang.Class<T> type)
Get a required annotation array attribute value from the annotation.
|
boolean |
getBoolean(java.lang.String attributeName)
Get a required boolean attribute value from the annotation.
|
boolean[] |
getBooleanArray(java.lang.String attributeName)
Get a required boolean array attribute value from the annotation.
|
byte |
getByte(java.lang.String attributeName)
Get a required byte attribute value from the annotation.
|
byte[] |
getByteArray(java.lang.String attributeName)
Get a required byte array attribute value from the annotation.
|
char |
getChar(java.lang.String attributeName)
Get a required char attribute value from the annotation.
|
char[] |
getCharArray(java.lang.String attributeName)
Get a required char array attribute value from the annotation.
|
java.lang.Class<?> |
getClass(java.lang.String attributeName)
Get a required class attribute value from the annotation.
|
java.lang.Class<?>[] |
getClassArray(java.lang.String attributeName)
Get a required class array attribute value from the annotation.
|
java.util.Optional<java.lang.Object> |
getDefaultValue(java.lang.String attributeName)
Get the default attribute value from the annotation as specified in
the annotation declaration.
|
<T> java.util.Optional<T> |
getDefaultValue(java.lang.String attributeName,
java.lang.Class<T> type)
Get the default attribute value from the annotation as specified in
the annotation declaration.
|
int |
getDepth()
Get the depth of this annotation related to its use as a
meta-annotation.
|
double |
getDouble(java.lang.String attributeName)
Get a required double attribute value from the annotation.
|
double[] |
getDoubleArray(java.lang.String attributeName)
Get a required double array attribute value from the annotation.
|
<E extends java.lang.Enum<E>> |
getEnum(java.lang.String attributeName,
java.lang.Class<E> type)
Get a required enum attribute value from the annotation.
|
<E extends java.lang.Enum<E>> |
getEnumArray(java.lang.String attributeName,
java.lang.Class<E> type)
Get a required enum array attribute value from the annotation.
|
float |
getFloat(java.lang.String attributeName)
Get a required float attribute value from the annotation.
|
float[] |
getFloatArray(java.lang.String attributeName)
Get a required float array attribute value from the annotation.
|
int |
getInt(java.lang.String attributeName)
Get a required int attribute value from the annotation.
|
int[] |
getIntArray(java.lang.String attributeName)
Get a required int array attribute value from the annotation.
|
long |
getLong(java.lang.String attributeName)
Get a required long attribute value from the annotation.
|
long[] |
getLongArray(java.lang.String attributeName)
Get a required long array attribute value from the annotation.
|
MergedAnnotation<?> |
getParent()
Get the parent of the meta-annotation, or
null if the
annotation is not meta-present. |
short |
getShort(java.lang.String attributeName)
Get a required short attribute value from the annotation.
|
short[] |
getShortArray(java.lang.String attributeName)
Get a required short array attribute value from the annotation.
|
java.lang.Object |
getSource()
Get the source that ultimately declared the annotation, or
null if the source is not known. |
java.lang.String |
getString(java.lang.String attributeName)
Get a required string attribute value from the annotation.
|
java.lang.String[] |
getStringArray(java.lang.String attributeName)
Get a required string array attribute value from the annotation.
|
java.lang.Class<A> |
getType()
Get the
Class reference for the actual annotation type. |
java.util.Optional<java.lang.Object> |
getValue(java.lang.String attributeName)
Get an optional attribute value from the annotation.
|
<T> java.util.Optional<T> |
getValue(java.lang.String attributeName,
java.lang.Class<T> type)
Get an optional attribute value from the annotation.
|
boolean |
hasDefaultValue(java.lang.String attributeName)
Determine if the specified attribute name has a default value when compared
to the annotation declaration.
|
boolean |
hasNonDefaultValue(java.lang.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 java.lang.annotation.Annotation> |
missing()
Create a
MergedAnnotation that represents a missing annotation
(i.e. |
A |
synthesize()
Create a type-safe synthesized version of this annotation that can be
used directly in code.
|
java.util.Optional<A> |
synthesize(java.util.function.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.
|
static final java.lang.String VALUE
java.lang.Class<A> getType()
Class
reference for the actual annotation type.boolean isPresent()
MergedAnnotations.SearchStrategy
used.true
if the annotation is presentboolean isDirectlyPresent()
@Inherited
.true
if the annotation is directly presentboolean isMetaPresent()
true
if the annotation is meta-presentint getDepth()
0
,
a meta-annotation has a depth of 1
, a meta-annotation on a
meta-annotation has a depth of 2
, etc. A missing annotation will always return a depth of -1
.-1
if the annotation is missingint getAggregateIndex()
-1
.0
) or -1
if the
annotation is missing@Nullable java.lang.Object getSource()
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 return the same source as the getParent()
.null
@Nullable MergedAnnotation<?> getParent()
null
if the
annotation is not meta-present.null
boolean hasNonDefaultValue(java.lang.String attributeName)
attributeName
- the attribute nametrue
if the attribute value is different from the default
valueboolean hasDefaultValue(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute nametrue
if the attribute value is the same as the default
valuejava.util.NoSuchElementException
byte getByte(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributebyte[] getByteArray(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributeboolean getBoolean(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributeboolean[] getBooleanArray(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributechar getChar(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributechar[] getCharArray(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributeshort getShort(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributeshort[] getShortArray(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributeint getInt(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributeint[] getIntArray(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributelong getLong(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributelong[] getLongArray(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributedouble getDouble(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributedouble[] getDoubleArray(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributefloat getFloat(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributefloat[] getFloatArray(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributejava.lang.String getString(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributejava.lang.String[] getStringArray(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributejava.lang.Class<?> getClass(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attributejava.lang.Class<?>[] getClassArray(java.lang.String attributeName) throws java.util.NoSuchElementException
attributeName
- the attribute namejava.util.NoSuchElementException
- if there is no matching attribute<E extends java.lang.Enum<E>> E getEnum(java.lang.String attributeName, java.lang.Class<E> type) throws java.util.NoSuchElementException
attributeName
- the attribute nametype
- the enum typejava.util.NoSuchElementException
- if there is no matching attribute<E extends java.lang.Enum<E>> E[] getEnumArray(java.lang.String attributeName, java.lang.Class<E> type) throws java.util.NoSuchElementException
attributeName
- the attribute nametype
- the enum typejava.util.NoSuchElementException
- if there is no matching attribute<T extends java.lang.annotation.Annotation> MergedAnnotation<T> getAnnotation(java.lang.String attributeName, java.lang.Class<T> type) throws java.util.NoSuchElementException
attributeName
- the attribute nametype
- the annotation typeMergedAnnotation
java.util.NoSuchElementException
- if there is no matching attribute<T extends java.lang.annotation.Annotation> MergedAnnotation<T>[] getAnnotationArray(java.lang.String attributeName, java.lang.Class<T> type) throws java.util.NoSuchElementException
attributeName
- the attribute nametype
- the annotation typeMergedAnnotation
arrayjava.util.NoSuchElementException
- if there is no matching attributejava.util.Optional<java.lang.Object> getValue(java.lang.String attributeName)
attributeName
- the attribute nameOptional.empty()
if there is no
matching attribute<T> java.util.Optional<T> getValue(java.lang.String attributeName, java.lang.Class<T> type)
attributeName
- the attribute nametype
- the attribute type. Must be compatible with the underlying
attribute type or Object.class
.Optional.empty()
if there is no
matching attributejava.util.Optional<java.lang.Object> getDefaultValue(java.lang.String attributeName)
attributeName
- the attribute nameOptional.empty()
if
there is no matching attribute or no defined default<T> java.util.Optional<T> getDefaultValue(java.lang.String attributeName, java.lang.Class<T> type)
attributeName
- the attribute nametype
- the attribute type. Must be compatible with the underlying
attribute type or Object.class
.Optional.empty()
if
there is no matching attribute or no defined defaultMergedAnnotation<A> filterDefaultValues()
filterAttributes(Predicate)
MergedAnnotation<A> filterAttributes(java.util.function.Predicate<java.lang.String> predicate)
predicate
- a predicate used to filter attribute namesfilterDefaultValues()
,
MergedAnnotationPredicates
MergedAnnotation<A> withNonMergedAttributes()
Methods from this view will return attribute values with only alias mirroring rules applied. Aliases to parent attributes will not be applied.
AnnotationAttributes asAnnotationAttributes(MergedAnnotation.Adapt... adaptations)
AnnotationAttributes
instance from this
merged annotation.
The adaptations
may be used to change the way that values
are added.
adaptations
- adaptations that should be applied to the annotation valuesjava.util.Map<java.lang.String,java.lang.Object> asMap(MergedAnnotation.Adapt... adaptations)
Map
that contains all the annotation attributes.
The adaptations
may be used to change the way that values are added.
adaptations
- adaptations that should be applied to the annotation values<T extends java.util.Map<java.lang.String,java.lang.Object>> T asMap(java.util.function.Function<MergedAnnotation<?>,T> factory, MergedAnnotation.Adapt... adaptations)
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 factoryadaptations
- adaptations that should be applied to the annotation valuesA synthesize() throws java.util.NoSuchElementException
The result is synthesized using a JDK Proxy
and as a result may
incur a computational cost when first invoked.
java.util.NoSuchElementException
- on a missing annotationjava.util.Optional<A> synthesize(java.util.function.Predicate<? super MergedAnnotation<A>> condition) throws java.util.NoSuchElementException
The result is synthesized using a JDK Proxy
and as a result may
incur a computational cost when first invoked.
condition
- the test to determine if the annotation can be synthesizedjava.util.NoSuchElementException
- on a missing annotationMergedAnnotationPredicates
static <A extends java.lang.annotation.Annotation> MergedAnnotation<A> missing()
MergedAnnotation
that represents a missing annotation
(i.e. one that is not present).static <A extends java.lang.annotation.Annotation> MergedAnnotation<A> from(A annotation)
MergedAnnotation
instance from the specified
annotation.annotation
- the annotation to includeMergedAnnotation
instance containing the annotationstatic <A extends java.lang.annotation.Annotation> MergedAnnotation<A> from(@Nullable java.lang.Object source, A annotation)
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 includeMergedAnnotation
instance for the annotationstatic <A extends java.lang.annotation.Annotation> MergedAnnotation<A> from(java.lang.Class<A> annotationType)
MergedAnnotation
instance from 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 typeMergedAnnotation
instance for the annotationstatic <A extends java.lang.annotation.Annotation> MergedAnnotation<A> from(java.lang.Class<A> annotationType, @Nullable java.util.Map<java.lang.String,?> attributes)
MergedAnnotation
instance from the specified
annotation type and attributes map.annotationType
- the annotation typeattributes
- the annotation attributes or null
if just default
values should be usedMergedAnnotation
instance for the annotation and attributesfrom(AnnotatedElement, Class, Map)
static <A extends java.lang.annotation.Annotation> MergedAnnotation<A> from(@Nullable java.lang.reflect.AnnotatedElement source, java.lang.Class<A> annotationType, @Nullable java.util.Map<java.lang.String,?> attributes)
MergedAnnotation
instance from the specified
annotation type and attributes 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 or null
if just default
values should be usedMergedAnnotation
instance for the annotation and attributes