Class ReflectionBeanDefinition<T>
- Type Parameters:
T- The bean type
- All Implemented Interfaces:
BeanContextConfigurable, EnvironmentConfigurable, RuntimeBeanDefinition<T>, AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, BeanInfo<T>, Named, Ordered, ArgumentCoercible<T>, BeanContextConditional, BeanDefinition<T>, BeanDefinitionReference<T>, BeanType<T>, DisposableBeanDefinition<T>, InitializingBeanDefinition<T>, InjectableBeanDefinition<T>, InstantiatableBeanDefinition<T>, QualifiedBeanType<T>
BeanDefinition over a Class, with the injection points, the executable methods and the life
cycle a generated definition would have, to register a type the annotation processors never saw with a
bean context
at runtime.
The definition is read from the class as the processors read it at compilation time:
- the bean is instantiated by the static method annotated
Creatorthe class declares, else by one of its accessible - non-private - constructors: the only one, else the one annotated@Inject, else the one annotatedCreator, else the canonical constructor of a record, else the first public one. That is the selectionClassElement#getPrimaryConstructor()makes at compilation time, but for a record whose constructors carry no annotation: the processors take the first public one there, where this takes the canonical one, which is the one the components describe. An annotation counts through its stereotypes, so a meta-annotated@Creatorcounts; - the non-static, non-final fields annotated
@Inject,ValueorProperty, and the ones declaring a qualifier without@Inject, are injected, the super classes' first; - the methods annotated
@Injectand the setters annotated with a qualifier -Valueis one - are injected, the methods annotated@PostConstructand@PreDestroyare the life cycle methods; - the methods annotated
Executable, and the public methods of a type annotatedExecutable, are the executable methods; - the scope, the qualifier, the order, the exposed types of
@Bean(typed = ...)and the conditions come from the annotations of the class, unless thebuilderoverrides them.
An inherited injection point is read as the bean type sees it: a member a generic super class declares
over a variable that the bean type gives a value to - a T dep of a class Base<T> inherited by
a class Impl extends Base<Book> - is injected as the value, a Book, which is what a generated
definition of the bean type asks for.
Each injected argument is resolved as a generated definition resolves it: a bean by type and qualifier, a
Collection, an array, a Stream, an Optional or a Map of beans, a
BeanRegistration or a collection of them, a configuration Value or Property. The
features that need the processors - @ConfigurationProperties binding, @EachProperty and
@EachBean iteration, @Parameter arguments, AOP advice - are not available to a reflective
definition.
- Since:
- 5.2.0
- Author:
- Denis Stepanov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilds the definition of a type, reading the class for what the builder does not set.Nested classes/interfaces inherited from class AbstractInitializableBeanDefinition
AbstractInitializableBeanDefinition.AnnotationReference, AbstractInitializableBeanDefinition.FieldReference, AbstractInitializableBeanDefinition.MethodOrFieldReference, AbstractInitializableBeanDefinition.MethodReference, AbstractInitializableBeanDefinition.PrecalculatedInfoNested classes/interfaces inherited from interface RuntimeBeanDefinition
RuntimeBeanDefinition.CreationContext, RuntimeBeanDefinition.DisposalContext, RuntimeBeanDefinition.LookupContext -
Field Summary
Fields inherited from interface AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBERFields inherited from interface AnnotationSource
EMPTYFields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ReflectionBeanDefinition.Builder<T> A builder of the definition of a type, to override what its annotations declare.dispose(BeanResolutionContext resolutionContext, BeanContext context, T bean) Disposes of the bean definition by executing allPreDestroyhooks.booleanTwo reflective definitions are equal only when they are the same one: several definitions of one type, each with its own qualifier, are as many beans.Resolve the declared qualifier for this bean.Returns a potentially limited subset of bean types exposed by this bean.intgetOrder()@Nullable Constructor<T> The constructor the bean is instantiated with.@Nullable MethodThe staticCreatormethod the bean is instantiated with, when the class declares one.getTypeArguments(@Nullable Class<?> type) Return the type arguments for the given interface or super type for this bean.inthashCode()initialize(BeanResolutionContext resolutionContext, BeanContext context, T bean) Initializes the bean invoking allPostConstructhooks.inject(BeanResolutionContext resolutionContext, BeanContext context, T bean) Inject the given bean with the context.instantiate(BeanResolutionContext resolutionContext, BeanContext context) Builds a bean instance.static booleanisDefinable(Class<?> type) Whether a definition can be built for a type: a class, not abstract, not a non-static inner class, and with an instantiation route - an accessible constructor or a staticCreatorfactory method.booleanisEnabled(BeanContext context, @Nullable BeanResolutionContext resolutionContext) Return whether this component is enabled for the given context.load(BeanContext context) Configures the definition for the context it is loaded by, as the reference of a generated definition does: the property expressions of the metadata resolve against the environment of an application context.static <T> ReflectionBeanDefinition<T> The definition of a type, read from its annotations.protected final voidonFail(io.micronaut.context.DefaultConditionContext<io.micronaut.context.AbstractBeanContextConditional> conditionContext, BeanContext context) toString()Methods inherited from class AbstractInitializableBeanDefinition
booleanValue, booleanValue, booleanValue, booleanValue, checkIfShouldLoad, checkInjectedBeanPropertyValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, configure, configure, containsProperties, containsProperties, containsPropertiesValue, containsPropertyValue, containsValueForField, containsValueForMethodArgument, copyAnnotationMetadata, doInstantiate, doubleValue, doubleValue, doubleValue, enumValue, enumValue, enumValue, enumValue, enumValues, enumValues, enumValues, enumValues, findAnnotation, findAnnotation, findBeanForConstructorArgument, findBeanForConstructorArgumentObject, findBeanForField, findBeanForFieldObject, findBeanForMethodArgument, findBeanForMethodArgumentObject, findDeclaredAnnotation, findDeclaredAnnotation, findMethod, findPossibleMethods, findRepeatableAnnotation, findRepeatableAnnotation, getAnnotation, getAnnotation, getAnnotationMetadata, getAnnotationNameByStereotype, getAnnotationNameByStereotype, getAnnotationNames, getAnnotationNamesByStereotype, getAnnotationNamesByStereotype, getAnnotationType, getAnnotationType, getAnnotationTypeByStereotype, getAnnotationTypeByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationValuesByName, getAnnotationValuesByStereotype, getAnnotationValuesByType, getBeanForAnnotation, getBeanForConstructorArgument, getBeanForField, getBeanForMethodArgument, getBeanForSetter, getBeanRegistrationForConstructorArgument, getBeanRegistrationForField, getBeanRegistrationForMethodArgument, getBeanRegistrationsForConstructorArgument, getBeanRegistrationsForConstructorArgumentObject, getBeanRegistrationsForField, getBeanRegistrationsForFieldObject, getBeanRegistrationsForMethodArgument, getBeanRegistrationsForMethodArgumentObject, getBeansOfTypeForConstructorArgument, getBeansOfTypeForConstructorArgumentObject, getBeansOfTypeForField, getBeansOfTypeForFieldObject, getBeansOfTypeForMethodArgument, getBeansOfTypeForMethodArgumentObject, getBeansOfTypeForSetter, getBeanType, getConstructor, getContainerElement, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByName, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDeclaringType, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getEvaluatedExpressionValueForConstructorArgument, getEvaluatedExpressionValueForMethodArgument, getExecutableMethods, getExecutableMethodsForProcessing, getIndexesOfExecutableMethodsForProcessing, getInjectedFields, getInjectedMethods, getMapOfTypeForConstructorArgument, getMapOfTypeForConstructorArgumentObject, getMapOfTypeForField, getMapOfTypeForFieldObject, getMapOfTypeForMethodArgument, getMapOfTypeForMethodArgumentObject, getName, getPostConstructExecutableMethods, getPostConstructMethods, getPreDestroyExecutableMethods, getPreDestroyMethods, getPropertyPlaceholderValueForConstructorArgument, getPropertyPlaceholderValueForField, getPropertyPlaceholderValueForMethodArgument, getPropertyPlaceholderValueForSetter, getPropertyValueForConstructorArgument, getPropertyValueForField, getPropertyValueForMethodArgument, getPropertyValueForSetter, getRequiredArguments, getRequiredComponents, getScope, getScopeName, getStereotypeAnnotationNames, getStreamOfTypeForConstructorArgument, getStreamOfTypeForField, getStreamOfTypeForMethodArgument, getTargetAnnotationMetadata, getTypeArgumentKeys, getTypeArguments, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValueForConstructorArgument, getValueForField, getValueForMethodArgument, getValueForPath, getValues, getValues, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation, hasDeclaredStereotype, hasDeclaredStereotype, hasDeclaredStereotype, hasEvaluatedExpressions, hasPropertyExpressions, hasSimpleAnnotation, hasSimpleDeclaredAnnotation, hasStereotype, hasStereotype, hasStereotype, hasStereotype, instantiate, intValue, intValue, intValue, invokeMethodWithReflection, isAbstract, isAnnotationPresent, isConfigurationProperties, isContainerType, isDeclaredAnnotationPresent, isEmpty, isFalse, isFalse, isInnerConfiguration, isIterable, isMethodResolved, isPresent, isPresent, isPrimary, isRepeatableAnnotation, isRepeatableAnnotation, isSingleton, isTrue, isTrue, longValue, longValue, postConstruct, preDestroy, requiresMethodProcessing, setFieldWithReflection, stringValue, stringValue, stringValue, stringValue, stringValues, stringValues, stringValues, stringValues, synthesize, synthesize, synthesizeAll, synthesizeAnnotationsByType, synthesizeDeclared, synthesizeDeclared, synthesizeDeclared, synthesizeDeclaredAnnotationsByType, warn, warnMissingPropertyMethods inherited from interface AnnotationMetadata
enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresentMethods inherited from interface AnnotationMetadataDelegate
booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, copyAnnotationMetadata, doubleValue, doubleValue, doubleValue, enumValue, enumValue, enumValue, enumValue, enumValues, enumValues, enumValues, enumValues, findAnnotation, findAnnotation, findDeclaredAnnotation, findDeclaredAnnotation, findRepeatableAnnotation, findRepeatableAnnotation, getAnnotation, getAnnotation, getAnnotationNameByStereotype, getAnnotationNameByStereotype, getAnnotationNames, getAnnotationNamesByStereotype, getAnnotationNamesByStereotype, getAnnotationType, getAnnotationType, getAnnotationTypeByStereotype, getAnnotationTypeByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationValuesByName, getAnnotationValuesByStereotype, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByName, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, getTargetAnnotationMetadata, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValues, getValues, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation, hasDeclaredStereotype, hasDeclaredStereotype, hasDeclaredStereotype, hasEvaluatedExpressions, hasPropertyExpressions, hasSimpleAnnotation, hasSimpleDeclaredAnnotation, hasStereotype, hasStereotype, hasStereotype, hasStereotype, intValue, intValue, intValue, isAnnotationPresent, isDeclaredAnnotationPresent, isEmpty, isFalse, isFalse, isPresent, isPresent, isRepeatableAnnotation, isRepeatableAnnotation, isTrue, isTrue, longValue, longValue, stringValue, stringValue, stringValue, stringValue, stringValues, stringValues, stringValues, stringValues, synthesize, synthesize, synthesizeAll, synthesizeAnnotationsByType, synthesizeDeclared, synthesizeDeclared, synthesizeDeclared, synthesizeDeclaredAnnotationsByTypeMethods inherited from interface BeanContextConditional
isEnabledMethods inherited from interface BeanDefinition
asArgument, findMethod, findPossibleMethods, getBeanDescription, getBeanDescription, getBeanType, getConstructor, getContainerElement, getDeclaringType, getDefaultImplementation, getExecutableMethods, getExecutableMethodsForProcessing, getGenericBeanType, getInjectedFields, getInjectedMethods, getName, getPostConstructMethods, getPreDestroyMethods, getReplacesDefinition, getRequiredComponents, getRequiredMethod, getScope, getScopeName, getTypeArguments, getTypeInformation, getTypeParameters, getTypeParameters, hasAnnotatedMethod, isAbstract, isCanBeReplaced, isCandidateBean, isConfigurationProperties, isIterable, isProxy, isSingletonMethods inherited from interface BeanDefinitionReference
getIndexes, isParallel, isProxiedBean, isProxyTargetMethods inherited from interface BeanType
getBeanName, isContainerType, isPrimary, requiresMethodProcessingMethods inherited from interface DisposableBeanDefinition
dispose, getPreDestroyExecutableMethodsMethods inherited from interface InitializingBeanDefinition
getPostConstructExecutableMethods, initializeMethods inherited from interface InjectableBeanDefinition
injectMethods inherited from interface InstantiatableBeanDefinition
instantiateMethods inherited from interface QualifiedBeanType
resolveDynamicQualifierMethods inherited from interface RuntimeBeanDefinition
getAnnotationMetadata, getTypeArgumentKeys, getTypeArguments, isConfigurationProperties, isContextScope, isEnabled, isPresent, isSingleton, load
-
Method Details
-
of
The definition of a type, read from its annotations.- Type Parameters:
T- The bean type- Parameters:
type- The type- Returns:
- The definition
- Throws:
IllegalArgumentException- When the type cannot be a bean: an interface, an abstract class, a non-static inner class or a type without an accessible constructor
-
isDefinable
Whether a definition can be built for a type: a class, not abstract, not a non-static inner class, and with an instantiation route - an accessible constructor or a staticCreatorfactory method.A container adapting another one asks before it binds, the way it asks
ReflectionBeanIntrospection.isIntrospectable(Class): a binding to a type this refuses has to be reported to the user in that container's own terms, rather than caught as an exception.- Parameters:
type- The type- Returns:
- Whether
of(Class)would return a definition rather than throw
-
builder
A builder of the definition of a type, to override what its annotations declare.- Type Parameters:
T- The bean type- Parameters:
type- The type- Returns:
- The builder
-
getTargetConstructor
The constructor the bean is instantiated with.- Returns:
- The constructor,
nullwhen the bean is instantiated by aCreatorfactory method - See Also:
-
getTargetFactoryMethod
-
getBeanDefinitionName
- Specified by:
getBeanDefinitionNamein interfaceBeanDefinitionReference<T>- Specified by:
getBeanDefinitionNamein interfaceRuntimeBeanDefinition<T>- Returns:
- The class name of the backing
BeanDefinition
-
getOrder
-
getDeclaredQualifier
Description copied from interface:QualifiedBeanTypeResolve the declared qualifier for this bean.- Specified by:
getDeclaredQualifierin interfaceQualifiedBeanType<T>- Overrides:
getDeclaredQualifierin classAbstractInitializableBeanDefinition<T>- Returns:
- The qualifier or null if this isn't one
-
getExposedTypes
Description copied from interface:BeanTypeReturns a potentially limited subset of bean types exposed by this bean. The types to be exposed can be defined by theTypeannotation.- Specified by:
getExposedTypesin interfaceBeanType<T>- Overrides:
getExposedTypesin classAbstractInitializableBeanDefinition<T>- Returns:
- The exposed types
-
getTypeArguments
Description copied from interface:BeanDefinitionReturn the type arguments for the given interface or super type for this bean.- Specified by:
getTypeArgumentsin interfaceBeanDefinition<T>- Specified by:
getTypeArgumentsin interfaceRuntimeBeanDefinition<T>- Parameters:
type- The super class or interface type- Returns:
- The type arguments
-
load
Configures the definition for the context it is loaded by, as the reference of a generated definition does: the property expressions of the metadata resolve against the environment of an application context.- Specified by:
loadin interfaceBeanDefinitionReference<T>- Specified by:
loadin interfaceRuntimeBeanDefinition<T>- Parameters:
context- The bean context- Returns:
- The loaded bean definition or null if it shouldn't be loaded
-
instantiate
public T instantiate(BeanResolutionContext resolutionContext, BeanContext context) throws BeanInstantiationException Description copied from interface:InstantiatableBeanDefinitionBuilds a bean instance.- Specified by:
instantiatein interfaceInstantiatableBeanDefinition<T>- Parameters:
resolutionContext- The bean resolution contextcontext- The context- Returns:
- The instance
- Throws:
BeanInstantiationException- if the instance could not be instantiated
-
inject
Description copied from interface:InjectableBeanDefinitionInject the given bean with the context.- Specified by:
injectin interfaceInjectableBeanDefinition<T>- Overrides:
injectin classAbstractInitializableBeanDefinition<T>- Parameters:
resolutionContext- the resolution contextcontext- The contextbean- The bean- Returns:
- The injected bean
-
initialize
Description copied from interface:InitializingBeanDefinitionInitializes the bean invoking allPostConstructhooks.- Specified by:
initializein interfaceInitializingBeanDefinition<T>- Parameters:
resolutionContext- The resolution contextcontext- The bean contextbean- The bean- Returns:
- The bean instance
-
dispose
Description copied from interface:DisposableBeanDefinitionDisposes of the bean definition by executing allPreDestroyhooks.- Specified by:
disposein interfaceDisposableBeanDefinition<T>- Parameters:
resolutionContext- The bean resolution contextcontext- The bean contextbean- The bean- Returns:
- The bean instance
-
toString
- Overrides:
toStringin classAbstractInitializableBeanDefinition<T>
-
equals
Two reflective definitions are equal only when they are the same one: several definitions of one type, each with its own qualifier, are as many beans.- Overrides:
equalsin classAbstractInitializableBeanDefinition<T>
-
hashCode
public int hashCode()- Overrides:
hashCodein classAbstractInitializableBeanDefinition<T>
-
isEnabled
Description copied from interface:BeanContextConditionalReturn whether this component is enabled for the given context.- Specified by:
isEnabledin interfaceBeanContextConditional- Parameters:
context- The contextresolutionContext- The bean resolution context- Returns:
- True if it is
-
onFail
protected final void onFail(io.micronaut.context.DefaultConditionContext<io.micronaut.context.AbstractBeanContextConditional> conditionContext, BeanContext context)
-