Interface AnnotationSource
-
- All Known Subinterfaces:
AnnotatedElement
,AnnotationMetadata
,AnnotationMetadataDelegate
,AnnotationMetadataProvider
,Argument<T>
,ArgumentConversionContext<T>
,ArgumentValue<V>
,BeanConstructor<T>
,BeanIntrospection<T>
,BeanIntrospectionReference<T>
,BeanMethod<B,T>
,BeanProperty<B,T>
,BeanWrapper<T>
,BoundExecutable<T,R>
,ConversionContext
,Executable<T,R>
,GenericPlaceholder<T>
,GraalReflectionConfigurer
,ImmutableArgumentConversionContext<T>
,MutableArgumentValue<V>
,ReturnType<T>
,TypeInformation<T>
,UnsafeBeanProperty<B,T>
- All Known Implementing Classes:
AbstractBeanConstructor
,AbstractBeanIntrospection
,AbstractBeanIntrospectionReference
,AbstractBeanMethod
,AbstractBeanProperty
,DefaultArgument
,GenericArgument
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 theAnnotationMetadata
which provides event more methods to read annotations values and computeRepeatable
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.- Since:
- 1.0
- See Also:
AnnotationMetadata
-
-
Field Summary
Fields Modifier and Type Field Description static AnnotationSource
EMPTY
An empty annotation source.
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default <T extends java.lang.annotation.Annotation>
java.util.Optional<AnnotationValue<T>>findAnnotation(java.lang.Class<T> annotationClass)
Find anAnnotationValue
for the given annotation type.default <T extends java.lang.annotation.Annotation>
java.util.Optional<AnnotationValue<T>>findAnnotation(java.lang.String annotation)
Find anAnnotationValue
for the given annotation name.default <T extends java.lang.annotation.Annotation>
java.util.Optional<AnnotationValue<T>>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>
java.util.Optional<AnnotationValue<T>>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>
AnnotationValue<T>getAnnotation(java.lang.Class<T> annotationClass)
Find anAnnotationValue
for the given annotation name.default <T extends java.lang.annotation.Annotation>
AnnotationValue<T>getAnnotation(java.lang.String annotation)
Find anAnnotationValue
for the given annotation name.default <T extends java.lang.annotation.Annotation>
AnnotationValue<T>getDeclaredAnnotation(java.lang.Class<T> annotationClass)
Find anAnnotationValue
for the given annotation name.default <T extends java.lang.annotation.Annotation>
AnnotationValue<T>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
isAnnotationPresent(java.lang.String annotationName)
Return whether an annotation is present.default boolean
isDeclaredAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Variation ofisAnnotationPresent(Class)
for declared annotations.default boolean
isDeclaredAnnotationPresent(java.lang.String annotationName)
Variation ofisAnnotationPresent(String)
for declared annotations.default <T extends java.lang.annotation.Annotation>
Tsynthesize(java.lang.Class<T> annotationClass)
Synthesizes a new annotation from the metadata for the given annotation type.default <T extends java.lang.annotation.Annotation>
Tsynthesize(java.lang.Class<T> annotationClass, java.lang.String sourceAnnotation)
Synthesizes a new annotation for the given annotation type using the member values of the given source annotation.default java.lang.annotation.Annotation[]
synthesizeAll()
Synthesizes a new annotations from the metadata.default <T extends java.lang.annotation.Annotation>
T[]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>
TsynthesizeDeclared(java.lang.Class<T> annotationClass)
Synthesizes a new annotation from the metadata for the given annotation type.default <T extends java.lang.annotation.Annotation>
TsynthesizeDeclared(java.lang.Class<T> annotationClass, java.lang.String sourceAnnotation)
Synthesizes a new annotation declared for the given annotation type using the member values of the given source annotation.default <T extends java.lang.annotation.Annotation>
T[]synthesizeDeclaredAnnotationsByType(java.lang.Class<T> annotationClass)
Synthesizes a new annotations from the metadata for the given type.
-
-
-
Field Detail
-
EMPTY
static final AnnotationSource EMPTY
An empty annotation source.
-
-
Method Detail
-
synthesize
@Nullable default <T extends java.lang.annotation.Annotation> T synthesize(@NonNull java.lang.Class<T> annotationClass)
Synthesizes a new annotation from the metadata for the given annotation type. This method works by creating a runtime proxy of the annotation interface and should be avoided in favour of direct use of the annotation metadata and only used for unique cases that require integrating third party libraries.- Type Parameters:
T
- The annotation generic type- Parameters:
annotationClass
- The annotation class- Returns:
- The annotation or null if it doesn't exist
-
synthesize
@Nullable default <T extends java.lang.annotation.Annotation> T synthesize(@NonNull java.lang.Class<T> annotationClass, @NonNull java.lang.String sourceAnnotation)
Synthesizes a new annotation for the given annotation type using the member values of the given source annotation.This method allows supporting synthesizing annotations that have been renamed, for example a
jakarta.inject.Named
annotation an be synthesized from the metadata of the ajavax.inject.Named
annotation.- Type Parameters:
T
- The annotation generic type- Parameters:
annotationClass
- The annotation classsourceAnnotation
- The source annotation that provides the member values- Returns:
- The annotation or null if it doesn't exist
- Since:
- 3.0.0
-
synthesizeDeclared
@Nullable default <T extends java.lang.annotation.Annotation> T synthesizeDeclared(@NonNull java.lang.Class<T> annotationClass, @NonNull java.lang.String sourceAnnotation)
Synthesizes a new annotation declared for the given annotation type using the member values of the given source annotation.This method allows supporting synthesizing annotations that have been renamed, for example a
jakarta.inject.Named
annotation an be synthesized from the metadata of the ajavax.inject.Named
annotation.- Type Parameters:
T
- The annotation generic type- Parameters:
annotationClass
- The annotation classsourceAnnotation
- The source annotation that provides the member values- Returns:
- The annotation or null if it doesn't exist
- Since:
- 3.0.0
-
synthesizeDeclared
@Nullable default <T extends java.lang.annotation.Annotation> T synthesizeDeclared(@NonNull java.lang.Class<T> annotationClass)
Synthesizes a new annotation from the metadata for the given annotation type. This method works by creating a runtime proxy of the annotation interface and should be avoided in favour of direct use of the annotation metadata and only used for unique cases that require integrating third party libraries.This method ignores inherited annotations. (Returns null if no annotations are directly present on this element.)
- Type Parameters:
T
- The annotation generic type- Parameters:
annotationClass
- The annotation class- Returns:
- The annotation or null if it doesn't exist
-
synthesizeAll
@NonNull default java.lang.annotation.Annotation[] synthesizeAll()
Synthesizes a new annotations from the metadata. This method works by creating a runtime proxy of the annotation interface and should be avoided in favour of direct use of the annotation metadata and only used for unique cases that require integrating third party libraries.- Returns:
- All the annotations
-
synthesizeDeclared
@NonNull default java.lang.annotation.Annotation[] synthesizeDeclared()
Synthesizes a new annotations from the metadata. This method works by creating a runtime proxy of the annotation interface and should be avoided in favour of direct use of the annotation metadata and only used for unique cases that require integrating third party libraries.- Returns:
- All declared annotations
-
synthesizeAnnotationsByType
@NonNull default <T extends java.lang.annotation.Annotation> T[] synthesizeAnnotationsByType(@NonNull java.lang.Class<T> annotationClass)
Synthesizes a new annotations from the metadata for the given type. This method works by creating a runtime proxy of the annotation interface and should be avoided in favour of direct use of the annotation metadata and only used for unique cases that require integrating third party libraries.- Type Parameters:
T
- The annotation generic type- Parameters:
annotationClass
- The annotation type- Returns:
- All annotations by the given type
-
synthesizeDeclaredAnnotationsByType
@NonNull default <T extends java.lang.annotation.Annotation> T[] synthesizeDeclaredAnnotationsByType(@NonNull java.lang.Class<T> annotationClass)
Synthesizes a new annotations from the metadata for the given type. This method works by creating a runtime proxy of the annotation interface and should be avoided in favour of direct use of the annotation metadata and only used for unique cases that require integrating third party libraries.- Type Parameters:
T
- The annotation generic type- Parameters:
annotationClass
- The annotation type- Returns:
- Declared annotations by the given type
-
findAnnotation
@NonNull default <T extends java.lang.annotation.Annotation> java.util.Optional<AnnotationValue<T>> findAnnotation(@NonNull java.lang.String annotation)
Find anAnnotationValue
for the given annotation name.- Type Parameters:
T
- The annotation type- Parameters:
annotation
- The annotation name- Returns:
- A
AnnotationValue
instance
-
findAnnotation
@NonNull default <T extends java.lang.annotation.Annotation> java.util.Optional<AnnotationValue<T>> findAnnotation(@NonNull java.lang.Class<T> annotationClass)
Find anAnnotationValue
for the given annotation type.- Type Parameters:
T
- The annotation type- Parameters:
annotationClass
- The annotation- Returns:
- A
AnnotationValue
instance
-
findDeclaredAnnotation
@NonNull default <T extends java.lang.annotation.Annotation> java.util.Optional<AnnotationValue<T>> findDeclaredAnnotation(@NonNull java.lang.String annotation)
Get all of the values for the given annotation that are directly declared on the annotated element.- Type Parameters:
T
- The annotation type- Parameters:
annotation
- The annotation name- Returns:
- A
AnnotationValue
instance
-
findDeclaredAnnotation
@NonNull default <T extends java.lang.annotation.Annotation> java.util.Optional<AnnotationValue<T>> findDeclaredAnnotation(@NonNull java.lang.Class<T> annotationClass)
Get all of the values for the given annotation that are directly declared on the annotated element.- Type Parameters:
T
- The annotation type- Parameters:
annotationClass
- The annotation name- Returns:
- A
AnnotationValue
instance
-
getAnnotation
@Nullable default <T extends java.lang.annotation.Annotation> AnnotationValue<T> getAnnotation(@NonNull java.lang.String annotation)
Find anAnnotationValue
for the given annotation name.- Type Parameters:
T
- The annotation type- Parameters:
annotation
- The annotation name- Returns:
- A
AnnotationValue
instance or null
-
getAnnotation
@Nullable default <T extends java.lang.annotation.Annotation> AnnotationValue<T> getAnnotation(@NonNull java.lang.Class<T> annotationClass)
Find anAnnotationValue
for the given annotation name.- Type Parameters:
T
- The annotation type- Parameters:
annotationClass
- The annotation name- Returns:
- A
AnnotationValue
instance or null
-
getDeclaredAnnotation
@Nullable default <T extends java.lang.annotation.Annotation> AnnotationValue<T> getDeclaredAnnotation(@NonNull java.lang.String annotation)
Get all of the values for the given annotation that are directly declared on the annotated element.- Type Parameters:
T
- The annotation type- Parameters:
annotation
- The annotation name- Returns:
- A
AnnotationValue
instance
-
getDeclaredAnnotation
@Nullable default <T extends java.lang.annotation.Annotation> AnnotationValue<T> getDeclaredAnnotation(@NonNull java.lang.Class<T> annotationClass)
Find anAnnotationValue
for the given annotation name.- Type Parameters:
T
- The annotation type- Parameters:
annotationClass
- The annotation name- Returns:
- A
AnnotationValue
instance or null
-
isAnnotationPresent
default boolean isAnnotationPresent(@NonNull java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Return whether an annotation is present.- Parameters:
annotationClass
- The annotation class- Returns:
- True if it is
-
isDeclaredAnnotationPresent
default boolean isDeclaredAnnotationPresent(@NonNull java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Variation ofisAnnotationPresent(Class)
for declared annotations.- Parameters:
annotationClass
- The annotation class- Returns:
- True if it is
-
isAnnotationPresent
default boolean isAnnotationPresent(@NonNull java.lang.String annotationName)
Return whether an annotation is present.- Parameters:
annotationName
- The annotation name- Returns:
- True if it is
-
isDeclaredAnnotationPresent
default boolean isDeclaredAnnotationPresent(@NonNull java.lang.String annotationName)
Variation ofisAnnotationPresent(String)
for declared annotations.- Parameters:
annotationName
- The annotation name- Returns:
- True if it is
-
-