Package io.micronaut.inject.writer
Class AbstractBeanDefinitionBuilder
- java.lang.Object
-
- io.micronaut.inject.writer.AbstractBeanDefinitionBuilder
-
- All Implemented Interfaces:
io.micronaut.core.annotation.AnnotatedElement,io.micronaut.core.annotation.AnnotationMetadata,io.micronaut.core.annotation.AnnotationMetadataDelegate,io.micronaut.core.annotation.AnnotationMetadataProvider,io.micronaut.core.annotation.AnnotationSource,io.micronaut.core.naming.Described,io.micronaut.core.naming.Named,BeanElementBuilder,ConfigurableElement,Element
@Internal public abstract class AbstractBeanDefinitionBuilder extends java.lang.Object implements BeanElementBuilder
Abstract implementation of theBeanElementBuilderinterface that should be implemented by downstream language specific implementations.- Since:
- 3.0.0
-
-
Field Summary
Fields Modifier and Type Field Description protected ConfigurationMetadataBuilder<?>metadataBuilderprotected VisitorContextvisitorContext-
Fields inherited from interface io.micronaut.core.annotation.AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBER
-
Fields inherited from interface io.micronaut.inject.ast.Element
EMPTY_ELEMENT_ARRAY
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractBeanDefinitionBuilder(Element originatingElement, ClassElement beanType, ConfigurationMetadataBuilder<?> metadataBuilder, VisitorContext visitorContext)Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract <T extends java.lang.annotation.Annotation>
voidannotate(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, io.micronaut.core.annotation.AnnotationValue<T> annotationValue)Add an annotation to the given metadata.protected abstract <T extends java.lang.annotation.Annotation>
voidannotate(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.String annotationType, java.util.function.Consumer<io.micronaut.core.annotation.AnnotationValueBuilder<T>> consumer)Add an annotation to the given metadata.<T extends java.lang.annotation.Annotation>
Elementannotate(io.micronaut.core.annotation.AnnotationValue<T> annotationValue)Annotate this element with the given annotation type.<T extends java.lang.annotation.Annotation>
BeanElementBuilderannotate(java.lang.String annotationType, java.util.function.Consumer<io.micronaut.core.annotation.AnnotationValueBuilder<T>> consumer)Annotate this element with the given annotation type.BeanClassWriterbuild()Build the bean definition writer.protected booleanconfigureBeanVisitor(BeanDefinitionVisitor beanDefinitionWriter)Configure the bean visitor for this builder.protected abstract BeanDefinitionVisitorcreateAopWriter(BeanDefinitionWriter beanDefinitionWriter, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)Creates the AOP writer.protected abstract java.util.function.BiConsumer<TypedElement,MethodElement>createAroundMethodVisitor(BeanDefinitionVisitor aopProxyWriter)Creates the around method visitor.protected BeanDefinitionVisitorcreateBeanDefinitionWriter()protected abstract AbstractBeanDefinitionBuildercreateChildBean(FieldElement producerField)Creates a child bean for the given producer field.protected abstract AbstractBeanDefinitionBuildercreateChildBean(MethodElement producerMethod)Creates a child bean for the given producer method.BeanElementBuildercreateWith(MethodElement element)Specifies the bean will created with the given method element.protected voidfinalizeAndWriteBean(ClassWriterOutputVisitor classWriterOutputVisitor, BeanDefinitionVisitor beanDefinitionWriter)Finish the given bean and write it to the output.io.micronaut.core.annotation.AnnotationMetadatagetAnnotationMetadata()ClassElementgetBeanType()java.util.List<AbstractBeanDefinitionBuilder>getChildBeans()Any child bean definitions.java.lang.StringgetName()java.lang.ObjectgetNativeType()Returns the native underlying type.ElementgetOriginatingElement()protected BeanParameterElement[]getParameters()protected BeanParameterElement[]initBeanParameters(ParameterElement[] constructorParameters)Initialize the bean parameters.BeanElementBuilderinject()Dependency inject this bean.BeanElementBuilderintercept(io.micronaut.core.annotation.AnnotationValue<?>... annotationValue)Intercept the bean.protected booleanisIntercepted()Is the bean to be built intercepted?booleanisProtected()booleanisPublic()<E extends MemberElement>
BeanElementBuilderproduceBeans(ElementQuery<E> methodsOrFields, java.util.function.Consumer<BeanElementBuilder> childBeanBuilder)Produce additional beans from the given methods.protected abstract voidremoveAnnotation(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.String annotationType)Remove an annotation for the given name.BeanElementBuilderremoveAnnotation(java.lang.String annotationType)Removes an annotation of the given type from the element.protected abstract <T extends java.lang.annotation.Annotation>
voidremoveAnnotationIf(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.util.function.Predicate<io.micronaut.core.annotation.AnnotationValue<T>> predicate)Remove an annotation if it matches the given condition.<T extends java.lang.annotation.Annotation>
BeanElementBuilderremoveAnnotationIf(java.util.function.Predicate<io.micronaut.core.annotation.AnnotationValue<T>> predicate)Removes all annotations that pass the given predicate.protected abstract voidremoveStereotype(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.String annotationType)Remove a stereotype from the given metadata.BeanElementBuilderremoveStereotype(java.lang.String annotationType)Removes a stereotype of the given name from the element.BeanElementBuildertypeArguments(ClassElement... types)Fills the type arguments for the bean with the given types.BeanElementBuildertypeArgumentsForType(ClassElement type, ClassElement... types)Fills the type arguments for the given interface or super class with the given types.BeanElementBuildertyped(ClassElement... types)Alters the exposed types for the bean limiting the exposed type to the given types.protected voidvisitInterceptedMethods(java.util.function.BiConsumer<TypedElement,MethodElement> consumer)Visit the intercepted methods of this type.BeanElementBuilderwithConstructor(java.util.function.Consumer<BeanConstructorElement> constructorElement)Allows configuring the bean constructor.BeanElementBuilderwithFields(ElementQuery<FieldElement> fields, java.util.function.Consumer<BeanFieldElement> beanFields)Allows configuring fields of the bean.BeanElementBuilderwithMethods(ElementQuery<MethodElement> methods, java.util.function.Consumer<BeanMethodElement> beanMethods)Allows configuring methods of the bean.BeanElementBuilderwithParameters(java.util.function.Consumer<BeanParameterElement[]> parameters)Allows configuring the parameters for the current constructor.static voidwriteBeanDefinitionBuilders(ClassWriterOutputVisitor classWriterOutputVisitor, java.util.List<AbstractBeanDefinitionBuilder> beanDefinitionBuilders)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.micronaut.core.annotation.AnnotatedElement
isDeclaredNonNull, isDeclaredNullable, isNonNull, isNullable
-
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, 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, synthesizeDeclaredAnnotationsByType
-
Methods inherited from interface io.micronaut.inject.ast.beans.BeanElementBuilder
annotate, annotate, annotate, getDeclaringElement, getProducingElement, produceBeans, qualifier, qualifier, removeAnnotation, removeStereotype, scope, scope
-
Methods inherited from interface io.micronaut.inject.ast.Element
getDescription, getDescription, getDocumentation, getModifiers, getSimpleName, isAbstract, isFinal, isPackagePrivate, isPrivate, isStatic
-
-
-
-
Field Detail
-
metadataBuilder
protected final ConfigurationMetadataBuilder<?> metadataBuilder
-
visitorContext
protected final VisitorContext visitorContext
-
-
Constructor Detail
-
AbstractBeanDefinitionBuilder
protected AbstractBeanDefinitionBuilder(Element originatingElement, ClassElement beanType, ConfigurationMetadataBuilder<?> metadataBuilder, VisitorContext visitorContext)
Default constructor.- Parameters:
originatingElement- The originating elementbeanType- The bean typemetadataBuilder- the metadata buildervisitorContext- the visitor context
-
-
Method Detail
-
intercept
public BeanElementBuilder intercept(io.micronaut.core.annotation.AnnotationValue<?>... annotationValue)
Description copied from interface:BeanElementBuilderIntercept the bean.- Specified by:
interceptin interfaceBeanElementBuilder- Parameters:
annotationValue- The annotation to intercept- Returns:
- This bean method
-
writeBeanDefinitionBuilders
@Internal public static void writeBeanDefinitionBuilders(ClassWriterOutputVisitor classWriterOutputVisitor, java.util.List<AbstractBeanDefinitionBuilder> beanDefinitionBuilders) throws java.io.IOException
- Throws:
java.io.IOException
-
isIntercepted
protected boolean isIntercepted()
Is the bean to be built intercepted?- Returns:
- True if it is
-
inject
public BeanElementBuilder inject()
Description copied from interface:BeanElementBuilderDependency inject this bean.- Specified by:
injectin interfaceBeanElementBuilder- Returns:
- this bean builder
-
getChildBeans
public java.util.List<AbstractBeanDefinitionBuilder> getChildBeans()
Any child bean definitions.- Returns:
- The child beans
-
getOriginatingElement
@NonNull public Element getOriginatingElement()
- Specified by:
getOriginatingElementin interfaceBeanElementBuilder- Returns:
- The originating element
-
getBeanType
@NonNull public ClassElement getBeanType()
- Specified by:
getBeanTypein interfaceBeanElementBuilder- Returns:
- The bean type
-
initBeanParameters
protected final BeanParameterElement[] initBeanParameters(@NonNull ParameterElement[] constructorParameters)
Initialize the bean parameters.- Parameters:
constructorParameters- The parameters to use.- Returns:
- The initialized parameters
-
getAnnotationMetadata
@NonNull public io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata()
- Specified by:
getAnnotationMetadatain interfaceio.micronaut.core.annotation.AnnotationMetadataProvider
-
createWith
@NonNull public BeanElementBuilder createWith(@NonNull MethodElement element)
Description copied from interface:BeanElementBuilderSpecifies the bean will created with the given method element. If not specified the bean will be created withClassElement.getPrimaryConstructor().Note that the method can be a one of the following:
- An accessible constructor on the bean type being generated
- An accessible static method on the bean type being generated
- Specified by:
createWithin interfaceBeanElementBuilder- Parameters:
element- The element- Returns:
- This bean builder
-
typed
@NonNull public BeanElementBuilder typed(ClassElement... types)
Description copied from interface:BeanElementBuilderAlters the exposed types for the bean limiting the exposed type to the given types.- Specified by:
typedin interfaceBeanElementBuilder- Parameters:
types- 1 or more types to expose- Returns:
- This builder
-
typeArguments
@NonNull public BeanElementBuilder typeArguments(@NonNull ClassElement... types)
Description copied from interface:BeanElementBuilderFills the type arguments for the bean with the given types.- Specified by:
typeArgumentsin interfaceBeanElementBuilder- Specified by:
typeArgumentsin interfaceConfigurableElement- Parameters:
types- The types- Returns:
- This bean builder
-
typeArgumentsForType
@NonNull public BeanElementBuilder typeArgumentsForType(ClassElement type, @NonNull ClassElement... types)
Description copied from interface:BeanElementBuilderFills the type arguments for the given interface or super class with the given types.- Specified by:
typeArgumentsForTypein interfaceBeanElementBuilder- Parameters:
type- The type or interface. If null, results in a no-optypes- The types- Returns:
- This bean builder
-
withConstructor
public BeanElementBuilder withConstructor(java.util.function.Consumer<BeanConstructorElement> constructorElement)
Description copied from interface:BeanElementBuilderAllows configuring the bean constructor.- Specified by:
withConstructorin interfaceBeanElementBuilder- Parameters:
constructorElement- The constructor element- Returns:
- This bean builder
-
withMethods
@NonNull public BeanElementBuilder withMethods(@NonNull ElementQuery<MethodElement> methods, @NonNull java.util.function.Consumer<BeanMethodElement> beanMethods)
Description copied from interface:BeanElementBuilderAllows configuring methods of the bean.- Specified by:
withMethodsin interfaceBeanElementBuilder- Parameters:
methods- TheElementQueryto locate selected methods.beanMethods- A consumer that receives eachBeanMethodElement- Returns:
- This builder
-
withFields
@NonNull public BeanElementBuilder withFields(@NonNull ElementQuery<FieldElement> fields, @NonNull java.util.function.Consumer<BeanFieldElement> beanFields)
Description copied from interface:BeanElementBuilderAllows configuring fields of the bean.- Specified by:
withFieldsin interfaceBeanElementBuilder- Parameters:
fields- TheElementQueryto locate fields.beanFields- The bean fields- Returns:
- This builder
-
withParameters
@NonNull public BeanElementBuilder withParameters(java.util.function.Consumer<BeanParameterElement[]> parameters)
Description copied from interface:BeanElementBuilderAllows configuring the parameters for the current constructor.- Specified by:
withParametersin interfaceBeanElementBuilder- Parameters:
parameters- The parameters- Returns:
- This builder
-
getParameters
@NonNull protected BeanParameterElement[] getParameters()
- Returns:
- The bean creation parameters.
-
getName
@NonNull public java.lang.String getName()
-
isProtected
public boolean isProtected()
- Specified by:
isProtectedin interfaceElement- Returns:
- True if the element is protected.
-
isPublic
public boolean isPublic()
-
getNativeType
@NonNull public java.lang.Object getNativeType()
Description copied from interface:ElementReturns the native underlying type. This API is extended by all of the inject language implementations. The object returned by this method will be the language native type the information is being retrieved from.- Specified by:
getNativeTypein interfaceElement- Returns:
- The native type
-
annotate
@NonNull public <T extends java.lang.annotation.Annotation> BeanElementBuilder annotate(@NonNull java.lang.String annotationType, @NonNull java.util.function.Consumer<io.micronaut.core.annotation.AnnotationValueBuilder<T>> consumer)
Description copied from interface:ElementAnnotate this element with the given annotation type. If the annotation is already present then any values populated by the builder will be merged/overridden with the existing values.- Specified by:
annotatein interfaceBeanElementBuilder- Specified by:
annotatein interfaceElement- Type Parameters:
T- The annotation generic type- Parameters:
annotationType- The annotation typeconsumer- A function that receives theAnnotationValueBuilder- Returns:
- This element
-
annotate
public <T extends java.lang.annotation.Annotation> Element annotate(io.micronaut.core.annotation.AnnotationValue<T> annotationValue)
Description copied from interface:ElementAnnotate this element with the given annotation type. If the annotation is already present then any values populated by the builder will be merged/overridden with the existing values.
-
removeAnnotation
public BeanElementBuilder removeAnnotation(@NonNull java.lang.String annotationType)
Description copied from interface:ElementRemoves an annotation of the given type from the element.If the annotation features any stereotypes these will also be removed unless there are other annotations that reference the stereotype to be removed.
In the case of repeatable annotations this method will remove all repeated annotations, effectively clearing out all declared repeated annotations of the given type.
- Specified by:
removeAnnotationin interfaceBeanElementBuilder- Specified by:
removeAnnotationin interfaceElement- Parameters:
annotationType- The annotation type- Returns:
- This element
-
removeAnnotationIf
public <T extends java.lang.annotation.Annotation> BeanElementBuilder removeAnnotationIf(@NonNull java.util.function.Predicate<io.micronaut.core.annotation.AnnotationValue<T>> predicate)
Description copied from interface:ElementRemoves all annotations that pass the given predicate.- Specified by:
removeAnnotationIfin interfaceBeanElementBuilder- Specified by:
removeAnnotationIfin interfaceElement- Type Parameters:
T- The annotation generic type- Parameters:
predicate- The predicate- Returns:
- This element
-
removeStereotype
public BeanElementBuilder removeStereotype(@NonNull java.lang.String annotationType)
Description copied from interface:ElementRemoves a stereotype of the given name from the element.- Specified by:
removeStereotypein interfaceBeanElementBuilder- Specified by:
removeStereotypein interfaceElement- Parameters:
annotationType- The annotation type- Returns:
- This element
-
produceBeans
public <E extends MemberElement> BeanElementBuilder produceBeans(ElementQuery<E> methodsOrFields, java.util.function.Consumer<BeanElementBuilder> childBeanBuilder)
Description copied from interface:BeanElementBuilderProduce additional beans from the given methods.- Specified by:
produceBeansin interfaceBeanElementBuilder- Type Parameters:
E- A type variable to- Parameters:
methodsOrFields- TheElementQueryrepresenting the methods or fieldschildBeanBuilder- Configure the child bean builder- Returns:
- This bean builder
-
createChildBean
@NonNull protected abstract AbstractBeanDefinitionBuilder createChildBean(FieldElement producerField)
Creates a child bean for the given producer field.- Parameters:
producerField- The producer field- Returns:
- The child bean builder
-
visitInterceptedMethods
protected void visitInterceptedMethods(java.util.function.BiConsumer<TypedElement,MethodElement> consumer)
Visit the intercepted methods of this type.- Parameters:
consumer- A consumer to handle the method
-
createChildBean
@NonNull protected abstract AbstractBeanDefinitionBuilder createChildBean(MethodElement producerMethod)
Creates a child bean for the given producer method.- Parameters:
producerMethod- The producer method- Returns:
- The child bean builder
-
build
@Nullable public BeanClassWriter build()
Build the bean definition writer.- Returns:
- The writer, possibly null if it wasn't possible to build it
-
createAroundMethodVisitor
@NonNull protected abstract java.util.function.BiConsumer<TypedElement,MethodElement> createAroundMethodVisitor(BeanDefinitionVisitor aopProxyWriter)
Creates the around method visitor.- Parameters:
aopProxyWriter- The AOP writer- Returns:
- The visitor
-
createAopWriter
@NonNull protected abstract BeanDefinitionVisitor createAopWriter(BeanDefinitionWriter beanDefinitionWriter, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
Creates the AOP writer.- Parameters:
beanDefinitionWriter- The bean definition writerannotationMetadata- The annotation metadata- Returns:
- The AOP writer
-
finalizeAndWriteBean
protected void finalizeAndWriteBean(ClassWriterOutputVisitor classWriterOutputVisitor, BeanDefinitionVisitor beanDefinitionWriter) throws java.io.IOException
Finish the given bean and write it to the output.- Parameters:
classWriterOutputVisitor- The outputbeanDefinitionWriter- The writer- Throws:
java.io.IOException- If an error occurred
-
configureBeanVisitor
protected boolean configureBeanVisitor(BeanDefinitionVisitor beanDefinitionWriter)
Configure the bean visitor for this builder.- Parameters:
beanDefinitionWriter- The bean visitor- Returns:
- True if an error occurred
-
createBeanDefinitionWriter
protected BeanDefinitionVisitor createBeanDefinitionWriter()
- Returns:
- Creates the bean definition writer.
-
annotate
protected abstract <T extends java.lang.annotation.Annotation> void annotate(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.String annotationType, java.util.function.Consumer<io.micronaut.core.annotation.AnnotationValueBuilder<T>> consumer)Add an annotation to the given metadata.- Type Parameters:
T- The annotation generic type- Parameters:
annotationMetadata- The annotation metadataannotationType- the annotation typeconsumer- The builder
-
annotate
protected abstract <T extends java.lang.annotation.Annotation> void annotate(@NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull io.micronaut.core.annotation.AnnotationValue<T> annotationValue)Add an annotation to the given metadata.- Type Parameters:
T- The annotation generic type- Parameters:
annotationMetadata- The annotation metadataannotationValue- The value- Since:
- 3.3.0
-
removeStereotype
protected abstract void removeStereotype(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.String annotationType)Remove a stereotype from the given metadata.- Parameters:
annotationMetadata- The metadataannotationType- The stereotype
-
removeAnnotationIf
protected abstract <T extends java.lang.annotation.Annotation> void removeAnnotationIf(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.util.function.Predicate<io.micronaut.core.annotation.AnnotationValue<T>> predicate)Remove an annotation if it matches the given condition.- Type Parameters:
T- The annotation type- Parameters:
annotationMetadata- The metadatapredicate- The predicate
-
removeAnnotation
protected abstract void removeAnnotation(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.String annotationType)Remove an annotation for the given name.- Parameters:
annotationMetadata- The metadataannotationType- The type
-
-