Interface AnnotationSource
- All Known Subinterfaces:
AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata
,AdvisedBeanType<T>
,AnnotatedElement
,AnnotationElement
,AnnotationMetadata
,AnnotationMetadataDelegate
,AnnotationMetadataProvider
,Argument<T>
,ArgumentConversionContext<T>
,ArgumentInjectionPoint<B,
,T> ArgumentValue<V>
,ArrayableClassElement
,BeanConfiguration
,BeanConstructor<T>
,BeanConstructorElement
,BeanDefinition<T>
,BeanDefinitionMethodReference<T,
,R> BeanDefinitionReference<T>
,BeanElement
,BeanElementBuilder
,BeanFieldElement
,BeanInfo<T>
,BeanIntrospection<T>
,BeanIntrospectionReference<T>
,BeanMethod<B,
,T> BeanMethodElement
,BeanParameterElement
,BeanProperty<B,
,T> BeanReadProperty<B,
,T> BeanType<T>
,BeanWrapper<T>
,BeanWriteProperty<B,
,T> BoundExecutable<T,
,R> CallableInjectionPoint<T>
,ClassElement
,ConfigurableElement
,ConstructorElement
,ConstructorInjectionPoint<T>
,ConstructorInvocationContext<T>
,ConversionContext
,DelegatingBeanDefinition<T>
,DelegatingExecutableMethod<T,
,R> DisposableBeanDefinition<T>
,Element
,ElementAnnotationMetadata
,ElementMutableAnnotationMetadataDelegate<R>
,EnumBeanIntrospection<E>
,EnumBeanIntrospection.EnumConstant<E>
,EnumConstantElement
,EnumElement
,ErrorRouteInfo<T,
,R> Executable<T,
,R> ExecutableMethod<T,
,R> ExecutionHandle<T,
,R> FieldElement
,FieldInjectionPoint<B,
,T> FilterRoute
,GenericElement
,GenericPlaceholder<T>
,GenericPlaceholderElement
,GraalReflectionConfigurer
,HttpFilterResolver.FilterEntry
,ImmutableArgumentConversionContext<T>
,InitializingBeanDefinition<T>
,InjectableBeanDefinition<T>
,InjectableElement
,InjectionPoint<T>
,InstantiatableBeanDefinition<T>
,InvocationContext<T,
,R> KotlinParameterElement
,MemberElement
,MethodBasedRouteInfo<T,
,R> MethodBasedRouteMatch<T,
,R> MethodElement
,MethodExecutionHandle<T,
,R> MethodInjectionPoint<B,
,T> MethodInvocationContext<T,
,R> MethodReference<T,
,R> MutableAnnotationMetadataDelegate<R>
,MutableArgumentValue<V>
,PackageElement
,ParameterElement
,ParametrizedInstantiatableBeanDefinition<T>
,PropertyElement
,ProxyBeanDefinition<T>
,QualifiedBeanType<T>
,ReturnType<T>
,RouteInfo<R>
,RouteMatch<R>
,RuntimeBeanDefinition<T>
,StatusRouteInfo<T,
,R> TypedElement
,TypeInformation<T>
,UnsafeBeanInstantiationIntrospection<T>
,UnsafeBeanProperty<B,
,T> UnsafeBeanReadProperty<B,
,T> UnsafeBeanWriteProperty<B,
,T> UnsafeExecutable<T,
,R> UnsafeExecutionHandle<T,
,R> UriRouteInfo<T,
,R> UriRouteMatch<T,
,R> ValidatedBeanDefinition<T>
,WildcardElement
- All Known Implementing Classes:
AbstractAnnotationElement
,AbstractBeanConfiguration
,AbstractBeanConstructor
,AbstractBeanDefinitionBeanConstructor
,AbstractBeanDefinitionBuilder
,AbstractBeanIntrospectionReference
,AbstractBeanMethod
,AbstractBeanProperty
,AbstractBeanResolutionContext.AnnotationSegment
,AbstractBeanResolutionContext.ConstructorArgumentSegment
,AbstractBeanResolutionContext.ConstructorSegment
,AbstractBeanResolutionContext.FieldSegment
,AbstractBeanResolutionContext.MethodArgumentSegment
,AbstractBeanResolutionContext.MethodSegment
,AbstractElementAnnotationMetadata
,AbstractElementAnnotationMetadataFactory.AbstractElementAnnotationMetadata
,AbstractElementAnnotationMetadataFactory.MutableElementAnnotationMetadata
,AbstractEnumBeanIntrospectionAndReference
,AbstractEnumBeanIntrospectionAndReference.EnumConstantDynamicRef
,AbstractEnumBeanIntrospectionAndReference.EnumConstantRef
,AbstractEnvironmentAnnotationMetadata
,AbstractExecutableBeanMethod
,AbstractExecutableMethod
,AbstractGroovyElement
,AbstractInitializableBeanDefinition
,AbstractInitializableBeanDefinitionAndReference
,AbstractInitializableBeanDefinitionReference
,AbstractInitializableBeanIntrospection
,AbstractInitializableBeanIntrospectionAndReference
,AbstractJavaElement
,AbstractMutableAnnotationMetadata
,AbstractProviderDefinition
,AnnotationMetadataHierarchy
,AnnotationMetadataReference
,ApplicationEventPublisherFactory
,ArgumentBeanType
,BeanDefinitionWriter
,BeanProviderDefinition
,BeanRegistration
,ClientFilterResolutionContext
,ConstructorInterceptorChain
,DefaultAnnotationMetadata
,DefaultArgument
,DefaultErrorRouteInfo
,DefaultRequestMatcher
,DefaultRouteInfo
,DefaultStatusRouteInfo
,DefaultUriRouteMatch
,DefaultUrlRouteInfo
,DisabledBean
,EvaluatedAnnotationMetadata
,GenericArgument
,GenericPlaceholderElementAnnotationMetadata
,GroovyClassElement
,GroovyConstructorElement
,GroovyEnumConstantElement
,GroovyFieldElement
,GroovyMethodElement
,GroovyPackageElement
,GroovyParameterElement
,InterceptorChain
,InterceptorRegistryBean
,JakartaProviderBeanDefinition
,JavaClassElement
,JavaMethodElement
,JavaPackageElement
,JavaxProviderBeanDefinition
,MappingAnnotationMetadataDelegate
,MethodElementAnnotationMetadata
,MethodInterceptorChain
,MutableAnnotationMetadata
,MutatedMethodElementAnnotationMetadata
,PrimitiveElement
,PropertyElementAnnotationMetadata
,WildcardElementAnnotationMetadata
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.
- Since:
- 1.0
- Author:
- Graeme Rocher
- See Also:
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T extends Annotation>
@NonNull Optional<AnnotationValue<T>>findAnnotation
(@NonNull Class<T> annotationClass) Find anAnnotationValue
for the given annotation type.default <T extends Annotation>
@NonNull Optional<AnnotationValue<T>>findAnnotation
(@NonNull String annotation) Find anAnnotationValue
for the given annotation name.default <T extends Annotation>
@NonNull Optional<AnnotationValue<T>>findDeclaredAnnotation
(@NonNull Class<T> annotationClass) Get all values for the given annotation that are directly declared on the annotated element.default <T extends Annotation>
@NonNull Optional<AnnotationValue<T>>findDeclaredAnnotation
(@NonNull String annotation) Get all values for the given annotation that are directly declared on the annotated element.default <T extends Annotation>
@Nullable AnnotationValue<T>getAnnotation
(@NonNull Class<T> annotationClass) Find anAnnotationValue
for the given annotation name.default <T extends Annotation>
@Nullable AnnotationValue<T>getAnnotation
(@NonNull String annotation) Find anAnnotationValue
for the given annotation name.default <T extends Annotation>
@Nullable AnnotationValue<T>getDeclaredAnnotation
(@NonNull Class<T> annotationClass) Find anAnnotationValue
for the given annotation name.default <T extends Annotation>
@Nullable AnnotationValue<T>getDeclaredAnnotation
(@NonNull String annotation) Get all values for the given annotation that are directly declared on the annotated element.default AnnotationSource
Unwraps possible delegate or provider.default boolean
isAnnotationPresent
(@NonNull Class<? extends Annotation> annotationClass) Return whether an annotation is present.default boolean
isAnnotationPresent
(@NonNull String annotationName) Return whether an annotation is present.default boolean
isDeclaredAnnotationPresent
(@NonNull Class<? extends Annotation> annotationClass) Variation ofisAnnotationPresent(Class)
for declared annotations.default boolean
isDeclaredAnnotationPresent
(@NonNull String annotationName) Variation ofisAnnotationPresent(String)
for declared annotations.default <T extends Annotation>
Tsynthesize
(@NonNull Class<T> annotationClass) Synthesizes a new annotation from the metadata for the given annotation type.default <T extends Annotation>
Tsynthesize
(@NonNull Class<T> annotationClass, @NonNull String sourceAnnotation) Synthesizes a new annotation for the given annotation type using the member values of the given source annotation.default @NonNull Annotation[]
Synthesizes a new annotations from the metadata.default <T extends Annotation>
@NonNull T[]synthesizeAnnotationsByType
(@NonNull Class<T> annotationClass) Synthesizes a new annotations from the metadata for the given type.default @NonNull Annotation[]
Synthesizes a new annotations from the metadata.default <T extends Annotation>
TsynthesizeDeclared
(@NonNull Class<T> annotationClass) Synthesizes a new annotation from the metadata for the given annotation type.default <T extends Annotation>
TsynthesizeDeclared
(@NonNull Class<T> annotationClass, @NonNull String sourceAnnotation) Synthesizes a new annotation declared for the given annotation type using the member values of the given source annotation.default <T extends Annotation>
@NonNull T[]synthesizeDeclaredAnnotationsByType
(@NonNull Class<T> annotationClass) Synthesizes a new annotations from the metadata for the given type.
-
Field Details
-
EMPTY
An empty annotation source.
-
-
Method Details
-
synthesize
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 Annotation> T synthesize(@NonNull @NonNull Class<T> annotationClass, @NonNull @NonNull 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 ajakarta.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 Annotation> T synthesizeDeclared(@NonNull @NonNull Class<T> annotationClass, @NonNull @NonNull 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 ajakarta.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 Annotation> T synthesizeDeclared(@NonNull @NonNull 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
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
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 Annotation> @NonNull T[] synthesizeAnnotationsByType(@NonNull @NonNull 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 Annotation> @NonNull T[] synthesizeDeclaredAnnotationsByType(@NonNull @NonNull 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 Annotation> @NonNull Optional<AnnotationValue<T>> findAnnotation(@NonNull @NonNull 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 Annotation> @NonNull Optional<AnnotationValue<T>> findAnnotation(@NonNull @NonNull 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 Annotation> @NonNull Optional<AnnotationValue<T>> findDeclaredAnnotation(@NonNull @NonNull String annotation) Get all 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 Annotation> @NonNull Optional<AnnotationValue<T>> findDeclaredAnnotation(@NonNull @NonNull Class<T> annotationClass) Get all 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 Annotation> @Nullable AnnotationValue<T> getAnnotation(@NonNull @NonNull 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 Annotation> @Nullable AnnotationValue<T> getAnnotation(@NonNull @NonNull 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 Annotation> @Nullable AnnotationValue<T> getDeclaredAnnotation(@NonNull @NonNull String annotation) Get all 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 Annotation> @Nullable AnnotationValue<T> getDeclaredAnnotation(@NonNull @NonNull 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
Return whether an annotation is present.- Parameters:
annotationClass
- The annotation class- Returns:
- True if it is
-
isDeclaredAnnotationPresent
default boolean isDeclaredAnnotationPresent(@NonNull @NonNull Class<? extends Annotation> annotationClass) Variation ofisAnnotationPresent(Class)
for declared annotations.- Parameters:
annotationClass
- The annotation class- Returns:
- True if it is
-
isAnnotationPresent
Return whether an annotation is present.- Parameters:
annotationName
- The annotation name- Returns:
- True if it is
-
isDeclaredAnnotationPresent
Variation ofisAnnotationPresent(String)
for declared annotations.- Parameters:
annotationName
- The annotation name- Returns:
- True if it is
-
getTargetAnnotationMetadata
Unwraps possible delegate or provider.- Returns:
- unwrapped
- Since:
- 4.0.0
-