Class AbstractBeanDefinition<T>
- java.lang.Object
-
- io.micronaut.context.AbstractBeanDefinition<T>
-
- Type Parameters:
T- The Bean definition type
- All Implemented Interfaces:
EnvironmentConfigurable,io.micronaut.core.annotation.AnnotationMetadata,io.micronaut.core.annotation.AnnotationMetadataDelegate,io.micronaut.core.annotation.AnnotationMetadataProvider,io.micronaut.core.annotation.AnnotationSource,io.micronaut.core.naming.Named,io.micronaut.core.type.ArgumentCoercible<T>,BeanContextConditional,BeanDefinition<T>,BeanType<T>
- Direct Known Subclasses:
AbstractParametrizedBeanDefinition
@Internal public class AbstractBeanDefinition<T> extends java.lang.Object implements BeanDefinition<T>, EnvironmentConfigurable
Default implementation of the
BeanDefinitioninterface. This class is generally not used directly in user code. Instead a build time tool does analysis of source code and dynamically produces subclasses of this class containing information about the available injection points for a given class.For technical reasons the class has to be marked as public, but is regarded as internal and should be used by compiler tools and plugins (such as AST transformation frameworks)
The
BeanDefinitionWriterclass can be used to produce bean definitions at compile or runtime- Since:
- 1.0
- See Also:
BeanDefinitionWriter
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<io.micronaut.context.AbstractBeanDefinition.MethodKey,ExecutableMethod<T,?>>executableMethodMapprotected java.util.List<FieldInjectionPoint<T,?>>fieldInjectionPointsprotected java.util.List<MethodInjectionPoint<T,?>>methodInjectionPointsprotected java.util.List<MethodInjectionPoint<T,?>>postConstructMethodsprotected java.util.List<MethodInjectionPoint<T,?>>preDestroyMethods
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractBeanDefinition(java.lang.Class<T> type, io.micronaut.core.annotation.AnnotationMetadata constructorAnnotationMetadata, boolean requiresReflection, io.micronaut.core.type.Argument... arguments)Constructs a bean for the given type.protectedAbstractBeanDefinition(java.lang.Class<T> producedType, java.lang.Class<?> declaringType, java.lang.String fieldName, io.micronaut.core.annotation.AnnotationMetadata fieldMetadata, boolean isFinal)Constructs a bean definition that is produced from a method call on another type (factory bean).protectedAbstractBeanDefinition(java.lang.Class<T> producedType, java.lang.Class<?> declaringType, java.lang.String methodName, io.micronaut.core.annotation.AnnotationMetadata methodMetadata, boolean requiresReflection, io.micronaut.core.type.Argument<?>... arguments)Constructs a bean definition that is produced from a method call on another type (factory bean).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected AbstractBeanDefinition<T>addExecutableMethod(ExecutableMethod<T,?> executableMethod)Adds a newExecutableMethod.protected AbstractBeanDefinitionaddInjectionPoint(java.lang.Class declaringType, java.lang.Class fieldType, java.lang.String field, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, io.micronaut.core.type.Argument[] typeArguments, boolean requiresReflection)Adds an injection point for a field.protected AbstractBeanDefinitionaddInjectionPoint(java.lang.Class declaringType, java.lang.String method, io.micronaut.core.type.Argument[] arguments, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, boolean requiresReflection)Adds an injection point for a method that cannot be resolved at runtime, but a compile time produced injection point exists.protected AbstractBeanDefinitionaddPostConstruct(java.lang.Class declaringType, java.lang.String method, io.micronaut.core.type.Argument[] arguments, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, boolean requiresReflection)Adds a post construct method definition.protected AbstractBeanDefinitionaddPreDestroy(java.lang.Class declaringType, java.lang.String method, io.micronaut.core.type.Argument[] arguments, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, boolean requiresReflection)Adds a pre destroy method definition.voidconfigure(Environment environment)Configures the bean for the givenBeanContext.protected booleancontainsProperties(BeanResolutionContext resolutionContext, BeanContext context)If this bean is aConfigurationPropertiesbean return whether any properties for it are configured within the context.protected booleancontainsProperties(BeanResolutionContext resolutionContext, BeanContext context, java.lang.String subProperty)If this bean is aConfigurationPropertiesbean return whether any properties for it are configured within the context.protected booleancontainsValueForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex)Obtains a value for the given field argument.protected booleancontainsValueForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex)Obtains a value for the given method argument.booleanequals(java.lang.Object o)protected java.util.OptionalfindBeanForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, ConstructorInjectionPoint<T> constructorInjectionPoint, io.micronaut.core.type.Argument argument)Obtains all bean definitions for a constructor argument at the given indexprotected java.util.OptionalfindBeanForField(BeanResolutionContext resolutionContext, BeanContext context, FieldInjectionPoint injectionPoint)Obtains a an optional for the field at the given index and the argument at the given indexprotected java.util.OptionalfindBeanForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, MethodInjectionPoint injectionPoint, io.micronaut.core.type.Argument argument)Obtains an optional bean for the method at the given index and the argument at the given index<R> java.util.Optional<ExecutableMethod<T,R>>findMethod(java.lang.String name, java.lang.Class<?>... argumentTypes)Finds a singleExecutableMethodfor the given name and argument types.java.util.stream.Stream<ExecutableMethod<T,?>>findPossibleMethods(java.lang.String name)Finds possible methods for the given method name.io.micronaut.core.annotation.AnnotationMetadatagetAnnotationMetadata()protected java.lang.ObjectgetBeanForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argIndex)Obtains a bean definition for a constructor at the given indexprotected java.lang.ObjectgetBeanForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex)Obtains a bean definition for the field at the given index and the argument at the given indexprotected java.lang.ObjectgetBeanForField(BeanResolutionContext resolutionContext, BeanContext context, FieldInjectionPoint injectionPoint)Resolves a bean for the givenFieldInjectionPoint.protected java.lang.ObjectgetBeanForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex)Obtains a bean definition for the method at the given index and the argument at the given indexprotected BeanRegistration<?>getBeanRegistrationForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argIndex)Obtains a bean registration for a method injection point.protected BeanRegistration<?>getBeanRegistrationForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex)Obtains a bean registration for a field injection point.protected BeanRegistration<?>getBeanRegistrationForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex)Obtains a bean registration for a method injection point.protected java.lang.ObjectgetBeanRegistrationsForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argumentIndex)Obtains all bean definitions for a constructor argument at the given indexprotected java.lang.ObjectgetBeanRegistrationsForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex)Obtains all bean definitions for a field injection point.protected java.lang.ObjectgetBeanRegistrationsForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex)Obtains all bean definitions for a method injection point.protected java.lang.ObjectgetBeansOfTypeForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argumentIndex)Obtains all bean definitions for a constructor argument at the given index.protected java.util.CollectiongetBeansOfTypeForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, ConstructorInjectionPoint<T> constructorInjectionPoint, io.micronaut.core.type.Argument argument)Obtains all bean definitions for a constructor argument at the given index.protected java.lang.ObjectgetBeansOfTypeForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex)Obtains all bean definitions for the field at the given index.protected java.util.CollectiongetBeansOfTypeForField(BeanResolutionContext resolutionContext, BeanContext context, FieldInjectionPoint injectionPoint)Obtains a bean definition for the field at the given index and the argument at the given indexprotected java.lang.ObjectgetBeansOfTypeForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argumentIndex)Obtains all bean definitions for a constructor argument at the given index.protected java.util.CollectiongetBeansOfTypeForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, MethodInjectionPoint injectionPoint, io.micronaut.core.type.Argument argument)Obtains all bean definitions for the method at the given index and the argument at the given indexjava.lang.Class<T>getBeanType()Returns the bean type.ConstructorInjectionPoint<T>getConstructor()The single concrete constructor that is an injection point for creating the bean.java.util.Optional<io.micronaut.core.type.Argument<?>>getContainerElement()IfBeanType.isContainerType()returns true this will return the container element.java.util.Optional<java.lang.Class<?>>getDeclaringType()java.util.Collection<ExecutableMethod<T,?>>getExecutableMethods()java.util.Set<java.lang.Class<?>>getExposedTypes()Returns a potentially limited subset of bean types exposed by this bean.java.util.Collection<FieldInjectionPoint<T,?>>getInjectedFields()All the fields that require injection.java.util.Collection<MethodInjectionPoint<T,?>>getInjectedMethods()All methods that require injection.java.lang.StringgetName()java.util.Collection<MethodInjectionPoint<T,?>>getPostConstructMethods()All the methods that should be called once the bean has been fully initialized and constructed.java.util.Collection<MethodInjectionPoint<T,?>>getPreDestroyMethods()All the methods that should be called when the object is to be destroyed.protected java.lang.ObjectgetProxiedBean(BeanContext beanContext)Resolves the proxied bean instance for this bean.java.util.Collection<java.lang.Class<?>>getRequiredComponents()java.util.Optional<java.lang.Class<? extends java.lang.annotation.Annotation>>getScope()java.util.Optional<java.lang.String>getScopeName()protected java.util.stream.StreamgetStreamOfTypeForField(BeanResolutionContext resolutionContext, BeanContext context, FieldInjectionPoint injectionPoint)Obtains a bean definition for the field at the given index and the argument at the given indexjava.util.List<io.micronaut.core.type.Argument<?>>getTypeArguments(java.lang.String type)Return the type arguments for the given interface or super type for this bean.protected java.util.Map<java.lang.String,io.micronaut.core.type.Argument<?>[]>getTypeArgumentsMap()A method that subclasses can override to provide information on type arguments.protected java.lang.ObjectgetValueForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argIndex)Obtains a value for a bean definition for a constructor at the given indexprotected java.lang.ObjectgetValueForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex)Obtains a value for the given field from the bean contextprotected java.lang.ObjectgetValueForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex)Obtains a value for the given method argument.protected <T1> java.util.Optional<T1>getValueForPath(BeanResolutionContext resolutionContext, BeanContext context, io.micronaut.core.type.Argument<T1> propertyType, java.lang.String propertyPath)Resolve a value for the given field of the given type and path.protected <T1> java.util.Optional<T1>getValueForPath(BeanResolutionContext resolutionContext, BeanContext context, io.micronaut.core.type.Argument<T1> propertyType, java.lang.String... propertyPath)Resolve a value for the given field of the given type and path.inthashCode()booleanhasPropertyExpressions()Tinject(BeanContext context, T bean)Inject the given bean with the context.Tinject(BeanResolutionContext resolutionContext, BeanContext context, T bean)Inject the given bean with the context.protected java.lang.ObjectinjectAnother(BeanResolutionContext resolutionContext, BeanContext context, java.lang.Object bean)Inject another bean, for example one created via factory.protected java.lang.ObjectinjectBean(BeanResolutionContext resolutionContext, BeanContext context, java.lang.Object bean)The default implementation which provides no injection.protected voidinjectBeanField(BeanResolutionContext resolutionContext, DefaultBeanContext context, int index, java.lang.Object bean)Injects the value of a field of a bean that requires reflection.protected voidinjectBeanMethod(BeanResolutionContext resolutionContext, DefaultBeanContext context, int methodIndex, java.lang.Object bean)Inject a bean method that requires reflection.booleanisAbstract()booleanisEnabled(BeanContext context, BeanResolutionContext resolutionContext)Return whether this component is enabled for the given context.booleanisIterable()booleanisPrimary()booleanisProvided()protected java.lang.ObjectpostConstruct(BeanResolutionContext resolutionContext, BeanContext context, java.lang.Object bean)Default postConstruct hook that only invokes methods that require reflection.protected java.lang.ObjectpreDestroy(BeanResolutionContext resolutionContext, BeanContext context, java.lang.Object bean)Default preDestroy hook that only invokes methods that require reflection.protected io.micronaut.core.annotation.AnnotationMetadataresolveAnnotationMetadata()Resolves the annotation metadata for this bean.protected java.util.stream.StreamstreamOfTypeForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, ConstructorInjectionPoint<T> constructorInjectionPoint, io.micronaut.core.type.Argument argument)Obtains all bean definitions for a constructor argument at the given indexprotected java.util.stream.StreamstreamOfTypeForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, MethodInjectionPoint injectionPoint, io.micronaut.core.type.Argument argument)Obtains all bean definitions for the method at the given index and the argument at the given indexjava.lang.StringtoString()protected voidwarn(java.lang.String message)Allows printing warning messages produced by the compiler.protected voidwarnMissingProperty(java.lang.Class type, java.lang.String method, java.lang.String property)Allows printing warning messages produced by the compiler.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadata
getAnnotationValuesByName, getAnnotationValuesByStereotype, getDeclaredAnnotationValuesByName, getValues, hasDeclaredStereotype, isAnnotationPresent, isDeclaredAnnotationPresent
-
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataDelegate
booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, 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, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValues, getValues, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation, hasDeclaredStereotype, hasDeclaredStereotype, hasDeclaredStereotype, 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, synthesizeDeclaredAnnotationsByType
-
Methods inherited from interface io.micronaut.inject.BeanContextConditional
isEnabled, isEnabled
-
Methods inherited from interface io.micronaut.inject.BeanDefinition
asArgument, getDeclaredQualifier, getRequiredMethod, getTypeArguments, getTypeArguments, getTypeParameters, getTypeParameters, isCandidateBean, isProxy, isSingleton, resolveDynamicQualifier
-
Methods inherited from interface io.micronaut.inject.BeanType
isContainerType, requiresMethodProcessing
-
-
-
-
Field Detail
-
methodInjectionPoints
protected final java.util.List<MethodInjectionPoint<T,?>> methodInjectionPoints
-
fieldInjectionPoints
protected final java.util.List<FieldInjectionPoint<T,?>> fieldInjectionPoints
-
postConstructMethods
protected java.util.List<MethodInjectionPoint<T,?>> postConstructMethods
-
preDestroyMethods
protected java.util.List<MethodInjectionPoint<T,?>> preDestroyMethods
-
executableMethodMap
protected java.util.Map<io.micronaut.context.AbstractBeanDefinition.MethodKey,ExecutableMethod<T,?>> executableMethodMap
-
-
Constructor Detail
-
AbstractBeanDefinition
@Internal protected AbstractBeanDefinition(java.lang.Class<T> producedType, java.lang.Class<?> declaringType, java.lang.String fieldName, io.micronaut.core.annotation.AnnotationMetadata fieldMetadata, boolean isFinal)
Constructs a bean definition that is produced from a method call on another type (factory bean).- Parameters:
producedType- The produced typedeclaringType- The declaring type of the methodfieldName- The method namefieldMetadata- The metadata for the methodisFinal- Is the field final- Since:
- 3.0
-
AbstractBeanDefinition
@Internal protected AbstractBeanDefinition(java.lang.Class<T> producedType, java.lang.Class<?> declaringType, java.lang.String methodName, io.micronaut.core.annotation.AnnotationMetadata methodMetadata, boolean requiresReflection, io.micronaut.core.type.Argument<?>... arguments)
Constructs a bean definition that is produced from a method call on another type (factory bean).- Parameters:
producedType- The produced typedeclaringType- The declaring type of the methodmethodName- The method namemethodMetadata- The metadata for the methodrequiresReflection- Whether reflection is required to invoke the methodarguments- The method arguments
-
AbstractBeanDefinition
@Internal protected AbstractBeanDefinition(java.lang.Class<T> type, io.micronaut.core.annotation.AnnotationMetadata constructorAnnotationMetadata, boolean requiresReflection, io.micronaut.core.type.Argument... arguments)
Constructs a bean for the given type.- Parameters:
type- The typeconstructorAnnotationMetadata- The annotation metadata for the constructorrequiresReflection- Whether reflection is requiredarguments- The constructor arguments used to build the bean
-
-
Method Detail
-
getContainerElement
public java.util.Optional<io.micronaut.core.type.Argument<?>> getContainerElement()
Description copied from interface:BeanDefinitionIfBeanType.isContainerType()returns true this will return the container element.- Specified by:
getContainerElementin interfaceBeanDefinition<T>- Returns:
- The container element.
-
hasPropertyExpressions
public final boolean hasPropertyExpressions()
- Specified by:
hasPropertyExpressionsin interfaceio.micronaut.core.annotation.AnnotationMetadata- Specified by:
hasPropertyExpressionsin interfaceio.micronaut.core.annotation.AnnotationMetadataDelegate- Specified by:
hasPropertyExpressionsin interfaceEnvironmentConfigurable- Returns:
- Whether any environment specific property expressions exist in the object.
-
getTypeArguments
@NonNull public java.util.List<io.micronaut.core.type.Argument<?>> getTypeArguments(java.lang.String type)
Description copied from interface:BeanDefinitionReturn the type arguments for the given interface or super type for this bean.- Specified by:
getTypeArgumentsin interfaceBeanDefinition<T>- Parameters:
type- The super class or interface type- Returns:
- The type arguments
-
getAnnotationMetadata
@NonNull public io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata()
- Specified by:
getAnnotationMetadatain interfaceio.micronaut.core.annotation.AnnotationMetadataProvider
-
isAbstract
public boolean isAbstract()
- Specified by:
isAbstractin interfaceBeanDefinition<T>- Returns:
- Whether the bean definition is abstract
-
isIterable
public boolean isIterable()
- Specified by:
isIterablein interfaceBeanDefinition<T>- Returns:
- Whether the bean declared with
EachPropertyorEachBean
-
isPrimary
public boolean isPrimary()
-
findMethod
public <R> java.util.Optional<ExecutableMethod<T,R>> findMethod(java.lang.String name, java.lang.Class<?>... argumentTypes)
Description copied from interface:BeanDefinitionFinds a singleExecutableMethodfor the given name and argument types.- Specified by:
findMethodin interfaceBeanDefinition<T>- Type Parameters:
R- The return type- Parameters:
name- The method nameargumentTypes- The argument types- Returns:
- An optional
ExecutableMethod
-
findPossibleMethods
public java.util.stream.Stream<ExecutableMethod<T,?>> findPossibleMethods(java.lang.String name)
Description copied from interface:BeanDefinitionFinds possible methods for the given method name.- Specified by:
findPossibleMethodsin interfaceBeanDefinition<T>- Parameters:
name- The method name- Returns:
- The possible methods
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isProvided
public boolean isProvided()
- Specified by:
isProvidedin interfaceBeanDefinition<T>- Returns:
- Is this definition provided by another bean
- See Also:
Provided
-
getScope
public java.util.Optional<java.lang.Class<? extends java.lang.annotation.Annotation>> getScope()
- Specified by:
getScopein interfaceBeanDefinition<T>- Returns:
- The scope of the bean
-
getScopeName
public java.util.Optional<java.lang.String> getScopeName()
- Specified by:
getScopeNamein interfaceBeanDefinition<T>- Returns:
- The name of the scope
-
getBeanType
public final java.lang.Class<T> getBeanType()
Description copied from interface:BeanTypeReturns the bean type.- Specified by:
getBeanTypein interfaceBeanDefinition<T>- Specified by:
getBeanTypein interfaceBeanType<T>- Returns:
- The produced bean type
-
getExposedTypes
@NonNull public final java.util.Set<java.lang.Class<?>> 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>- Returns:
- The exposed types
-
getDeclaringType
public final java.util.Optional<java.lang.Class<?>> getDeclaringType()
- Specified by:
getDeclaringTypein interfaceBeanDefinition<T>- Returns:
- The type that declares this definition, null if not applicable.
-
getConstructor
public final ConstructorInjectionPoint<T> getConstructor()
Description copied from interface:BeanDefinitionThe single concrete constructor that is an injection point for creating the bean.- Specified by:
getConstructorin interfaceBeanDefinition<T>- Returns:
- The constructor injection point
-
getRequiredComponents
public java.util.Collection<java.lang.Class<?>> getRequiredComponents()
- Specified by:
getRequiredComponentsin interfaceBeanDefinition<T>- Returns:
- All required components for this entity definition
-
getInjectedMethods
public final java.util.Collection<MethodInjectionPoint<T,?>> getInjectedMethods()
Description copied from interface:BeanDefinitionAll methods that require injection. This is a subset of all the methods in the class.- Specified by:
getInjectedMethodsin interfaceBeanDefinition<T>- Returns:
- The required properties
-
getInjectedFields
public final java.util.Collection<FieldInjectionPoint<T,?>> getInjectedFields()
Description copied from interface:BeanDefinitionAll the fields that require injection.- Specified by:
getInjectedFieldsin interfaceBeanDefinition<T>- Returns:
- The required fields
-
getPostConstructMethods
public final java.util.Collection<MethodInjectionPoint<T,?>> getPostConstructMethods()
Description copied from interface:BeanDefinitionAll the methods that should be called once the bean has been fully initialized and constructed.- Specified by:
getPostConstructMethodsin interfaceBeanDefinition<T>- Returns:
- Methods to call post construct
-
getPreDestroyMethods
public final java.util.Collection<MethodInjectionPoint<T,?>> getPreDestroyMethods()
Description copied from interface:BeanDefinitionAll the methods that should be called when the object is to be destroyed.- Specified by:
getPreDestroyMethodsin interfaceBeanDefinition<T>- Returns:
- Methods to call pre-destroy
-
getName
@NonNull public java.lang.String getName()
-
inject
public T inject(BeanContext context, T bean)
Description copied from interface:BeanDefinitionInject the given bean with the context.- Specified by:
injectin interfaceBeanDefinition<T>- Parameters:
context- The contextbean- The bean- Returns:
- The injected bean
-
inject
public T inject(BeanResolutionContext resolutionContext, BeanContext context, T bean)
Description copied from interface:BeanDefinitionInject the given bean with the context.- Specified by:
injectin interfaceBeanDefinition<T>- Parameters:
resolutionContext- the resolution contextcontext- The contextbean- The bean- Returns:
- The injected bean
-
getExecutableMethods
public java.util.Collection<ExecutableMethod<T,?>> getExecutableMethods()
- Specified by:
getExecutableMethodsin interfaceBeanDefinition<T>- Returns:
- The
ExecutableMethodinstances for this definition
-
configure
@Internal public final void configure(Environment environment)
Configures the bean for the givenBeanContext. If the context features anEnvironmentthis method configures the annotation metadata such that environment aware values are returned.- Specified by:
configurein interfaceEnvironmentConfigurable- Parameters:
environment- The environment
-
warn
@Internal protected final void warn(java.lang.String message)
Allows printing warning messages produced by the compiler.- Parameters:
message- The message
-
warnMissingProperty
@Internal protected final void warnMissingProperty(java.lang.Class type, java.lang.String method, java.lang.String property)Allows printing warning messages produced by the compiler.- Parameters:
type- The typemethod- The methodproperty- The property
-
getProxiedBean
@Internal protected final java.lang.Object getProxiedBean(BeanContext beanContext)
Resolves the proxied bean instance for this bean.- Parameters:
beanContext- TheBeanContext- Returns:
- The proxied bean
-
addExecutableMethod
@Internal protected final AbstractBeanDefinition<T> addExecutableMethod(ExecutableMethod<T,?> executableMethod)
Adds a newExecutableMethod.- Parameters:
executableMethod- The method- Returns:
- The bean definition
-
addInjectionPoint
@Internal protected final AbstractBeanDefinition addInjectionPoint(java.lang.Class declaringType, java.lang.Class fieldType, java.lang.String field, @Nullable io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @Nullable io.micronaut.core.type.Argument[] typeArguments, boolean requiresReflection)
Adds an injection point for a field. Typically called by a dynamically generated subclass.- Parameters:
declaringType- The declaring typefieldType- The field typefield- The name of the fieldannotationMetadata- The annotation metadata for the fieldtypeArguments- The argumentsrequiresReflection- Whether reflection is required- Returns:
- this component definition
-
addInjectionPoint
@Internal protected final AbstractBeanDefinition addInjectionPoint(java.lang.Class declaringType, java.lang.String method, @Nullable io.micronaut.core.type.Argument[] arguments, @Nullable io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, boolean requiresReflection)
Adds an injection point for a method that cannot be resolved at runtime, but a compile time produced injection point exists. This allows the framework to recover and relay better error messages to the user instead of just NoSuchMethodError.- Parameters:
declaringType- The declaring typemethod- The methodarguments- The argument typesannotationMetadata- The annotation metadatarequiresReflection- Whether the method requires reflection to invoke- Returns:
- this component definition
-
addPostConstruct
@Internal protected final AbstractBeanDefinition addPostConstruct(java.lang.Class declaringType, java.lang.String method, @Nullable io.micronaut.core.type.Argument[] arguments, @Nullable io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, boolean requiresReflection)
Adds a post construct method definition.- Parameters:
declaringType- The declaring typemethod- The methodarguments- The argumentsannotationMetadata- The annotation metadatarequiresReflection- Whether the method requires reflection- Returns:
- This bean definition
-
addPreDestroy
@Internal protected final AbstractBeanDefinition addPreDestroy(java.lang.Class declaringType, java.lang.String method, io.micronaut.core.type.Argument[] arguments, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, boolean requiresReflection)
Adds a pre destroy method definition.- Parameters:
declaringType- The declaring typemethod- The methodarguments- The argumentsannotationMetadata- The annotation metadatarequiresReflection- Whether the method requires reflection- Returns:
- This bean definition
-
injectBean
@Internal protected java.lang.Object injectBean(BeanResolutionContext resolutionContext, BeanContext context, java.lang.Object bean)
The default implementation which provides no injection. To be overridden by compile time tooling.- Parameters:
resolutionContext- The resolution contextcontext- The bean contextbean- The bean- Returns:
- The injected bean
-
injectAnother
@Internal protected java.lang.Object injectAnother(BeanResolutionContext resolutionContext, BeanContext context, java.lang.Object bean)
Inject another bean, for example one created via factory.- Parameters:
resolutionContext- The reslution contextcontext- The contextbean- The bean- Returns:
- The bean
-
postConstruct
@Internal protected java.lang.Object postConstruct(BeanResolutionContext resolutionContext, BeanContext context, java.lang.Object bean)
Default postConstruct hook that only invokes methods that require reflection. Generated subclasses should override to call methods that don't require reflection.- Parameters:
resolutionContext- The resolution hookcontext- The contextbean- The bean- Returns:
- The bean
-
preDestroy
protected java.lang.Object preDestroy(BeanResolutionContext resolutionContext, BeanContext context, java.lang.Object bean)
Default preDestroy hook that only invokes methods that require reflection. Generated subclasses should override to call methods that don't require reflection.- Parameters:
resolutionContext- The resolution hookcontext- The contextbean- The bean- Returns:
- The bean
-
injectBeanMethod
@Internal protected void injectBeanMethod(BeanResolutionContext resolutionContext, DefaultBeanContext context, int methodIndex, java.lang.Object bean)
Inject a bean method that requires reflection.- Parameters:
resolutionContext- The resolution contextcontext- The bean contextmethodIndex- The method indexbean- The bean
-
injectBeanField
@Internal protected final void injectBeanField(BeanResolutionContext resolutionContext, DefaultBeanContext context, int index, java.lang.Object bean)
Injects the value of a field of a bean that requires reflection.- Parameters:
resolutionContext- The resolution contextcontext- The bean contextindex- The index of the fieldbean- The bean being injected
-
getValueForMethodArgument
@Internal protected final java.lang.Object getValueForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex)
Obtains a value for the given method argument.- Parameters:
resolutionContext- The resolution contextcontext- The bean contextmethodIndex- The method indexargIndex- The argument index- Returns:
- The value
-
containsValueForMethodArgument
@Internal protected final boolean containsValueForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex)
Obtains a value for the given method argument.- Parameters:
resolutionContext- The resolution contextcontext- The bean contextmethodIndex- The method indexargIndex- The argument index- Returns:
- The value
-
getBeanForMethodArgument
@Internal protected final java.lang.Object getBeanForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex)
Obtains a bean definition for the method at the given index and the argument at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextmethodIndex- The method indexargIndex- The argument index- Returns:
- The resolved bean
-
getBeansOfTypeForMethodArgument
@Internal protected final java.util.Collection getBeansOfTypeForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, MethodInjectionPoint injectionPoint, io.micronaut.core.type.Argument argument)
Obtains all bean definitions for the method at the given index and the argument at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextinjectionPoint- The method injection pointargument- The argument- Returns:
- The resolved bean
-
findBeanForMethodArgument
@Internal protected final java.util.Optional findBeanForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, MethodInjectionPoint injectionPoint, io.micronaut.core.type.Argument argument)
Obtains an optional bean for the method at the given index and the argument at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextinjectionPoint- The method injection pointargument- The argument- Returns:
- The resolved bean
-
streamOfTypeForMethodArgument
@Internal protected final java.util.stream.Stream streamOfTypeForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, MethodInjectionPoint injectionPoint, io.micronaut.core.type.Argument argument)
Obtains all bean definitions for the method at the given index and the argument at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextinjectionPoint- The method injection pointargument- The argument- Returns:
- The resolved bean
-
getBeanForConstructorArgument
@Internal protected final java.lang.Object getBeanForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argIndex)
Obtains a bean definition for a constructor at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextargIndex- The argument index- Returns:
- The resolved bean
-
getValueForConstructorArgument
@Internal protected final java.lang.Object getValueForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argIndex)
Obtains a value for a bean definition for a constructor at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextargIndex- The argument index- Returns:
- The resolved bean
-
getBeansOfTypeForConstructorArgument
@Internal protected final java.util.Collection getBeansOfTypeForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, ConstructorInjectionPoint<T> constructorInjectionPoint, io.micronaut.core.type.Argument argument)
Obtains all bean definitions for a constructor argument at the given index.- Parameters:
resolutionContext- The resolution contextcontext- The contextconstructorInjectionPoint- The constructor injection pointargument- The argument- Returns:
- The resolved bean
-
getBeansOfTypeForConstructorArgument
@Internal protected final java.lang.Object getBeansOfTypeForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argumentIndex)
Obtains all bean definitions for a constructor argument at the given index.- Parameters:
resolutionContext- The resolution contextcontext- The contextargumentIndex- The argument index- Returns:
- The resolved bean
-
getBeansOfTypeForMethodArgument
@Internal protected final java.lang.Object getBeansOfTypeForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argumentIndex)
Obtains all bean definitions for a constructor argument at the given index.- Parameters:
resolutionContext- The resolution contextcontext- The contextmethodIndex- The method indexargumentIndex- The argument index- Returns:
- The resolved bean
-
getBeansOfTypeForField
@Internal protected final java.lang.Object getBeansOfTypeForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex)
Obtains all bean definitions for the field at the given index.- Parameters:
resolutionContext- The resolution contextcontext- The contextfieldIndex- The field index- Returns:
- The resolved bean
-
getBeanRegistrationsForConstructorArgument
@Internal protected final java.lang.Object getBeanRegistrationsForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argumentIndex)
Obtains all bean definitions for a constructor argument at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextargumentIndex- The argument index- Returns:
- The resolved bean
-
getBeanRegistrationForConstructorArgument
@Internal protected final BeanRegistration<?> getBeanRegistrationForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argIndex)
Obtains a bean registration for a method injection point.Warning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextargIndex- The arg index- Returns:
- The resolved bean registration
-
getBeanRegistrationsForField
@Internal protected final java.lang.Object getBeanRegistrationsForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex)
Obtains all bean definitions for a field injection point.Warning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextfieldIndex- The field index- Returns:
- The resolved bean
-
getBeanRegistrationForField
@Internal protected final BeanRegistration<?> getBeanRegistrationForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex)
Obtains a bean registration for a field injection point.Warning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextfieldIndex- The field index- Returns:
- The resolved bean registration
-
getBeanRegistrationsForMethodArgument
@Internal protected final java.lang.Object getBeanRegistrationsForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex)
Obtains all bean definitions for a method injection point.Warning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextmethodIndex- The method indexargIndex- The arg index- Returns:
- The resolved bean
-
getBeanRegistrationForMethodArgument
@Internal protected final BeanRegistration<?> getBeanRegistrationForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex)
Obtains a bean registration for a method injection point.Warning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextmethodIndex- The method indexargIndex- The arg index- Returns:
- The resolved bean registration
-
streamOfTypeForConstructorArgument
@Internal protected final java.util.stream.Stream streamOfTypeForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, ConstructorInjectionPoint<T> constructorInjectionPoint, io.micronaut.core.type.Argument argument)
Obtains all bean definitions for a constructor argument at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextconstructorInjectionPoint- The constructor injection pointargument- The argument- Returns:
- The resolved bean
-
findBeanForConstructorArgument
@Internal protected final java.util.Optional findBeanForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, ConstructorInjectionPoint<T> constructorInjectionPoint, io.micronaut.core.type.Argument argument)
Obtains all bean definitions for a constructor argument at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextconstructorInjectionPoint- The constructor injection pointargument- The argument- Returns:
- The resolved bean
-
getBeanForField
@Internal protected final java.lang.Object getBeanForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex)
Obtains a bean definition for the field at the given index and the argument at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextfieldIndex- The field index- Returns:
- The resolved bean
-
getValueForField
@Internal protected final java.lang.Object getValueForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex)
Obtains a value for the given field from the bean contextWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextfieldIndex- The index of the field- Returns:
- The resolved bean
-
getValueForPath
@Internal protected final <T1> java.util.Optional<T1> getValueForPath(BeanResolutionContext resolutionContext, BeanContext context, io.micronaut.core.type.Argument<T1> propertyType, java.lang.String... propertyPath)
Resolve a value for the given field of the given type and path. Only used by applications compiled with versions of Micronaut prior to 1.2.0.- Type Parameters:
T1- The generic type- Parameters:
resolutionContext- The resolution contextcontext- The bean contextpropertyType- The required property typepropertyPath- The property path- Returns:
- An optional value
-
getValueForPath
@Internal protected final <T1> java.util.Optional<T1> getValueForPath(BeanResolutionContext resolutionContext, BeanContext context, io.micronaut.core.type.Argument<T1> propertyType, java.lang.String propertyPath)
Resolve a value for the given field of the given type and path.- Type Parameters:
T1- The generic type- Parameters:
resolutionContext- The resolution contextcontext- The bean contextpropertyType- The required property typepropertyPath- The property path- Returns:
- An optional value
-
containsValueForField
@Internal protected final boolean containsValueForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex)
Obtains a value for the given field argument.- Parameters:
resolutionContext- The resolution contextcontext- The bean contextfieldIndex- The field index- Returns:
- True if it does
-
containsProperties
@Internal protected final boolean containsProperties(BeanResolutionContext resolutionContext, BeanContext context)
If this bean is aConfigurationPropertiesbean return whether any properties for it are configured within the context.- Parameters:
resolutionContext- the resolution contextcontext- The context- Returns:
- True if it does
-
containsProperties
@Internal protected final boolean containsProperties(BeanResolutionContext resolutionContext, BeanContext context, java.lang.String subProperty)
If this bean is aConfigurationPropertiesbean return whether any properties for it are configured within the context.- Parameters:
resolutionContext- the resolution contextcontext- The contextsubProperty- The subproperty to check- Returns:
- True if it does
-
getBeanForField
@Internal protected final java.lang.Object getBeanForField(BeanResolutionContext resolutionContext, BeanContext context, FieldInjectionPoint injectionPoint)
Resolves a bean for the givenFieldInjectionPoint.- Parameters:
resolutionContext- TheBeanResolutionContextcontext- TheBeanContextinjectionPoint- TheFieldInjectionPoint- Returns:
- The resolved bean
- Throws:
DependencyInjectionException- If the bean cannot be resolved
-
findBeanForField
@Internal protected final java.util.Optional findBeanForField(BeanResolutionContext resolutionContext, BeanContext context, FieldInjectionPoint injectionPoint)
Obtains a an optional for the field at the given index and the argument at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextinjectionPoint- The field injection point- Returns:
- The resolved bean
-
getBeansOfTypeForField
@Internal protected final java.util.Collection getBeansOfTypeForField(BeanResolutionContext resolutionContext, BeanContext context, FieldInjectionPoint injectionPoint)
Obtains a bean definition for the field at the given index and the argument at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextinjectionPoint- The field injection point- Returns:
- The resolved bean
-
getStreamOfTypeForField
@Internal protected final java.util.stream.Stream getStreamOfTypeForField(BeanResolutionContext resolutionContext, BeanContext context, FieldInjectionPoint injectionPoint)
Obtains a bean definition for the field at the given index and the argument at the given indexWarning: this method is used by internal generated code and should not be called by user code.
- Parameters:
resolutionContext- The resolution contextcontext- The contextinjectionPoint- The field injection point- Returns:
- The resolved bean
-
getTypeArgumentsMap
@Internal protected java.util.Map<java.lang.String,io.micronaut.core.type.Argument<?>[]> getTypeArgumentsMap()
A method that subclasses can override to provide information on type arguments.- Returns:
- The type arguments
-
resolveAnnotationMetadata
protected io.micronaut.core.annotation.AnnotationMetadata resolveAnnotationMetadata()
Resolves the annotation metadata for this bean. Subclasses- Returns:
- The
AnnotationMetadata
-
isEnabled
public boolean isEnabled(@NonNull BeanContext context, @Nullable BeanResolutionContext resolutionContext)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
-
-