public interface AnnotationSource
A source of annotations. This API provides an alternative to Java's AnnotatedElement
that uses the compile time produced data
from Micronaut. This is the parent interface of the AnnotationMetadata
which provides event more methods to read annotations values and compute Repeatable
annotations.
Note that this interface also includes methods such as synthesize(Class)
that allows materializing an instance of an annotation by producing a runtime proxy. These methods are a last resort if no other option is possible and should generally be avoided as they require the use of runtime reflection and proxying which hurts performance and memory consumption.
AnnotationMetadata
Modifier and Type | Field and Description |
---|---|
static AnnotationSource |
EMPTY
An empty annotation source.
|
Modifier and Type | Method and Description |
---|---|
default <T extends Annotation> |
findAnnotation(Class<T> annotation)
Find an
AnnotationValue for the given annotation type. |
default <T extends Annotation> |
findAnnotation(String annotation)
Find an
AnnotationValue for the given annotation name. |
default <T extends Annotation> |
findDeclaredAnnotation(Class<T> annotation)
Get all of the values for the given annotation that are directly declared on the annotated element.
|
default <T extends Annotation> |
findDeclaredAnnotation(String annotation)
Get all of the values for the given annotation that are directly declared on the annotated element.
|
default <T extends Annotation> |
getAnnotation(Class<T> annotation)
Find an
AnnotationValue for the given annotation name. |
default <T extends Annotation> |
getAnnotation(String annotation)
Find an
AnnotationValue for the given annotation name. |
default <T extends Annotation> |
getDeclaredAnnotation(Class<T> annotation)
Find an
AnnotationValue for the given annotation name. |
default <T extends Annotation> |
getDeclaredAnnotation(String annotation)
Get all of the values for the given annotation that are directly declared on the annotated element.
|
default boolean |
isAnnotationPresent(Class<? extends Annotation> annotationClass)
Return whether an annotation is present.
|
default boolean |
isDeclaredAnnotationPresent(Class<? extends Annotation> annotationClass)
Variation of
isAnnotationPresent(Class) for declared annotations. |
default <T extends Annotation> |
synthesize(Class<T> annotationClass)
Synthesizes a new annotation from the metadata for the given annotation type.
|
default Annotation[] |
synthesizeAll()
Synthesizes a new annotations from the metadata.
|
default <T extends Annotation> |
synthesizeAnnotationsByType(Class<T> annotationClass)
Synthesizes a new annotations from the metadata for the given type.
|
default Annotation[] |
synthesizeDeclared()
Synthesizes a new annotations from the metadata.
|
default <T extends Annotation> |
synthesizeDeclared(Class<T> annotationClass)
Synthesizes a new annotation from the metadata for the given annotation type.
|
default <T extends Annotation> |
synthesizeDeclaredAnnotationsByType(Class<T> annotationClass)
Synthesizes a new annotations from the metadata for the given type.
|
static final AnnotationSource EMPTY
default <T extends Annotation> T synthesize(Class<T> annotationClass)
T
- The annotation generic typeannotationClass
- The annotation classdefault <T extends Annotation> T synthesizeDeclared(Class<T> annotationClass)
This method ignores inherited annotations. (Returns null if no annotations are directly present on this element.)
T
- The annotation generic typeannotationClass
- The annotation classdefault Annotation[] synthesizeAll()
default Annotation[] synthesizeDeclared()
default <T extends Annotation> T[] synthesizeAnnotationsByType(Class<T> annotationClass)
T
- The annotation generic typeannotationClass
- The annotation typedefault <T extends Annotation> T[] synthesizeDeclaredAnnotationsByType(Class<T> annotationClass)
T
- The annotation generic typeannotationClass
- The annotation typedefault <T extends Annotation> Optional<AnnotationValue<T>> findAnnotation(String annotation)
AnnotationValue
for the given annotation name.T
- The annotation typeannotation
- The annotation nameAnnotationValue
instancedefault <T extends Annotation> Optional<AnnotationValue<T>> findAnnotation(Class<T> annotation)
AnnotationValue
for the given annotation type.T
- The annotation typeannotation
- The annotationAnnotationValue
instancedefault <T extends Annotation> Optional<AnnotationValue<T>> findDeclaredAnnotation(String annotation)
T
- The annotation typeannotation
- The annotation nameAnnotationValue
instancedefault <T extends Annotation> Optional<AnnotationValue<T>> findDeclaredAnnotation(Class<T> annotation)
T
- The annotation typeannotation
- The annotation nameAnnotationValue
instance@Nullable default <T extends Annotation> AnnotationValue<T> getAnnotation(String annotation)
AnnotationValue
for the given annotation name.T
- The annotation typeannotation
- The annotation nameAnnotationValue
instance or null@Nullable default <T extends Annotation> AnnotationValue<T> getAnnotation(Class<T> annotation)
AnnotationValue
for the given annotation name.T
- The annotation typeannotation
- The annotation nameAnnotationValue
instance or null@Nullable default <T extends Annotation> AnnotationValue<T> getDeclaredAnnotation(String annotation)
T
- The annotation typeannotation
- The annotation nameAnnotationValue
instance@Nullable default <T extends Annotation> AnnotationValue<T> getDeclaredAnnotation(Class<T> annotation)
AnnotationValue
for the given annotation name.T
- The annotation typeannotation
- The annotation nameAnnotationValue
instance or nulldefault boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
annotationClass
- The annotation classdefault boolean isDeclaredAnnotationPresent(Class<? extends Annotation> annotationClass)
isAnnotationPresent(Class)
for declared annotations.annotationClass
- The annotation class