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> annotationClass)
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> annotationClass)
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> annotationClass)
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> annotationClass)
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
@Nullable default <T extends Annotation> T synthesize(@Nonnull Class<T> annotationClass)
T
- The annotation generic typeannotationClass
- The annotation class@Nullable default <T extends Annotation> T synthesizeDeclared(@Nonnull 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 Annotation[] synthesizeAll()
@Nonnull default Annotation[] synthesizeDeclared()
@Nonnull default <T extends Annotation> T[] synthesizeAnnotationsByType(@Nonnull Class<T> annotationClass)
T
- The annotation generic typeannotationClass
- The annotation type@Nonnull default <T extends Annotation> T[] synthesizeDeclaredAnnotationsByType(@Nonnull Class<T> annotationClass)
T
- The annotation generic typeannotationClass
- The annotation type@Nonnull default <T extends Annotation> Optional<AnnotationValue<T>> findAnnotation(@Nonnull String annotation)
AnnotationValue
for the given annotation name.T
- The annotation typeannotation
- The annotation nameAnnotationValue
instance@Nonnull default <T extends Annotation> Optional<AnnotationValue<T>> findAnnotation(@Nonnull Class<T> annotationClass)
AnnotationValue
for the given annotation type.T
- The annotation typeannotationClass
- The annotationAnnotationValue
instance@Nonnull default <T extends Annotation> Optional<AnnotationValue<T>> findDeclaredAnnotation(@Nonnull String annotation)
T
- The annotation typeannotation
- The annotation nameAnnotationValue
instance@Nonnull default <T extends Annotation> Optional<AnnotationValue<T>> findDeclaredAnnotation(@Nonnull Class<T> annotationClass)
T
- The annotation typeannotationClass
- The annotation nameAnnotationValue
instance@Nullable default <T extends Annotation> AnnotationValue<T> getAnnotation(@Nonnull 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(@Nonnull Class<T> annotationClass)
AnnotationValue
for the given annotation name.T
- The annotation typeannotationClass
- The annotation nameAnnotationValue
instance or null@Nullable default <T extends Annotation> AnnotationValue<T> getDeclaredAnnotation(@Nonnull String annotation)
T
- The annotation typeannotation
- The annotation nameAnnotationValue
instance@Nullable default <T extends Annotation> AnnotationValue<T> getDeclaredAnnotation(@Nonnull Class<T> annotationClass)
AnnotationValue
for the given annotation name.T
- The annotation typeannotationClass
- The annotation nameAnnotationValue
instance or nulldefault boolean isAnnotationPresent(@Nonnull Class<? extends Annotation> annotationClass)
annotationClass
- The annotation classdefault boolean isDeclaredAnnotationPresent(@Nonnull Class<? extends Annotation> annotationClass)
isAnnotationPresent(Class)
for declared annotations.annotationClass
- The annotation class