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 java.lang.annotation.Annotation> |
findAnnotation(java.lang.Class<T> annotationClass)
Find an
AnnotationValue for the given annotation type. |
default <T extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.String annotation)
Find an
AnnotationValue for the given annotation name. |
default <T extends java.lang.annotation.Annotation> |
findDeclaredAnnotation(java.lang.Class<T> annotationClass)
Get all of the values for the given annotation that are directly declared on the annotated element.
|
default <T extends java.lang.annotation.Annotation> |
findDeclaredAnnotation(java.lang.String annotation)
Get all of the values for the given annotation that are directly declared on the annotated element.
|
default <T extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.Class<T> annotationClass)
Find an
AnnotationValue for the given annotation name. |
default <T extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.String annotation)
Find an
AnnotationValue for the given annotation name. |
default <T extends java.lang.annotation.Annotation> |
getDeclaredAnnotation(java.lang.Class<T> annotationClass)
Find an
AnnotationValue for the given annotation name. |
default <T extends java.lang.annotation.Annotation> |
getDeclaredAnnotation(java.lang.String annotation)
Get all of the values for the given annotation that are directly declared on the annotated element.
|
default boolean |
isAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Return whether an annotation is present.
|
default boolean |
isDeclaredAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Variation of
isAnnotationPresent(Class) for declared annotations. |
default <T extends java.lang.annotation.Annotation> |
synthesize(java.lang.Class<T> annotationClass)
Synthesizes a new annotation from the metadata for the given annotation type.
|
default java.lang.annotation.Annotation[] |
synthesizeAll()
Synthesizes a new annotations from the metadata.
|
default <T extends java.lang.annotation.Annotation> |
synthesizeAnnotationsByType(java.lang.Class<T> annotationClass)
Synthesizes a new annotations from the metadata for the given type.
|
default java.lang.annotation.Annotation[] |
synthesizeDeclared()
Synthesizes a new annotations from the metadata.
|
default <T extends java.lang.annotation.Annotation> |
synthesizeDeclared(java.lang.Class<T> annotationClass)
Synthesizes a new annotation from the metadata for the given annotation type.
|
default <T extends java.lang.annotation.Annotation> |
synthesizeDeclaredAnnotationsByType(java.lang.Class<T> annotationClass)
Synthesizes a new annotations from the metadata for the given type.
|
static final AnnotationSource EMPTY
@Nullable
default <T extends java.lang.annotation.Annotation> T synthesize(@NonNull
java.lang.Class<T> annotationClass)
T - The annotation generic typeannotationClass - The annotation class@Nullable
default <T extends java.lang.annotation.Annotation> T synthesizeDeclared(@NonNull
java.lang.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 class@NonNull default java.lang.annotation.Annotation[] synthesizeAll()
@NonNull default java.lang.annotation.Annotation[] synthesizeDeclared()
@NonNull
default <T extends java.lang.annotation.Annotation> T[] synthesizeAnnotationsByType(@NonNull
java.lang.Class<T> annotationClass)
T - The annotation generic typeannotationClass - The annotation type@NonNull
default <T extends java.lang.annotation.Annotation> T[] synthesizeDeclaredAnnotationsByType(@NonNull
java.lang.Class<T> annotationClass)
T - The annotation generic typeannotationClass - The annotation type@NonNull default <T extends java.lang.annotation.Annotation> java.util.Optional<AnnotationValue<T>> findAnnotation(@NonNull java.lang.String annotation)
AnnotationValue for the given annotation name.T - The annotation typeannotation - The annotation nameAnnotationValue instance@NonNull default <T extends java.lang.annotation.Annotation> java.util.Optional<AnnotationValue<T>> findAnnotation(@NonNull java.lang.Class<T> annotationClass)
AnnotationValue for the given annotation type.T - The annotation typeannotationClass - The annotationAnnotationValue instance@NonNull default <T extends java.lang.annotation.Annotation> java.util.Optional<AnnotationValue<T>> findDeclaredAnnotation(@NonNull java.lang.String annotation)
T - The annotation typeannotation - The annotation nameAnnotationValue instance@NonNull default <T extends java.lang.annotation.Annotation> java.util.Optional<AnnotationValue<T>> findDeclaredAnnotation(@NonNull java.lang.Class<T> annotationClass)
T - The annotation typeannotationClass - The annotation nameAnnotationValue instance@Nullable default <T extends java.lang.annotation.Annotation> AnnotationValue<T> getAnnotation(@NonNull java.lang.String annotation)
AnnotationValue for the given annotation name.T - The annotation typeannotation - The annotation nameAnnotationValue instance or null@Nullable default <T extends java.lang.annotation.Annotation> AnnotationValue<T> getAnnotation(@NonNull java.lang.Class<T> annotationClass)
AnnotationValue for the given annotation name.T - The annotation typeannotationClass - The annotation nameAnnotationValue instance or null@Nullable default <T extends java.lang.annotation.Annotation> AnnotationValue<T> getDeclaredAnnotation(@NonNull java.lang.String annotation)
T - The annotation typeannotation - The annotation nameAnnotationValue instance@Nullable default <T extends java.lang.annotation.Annotation> AnnotationValue<T> getDeclaredAnnotation(@NonNull java.lang.Class<T> annotationClass)
AnnotationValue for the given annotation name.T - The annotation typeannotationClass - The annotation nameAnnotationValue instance or nulldefault boolean isAnnotationPresent(@NonNull
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
annotationClass - The annotation classdefault boolean isDeclaredAnnotationPresent(@NonNull
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
isAnnotationPresent(Class) for declared annotations.annotationClass - The annotation class