Class BeanDefinitionWriter
- All Implemented Interfaces:
AnnotatedElement
,AnnotationMetadata
,AnnotationMetadataDelegate
,AnnotationMetadataProvider
,AnnotationSource
,Described
,Named
,Toggleable
,MutableAnnotationMetadataDelegate<Element>
,BeanElement
,Element
,BeanDefinitionVisitor
,ClassOutputWriter
,OriginatingElements
,org.objectweb.asm.Opcodes
Responsible for building BeanDefinition
instances at compile time. Uses ASM build the class definition.
Should be used from AST frameworks to build bean definitions from source code data.
For example:
BeanDefinitionWriter writer = new BeanDefinitionWriter("my.package", "MyClass", "jakarta.inject.Singleton", true)
writer.visitBeanDefinitionConstructor()
writer.visitFieldInjectionPoint("my.Qualifier", false, "my.package.MyDependency", "myfield" )
writer.visitBeanDefinitionEnd()
writer.writeTo(new File(..))
- Since:
- 1.0
- Author:
- Graeme Rocher, Denis Stepanov
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Data used when visiting method. -
Field Summary
Fields inherited from class io.micronaut.inject.writer.AbstractClassFileWriter
ARRAY_PATTERN, CONSTRUCTOR_NAME, DEFAULT_MAX_STACK, DESCRIPTOR_DEFAULT_CONSTRUCTOR, METHOD_CREATE_ARGUMENT_SIMPLE, METHOD_CREATE_TYPE_VARIABLE_SIMPLE, METHOD_DEFAULT_CONSTRUCTOR, METHOD_GENERIC_PLACEHOLDER_SIMPLE, originatingElements, TYPE_ARGUMENT, TYPE_ARGUMENT_ARRAY, TYPE_CLASS, TYPE_GENERATED, TYPE_OBJECT, ZERO_ARGUMENTS_CONSTANT
Fields inherited from interface io.micronaut.core.annotation.AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBER
Fields inherited from interface io.micronaut.core.annotation.AnnotationSource
EMPTY
Fields inherited from interface io.micronaut.inject.writer.BeanDefinitionVisitor
PROXY_SUFFIX
Fields inherited from interface io.micronaut.inject.ast.Element
EMPTY_ELEMENT_ARRAY
Fields inherited from interface io.micronaut.inject.ast.annotation.MutableAnnotationMetadataDelegate
EMPTY
Fields inherited from interface org.objectweb.asm.Opcodes
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_MANDATED, ACC_MODULE, ACC_NATIVE, ACC_OPEN, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_RECORD, ACC_STATIC, ACC_STATIC_PHASE, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_TRANSITIVE, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASM10_EXPERIMENTAL, ASM4, ASM5, ASM6, ASM7, ASM8, ASM9, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, H_GETFIELD, H_GETSTATIC, H_INVOKEINTERFACE, H_INVOKESPECIAL, H_INVOKESTATIC, H_INVOKEVIRTUAL, H_NEWINVOKESPECIAL, H_PUTFIELD, H_PUTSTATIC, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INTEGER, INVOKEDYNAMIC, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SOURCE_DEPRECATED, SOURCE_MASK, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, UNINITIALIZED_THIS, V_PREVIEW, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7, V1_8, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V9
-
Constructor Summary
ConstructorDescriptionBeanDefinitionWriter
(ClassElement classElement, VisitorContext visitorContext) Creates a bean definition writer.BeanDefinitionWriter
(ClassElement classElement, OriginatingElements originatingElements, VisitorContext visitorContext) Creates a bean definition writer.BeanDefinitionWriter
(Element beanProducingElement, OriginatingElements originatingElements, VisitorContext visitorContext, @Nullable Integer uniqueIdentifier) Creates a bean definition writer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(ClassWriterOutputVisitor visitor) Write the class to output via a visitor that manages output destination.addAssociatedBean
(ClassElement type, VisitorContext visitorContext) This method adds an associated bean using this class element as the originating element.<T extends Annotation>
Elementannotate
(String annotationType, Consumer<AnnotationValueBuilder<T>> consumer) Annotate this element with the given annotation type.static void
finish()
Finish any work writing beans.Supplies the metadata.The type names produced by the bean.org.objectweb.asm.ClassVisitor
Returns the declaringClassElement
which may differ from theBeanElement.getBeanTypes()
in the case of factory beans.ReturnsExecutableMethodsDefinitionWriter
of one exists.Returns all injection points for the bean.Optional<org.objectweb.asm.Type>
getName()
Returns the native underlying type.Element[]
The element that produces the bean, this could be aClassElement
for regular beans, or either aMethodElement
orFieldElement
for factory beans.org.objectweb.asm.Type
The provided type of the bean.getScope()
The scope of the bean.boolean
boolean
boolean
boolean
boolean
Returns whether another bean exists that proxies this bean.boolean
Returns whether another bean is a proxy target that needs to be retained.boolean
isPublic()
boolean
boolean
removeAnnotation
(String annotationType) Removes an annotation of the given type from the element.<T extends Annotation>
ElementremoveAnnotationIf
(Predicate<AnnotationValue<T>> predicate) Removes all annotations that pass the given predicate.removeStereotype
(String annotationType) Removes a stereotype of the given name from the element.boolean
By default, when theBeanContext
is started, theBeanDefinition.getExecutableMethods()
are not processed by registeredExecutableMethodProcessor
instances unless this method returns true.void
setInterceptedType
(String typeName) Sets the name of the intercepted type.void
setProxiedBean
(boolean proxiedBean, boolean isProxyTarget) Sets whether this bean is a proxied type.void
setRequiresMethodProcessing
(boolean shouldPreProcess) Sets whether theBeanType.requiresMethodProcessing()
returns true.void
setValidated
(boolean validated) Make the bean definition as validated by jakarta.validation.byte[]
toString()
void
visitAnnotationMemberPropertyInjectionPoint
(TypedElement annotationMemberBeanType, String annotationMemberProperty, @Nullable String requiredValue, @Nullable String notEqualsValue) Visits an annotation injection point.void
visitBeanDefinitionConstructor
(MethodElement constructor, boolean requiresReflection, VisitorContext visitorContext) Visits the constructor used to create the bean definition.void
Finalize the bean definition to the given output stream.void
visitBeanDefinitionInterface
(Class<? extends BeanDefinition> interfaceType) Visit a marker interface on the generated bean definition.void
visitBeanFactoryField
(ClassElement factoryClass, FieldElement factoryField) In the case where the produced class is produced by a factory field annotated withBean
this method should be called.void
visitBeanFactoryMethod
(ClassElement factoryClass, MethodElement factoryMethod) In the case where the produced class is produced by a factory method annotated withBean
this method should be called.void
visitBeanFactoryMethod
(ClassElement factoryClass, MethodElement factoryMethod, ParameterElement[] parameters) In the case where the produced class is produced by a factory method annotated withBean
this method should be called.void
visitConfigBuilderDurationMethod
(String propertyName, ClassElement returnType, String methodName, String path) Visit a configuration builder method that accepts a long and a TimeUnit.void
Finalize a configuration builder field.void
visitConfigBuilderField
(ClassElement type, String field, AnnotationMetadata annotationMetadata, ConfigurationMetadataBuilder metadataBuilder, boolean isInterface) Begin defining a configuration builder.void
visitConfigBuilderMethod
(ClassElement type, String methodName, AnnotationMetadata annotationMetadata, ConfigurationMetadataBuilder metadataBuilder, boolean isInterface) Begin defining a configuration builder.void
visitConfigBuilderMethod
(String propertyName, ClassElement returnType, String methodName, ClassElement paramType, Map<String, ClassElement> generics, String path) Visit a configuration builder method.void
visitDefaultConstructor
(AnnotationMetadata annotationMetadata, VisitorContext visitorContext) Visits the constructor used to create the bean definition in the case where no constructor is present.int
visitExecutableMethod
(TypedElement declaringBean, MethodElement methodElement, VisitorContext visitorContext) Visit a method that is to be made executable allow invocation of said method without reflection.int
visitExecutableMethod
(TypedElement declaringType, MethodElement methodElement, String interceptedProxyClassName, String interceptedProxyBridgeMethodName) Visit a method that is to be made executable allow invocation of said method without reflection.void
visitFieldInjectionPoint
(TypedElement declaringType, FieldElement fieldElement, boolean requiresReflection, VisitorContext visitorContext) Visits a field injection point.void
visitFieldValue
(TypedElement declaringType, FieldElement fieldElement, boolean requiresReflection, boolean isOptional) Visits a field injection point.void
visitMethodInjectionPoint
(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, VisitorContext visitorContext) Visits a method injection point.void
visitPostConstructMethod
(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, VisitorContext visitorContext) Visits a method injection point.void
visitPreDestroyMethod
(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, VisitorContext visitorContext) Visits a method injection point.void
visitSetterValue
(TypedElement declaringType, MethodElement methodElement, AnnotationMetadata annotationMetadata, boolean requiresReflection, boolean isOptional) Visits an injection point for a setter.void
Alter the super class of this bean definition.void
visitSuperBeanDefinitionFactory
(String beanName) Alter the super class of this bean definition to use another factory bean.void
visitTypeArguments
(Map<String, Map<String, ClassElement>> typeArguments) Visits the type arguments for the bean.Methods inherited from class io.micronaut.inject.writer.AbstractClassFileWriter
addOriginatingElement, buildArgument, buildArgument, buildArgumentWithGenerics, buildArgumentWithGenerics, generateServiceDescriptor, getClassFileName, getConstructorDescriptor, getConstructorDescriptor, getConstructorDescriptor, getInternalName, getInternalNameForCast, getInternalNameForCast, getInternalNameForCast, getMethodDescriptor, getMethodDescriptor, getMethodDescriptor, getMethodDescriptor, getMethodDescriptorForReturnType, getMethodSignature, getObjectType, getOriginatingElement, getTypeDescriptor, getTypeDescriptor, getTypeDescriptor, getTypeDescriptor, getTypeReference, getTypeReferenceForName, getTypes, implementInterceptedTypeMethod, invokeConstructor, invokeInterfaceStaticMethod, invokeMethod, newClassWriterOutputVisitor, pushBoxPrimitiveIfNecessary, pushBoxPrimitiveIfNecessary, pushBoxPrimitiveIfNecessary, pushBuildArgumentsForMethod, pushCastToType, pushCastToType, pushCastToType, pushCreateArgument, pushListOfString, pushMethodNameAndTypesArguments, pushNewArray, pushNewArray, pushNewInstance, pushReturnTypeArgument, pushReturnValue, pushStoreInArray, pushStoreInArray, pushStoreStringInArray, pushStoreTypeInArray, pushStringMapOf, pushTypeArgumentElements, returnVoid, startClass, startClass, startConstructor, startConstructor, startFinalClass, startProtectedMethod, startPublicClass, startPublicFinalClass, startPublicFinalMethodZeroArgs, startPublicMethod, startPublicMethod, startPublicMethodZeroArgs, startService, startService, toTypeString, visitStaticInitializer, writeBooleanMethod, writeClassToDisk, writeClassToDisk, writeTo
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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
enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasEvaluatedExpressions, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresent
Methods inherited from interface io.micronaut.core.annotation.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, 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.writer.BeanDefinitionVisitor
getOriginatingElement, writeTo
Methods inherited from interface io.micronaut.inject.ast.beans.BeanElement
getOriginatingElement
Methods inherited from interface io.micronaut.inject.ast.Element
annotate, annotate, annotate, annotate, getDescription, getDescription, getDocumentation, getModifiers, getSimpleName, isFinal, isPackagePrivate, isPrivate, isStatic, isSynthetic, removeAnnotation, removeStereotype, withAnnotationMetadata
Methods inherited from interface io.micronaut.inject.writer.OriginatingElements
addOriginatingElement
-
Field Details
-
OMIT_CONFPROP_INJECTION_POINTS
- See Also:
-
CLASS_SUFFIX
- See Also:
-
-
Constructor Details
-
BeanDefinitionWriter
Creates a bean definition writer.- Parameters:
classElement
- The class elementvisitorContext
- The visitor context
-
BeanDefinitionWriter
public BeanDefinitionWriter(ClassElement classElement, OriginatingElements originatingElements, VisitorContext visitorContext) Creates a bean definition writer.- Parameters:
classElement
- The class elementoriginatingElements
- The originating elementsvisitorContext
- The visitor context
-
BeanDefinitionWriter
public BeanDefinitionWriter(Element beanProducingElement, OriginatingElements originatingElements, VisitorContext visitorContext, @Nullable @Nullable Integer uniqueIdentifier) Creates a bean definition writer.- Parameters:
beanProducingElement
- The bean producing elementoriginatingElements
- The originating elementsvisitorContext
- The visitor contextuniqueIdentifier
- An optional unique identifier to include in the bean name
-
-
Method Details
-
isEnabled
public boolean isEnabled()- Specified by:
isEnabled
in interfaceToggleable
- Returns:
- Whether the component is enabled
-
getExecutableMethodsWriter
ReturnsExecutableMethodsDefinitionWriter
of one exists.- Returns:
- An instance of
ExecutableMethodsDefinitionWriter
-
getTypeArguments
- Specified by:
getTypeArguments
in interfaceBeanDefinitionVisitor
- Returns:
- The generic type arguments for the bean type.
-
getTypeArgumentMap
- Specified by:
getTypeArgumentMap
in interfaceBeanDefinitionVisitor
- Returns:
- A map of the type arguments for the bean.
-
getBeanDefinitionReferenceClassName
- Specified by:
getBeanDefinitionReferenceClassName
in interfaceBeanDefinitionVisitor
- Returns:
- The name of the bean definition reference class.
-
getPostConstructMethodVisits
- Returns:
- The data for any post construct methods that were visited
-
getClassWriter
public org.objectweb.asm.ClassVisitor getClassWriter()- Returns:
- The underlying class writer
-
isInterface
public boolean isInterface()- Specified by:
isInterface
in interfaceBeanDefinitionVisitor
- Returns:
- Whether the provided type an interface
-
isSingleton
public boolean isSingleton()- Specified by:
isSingleton
in interfaceBeanDefinitionVisitor
- Returns:
- Is the bean singleton
-
visitBeanDefinitionInterface
Description copied from interface:BeanDefinitionVisitor
Visit a marker interface on the generated bean definition.- Specified by:
visitBeanDefinitionInterface
in interfaceBeanDefinitionVisitor
- Parameters:
interfaceType
- The interface type
-
visitSuperBeanDefinition
Description copied from interface:BeanDefinitionVisitor
Alter the super class of this bean definition. The passed class should be a subclass ofAbstractInitializableBeanDefinition
.- Specified by:
visitSuperBeanDefinition
in interfaceBeanDefinitionVisitor
- Parameters:
name
- The super type
-
visitSuperBeanDefinitionFactory
Description copied from interface:BeanDefinitionVisitor
Alter the super class of this bean definition to use another factory bean.- Specified by:
visitSuperBeanDefinitionFactory
in interfaceBeanDefinitionVisitor
- Parameters:
beanName
- The bean name
-
getBeanTypeName
- Specified by:
getBeanTypeName
in interfaceBeanDefinitionVisitor
- Returns:
- The full class name of the bean
-
getProvidedType
public org.objectweb.asm.Type getProvidedType()Description copied from interface:BeanDefinitionVisitor
The provided type of the bean. Usually this is the same asBeanDefinitionVisitor.getBeanTypeName()
, except in the case of factory beans which produce a different type.- Specified by:
getProvidedType
in interfaceBeanDefinitionVisitor
- Returns:
- The provided type
-
setValidated
public void setValidated(boolean validated) Description copied from interface:BeanDefinitionVisitor
Make the bean definition as validated by jakarta.validation.- Specified by:
setValidated
in interfaceBeanDefinitionVisitor
- Parameters:
validated
- Whether the bean definition is validated
-
setInterceptedType
Description copied from interface:BeanDefinitionVisitor
Sets the name of the intercepted type.- Specified by:
setInterceptedType
in interfaceBeanDefinitionVisitor
- Parameters:
typeName
- The type name
-
getInterceptedType
- Specified by:
getInterceptedType
in interfaceBeanDefinitionVisitor
- Returns:
- The intercepted type
-
isValidated
public boolean isValidated()- Specified by:
isValidated
in interfaceBeanDefinitionVisitor
- Returns:
- Return whether the bean definition is validated.
-
getBeanDefinitionName
- Specified by:
getBeanDefinitionName
in interfaceBeanDefinitionVisitor
- Returns:
- The name of the bean definition class
-
visitBeanFactoryMethod
In the case where the produced class is produced by a factory method annotated with
Bean
this method should be called.- Specified by:
visitBeanFactoryMethod
in interfaceBeanDefinitionVisitor
- Parameters:
factoryClass
- The factory classfactoryMethod
- The factory method
-
visitBeanFactoryMethod
public void visitBeanFactoryMethod(ClassElement factoryClass, MethodElement factoryMethod, ParameterElement[] parameters) In the case where the produced class is produced by a factory method annotated with
Bean
this method should be called.- Specified by:
visitBeanFactoryMethod
in interfaceBeanDefinitionVisitor
- Parameters:
factoryClass
- The factory classfactoryMethod
- The factory methodparameters
- The parameters
-
visitBeanFactoryField
In the case where the produced class is produced by a factory field annotated with
Bean
this method should be called.- Specified by:
visitBeanFactoryField
in interfaceBeanDefinitionVisitor
- Parameters:
factoryClass
- The factory classfactoryField
- The factory field
-
visitBeanDefinitionConstructor
public void visitBeanDefinitionConstructor(MethodElement constructor, boolean requiresReflection, VisitorContext visitorContext) Visits the constructor used to create the bean definition.- Specified by:
visitBeanDefinitionConstructor
in interfaceBeanDefinitionVisitor
- Parameters:
constructor
- The constructorrequiresReflection
- Whether invoking the constructor requires reflectionvisitorContext
- The visitor context
-
visitDefaultConstructor
public void visitDefaultConstructor(AnnotationMetadata annotationMetadata, VisitorContext visitorContext) Description copied from interface:BeanDefinitionVisitor
Visits the constructor used to create the bean definition in the case where no constructor is present. This method should only be called in the class defines no constructor.- Specified by:
visitDefaultConstructor
in interfaceBeanDefinitionVisitor
- Parameters:
annotationMetadata
- The annotation metadata for the constructorvisitorContext
- The visitor context
-
visitBeanDefinitionEnd
public void visitBeanDefinitionEnd()Finalize the bean definition to the given output stream.- Specified by:
visitBeanDefinitionEnd
in interfaceBeanDefinitionVisitor
-
toByteArray
public byte[] toByteArray()- Returns:
- The bytes of the class
-
accept
Description copied from interface:BeanDefinitionVisitor
Write the class to output via a visitor that manages output destination.- Specified by:
accept
in interfaceBeanDefinitionVisitor
- Specified by:
accept
in interfaceClassOutputWriter
- Parameters:
visitor
- the writer output visitor- Throws:
IOException
- If an error occurs
-
visitSetterValue
public void visitSetterValue(TypedElement declaringType, MethodElement methodElement, AnnotationMetadata annotationMetadata, boolean requiresReflection, boolean isOptional) Description copied from interface:BeanDefinitionVisitor
Visits an injection point for a setter.- Specified by:
visitSetterValue
in interfaceBeanDefinitionVisitor
- Parameters:
declaringType
- The declaring typemethodElement
- The method elementannotationMetadata
- The annotationMetadatarequiresReflection
- Whether the setter requires reflectionisOptional
- Whether the setter is optional
-
visitPostConstructMethod
public void visitPostConstructMethod(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, VisitorContext visitorContext) Description copied from interface:BeanDefinitionVisitor
Visits a method injection point.- Specified by:
visitPostConstructMethod
in interfaceBeanDefinitionVisitor
- Parameters:
declaringType
- The declaring type of the method. Either a Class or a string representing the name of the typemethodElement
- The method elementrequiresReflection
- Whether the method requires reflectionvisitorContext
- The visitor context
-
visitPreDestroyMethod
public void visitPreDestroyMethod(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, VisitorContext visitorContext) Description copied from interface:BeanDefinitionVisitor
Visits a method injection point.- Specified by:
visitPreDestroyMethod
in interfaceBeanDefinitionVisitor
- Parameters:
declaringType
- The bean type of the methodmethodElement
- The method elementrequiresReflection
- Whether the method requires reflectionvisitorContext
- The visitor context
-
visitMethodInjectionPoint
public void visitMethodInjectionPoint(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, VisitorContext visitorContext) Description copied from interface:BeanDefinitionVisitor
Visits a method injection point.- Specified by:
visitMethodInjectionPoint
in interfaceBeanDefinitionVisitor
- Parameters:
declaringType
- The bean type of the methodmethodElement
- The method elementrequiresReflection
- Whether the method requires reflectionvisitorContext
- The visitor context
-
visitExecutableMethod
public int visitExecutableMethod(TypedElement declaringBean, MethodElement methodElement, VisitorContext visitorContext) Description copied from interface:BeanDefinitionVisitor
Visit a method that is to be made executable allow invocation of said method without reflection.- Specified by:
visitExecutableMethod
in interfaceBeanDefinitionVisitor
- Parameters:
declaringBean
- The declaring bean of the method. Note this may differ fromMemberElement.getDeclaringType()
in the case of the method coming from a super class or interface.methodElement
- The method elementvisitorContext
- The visitor context- Returns:
- The index of a new method
-
visitExecutableMethod
public int visitExecutableMethod(TypedElement declaringType, MethodElement methodElement, String interceptedProxyClassName, String interceptedProxyBridgeMethodName) Visit a method that is to be made executable allow invocation of said method without reflection.- Parameters:
declaringType
- The declaring type of the method. Either a Class or a string representing the name of the typemethodElement
- The method elementinterceptedProxyClassName
- The intercepted proxy class nameinterceptedProxyBridgeMethodName
- The intercepted proxy bridge method name- Returns:
- The index of a new method.
-
toString
-
getPackageName
- Specified by:
getPackageName
in interfaceBeanDefinitionVisitor
- Returns:
- The package name of the bean
-
getBeanSimpleName
- Specified by:
getBeanSimpleName
in interfaceBeanDefinitionVisitor
- Returns:
- The short name of the bean
-
getAnnotationMetadata
Description copied from interface:AnnotationMetadataProvider
Supplies the metadata. Defaults toAnnotationMetadata.EMPTY_METADATA
.- Specified by:
getAnnotationMetadata
in interfaceAnnotationMetadataProvider
- Specified by:
getAnnotationMetadata
in interfaceBeanDefinitionVisitor
- Returns:
- The annotation metadata
-
visitConfigBuilderField
public void visitConfigBuilderField(ClassElement type, String field, AnnotationMetadata annotationMetadata, ConfigurationMetadataBuilder metadataBuilder, boolean isInterface) Description copied from interface:BeanDefinitionVisitor
Begin defining a configuration builder.- Specified by:
visitConfigBuilderField
in interfaceBeanDefinitionVisitor
- Parameters:
type
- The type of the builderfield
- The name of the field that represents the builderannotationMetadata
- The annotation metadata associated with the fieldmetadataBuilder
- TheConfigurationMetadataBuilder
isInterface
- Whether the builder type is an interface or not- See Also:
-
visitConfigBuilderMethod
public void visitConfigBuilderMethod(ClassElement type, String methodName, AnnotationMetadata annotationMetadata, ConfigurationMetadataBuilder metadataBuilder, boolean isInterface) Description copied from interface:BeanDefinitionVisitor
Begin defining a configuration builder.- Specified by:
visitConfigBuilderMethod
in interfaceBeanDefinitionVisitor
- Parameters:
type
- The type of the buildermethodName
- The name of the method that returns the builderannotationMetadata
- The annotation metadata associated with the fieldmetadataBuilder
- TheConfigurationMetadataBuilder
isInterface
- Whether the builder type is an interface or not- See Also:
-
visitConfigBuilderDurationMethod
public void visitConfigBuilderDurationMethod(String propertyName, ClassElement returnType, String methodName, String path) Description copied from interface:BeanDefinitionVisitor
Visit a configuration builder method that accepts a long and a TimeUnit.- Specified by:
visitConfigBuilderDurationMethod
in interfaceBeanDefinitionVisitor
- Parameters:
propertyName
- The property namereturnType
- The return typemethodName
- The method namepath
- The property path- See Also:
-
visitConfigBuilderMethod
public void visitConfigBuilderMethod(String propertyName, ClassElement returnType, String methodName, ClassElement paramType, Map<String, ClassElement> generics, String path) Description copied from interface:BeanDefinitionVisitor
Visit a configuration builder method.- Specified by:
visitConfigBuilderMethod
in interfaceBeanDefinitionVisitor
- Parameters:
propertyName
- The property namereturnType
- The return typemethodName
- The method nameparamType
- The method typegenerics
- The generic types of the methodpath
- The property path- See Also:
-
visitConfigBuilderEnd
public void visitConfigBuilderEnd()Description copied from interface:BeanDefinitionVisitor
Finalize a configuration builder field.- Specified by:
visitConfigBuilderEnd
in interfaceBeanDefinitionVisitor
- See Also:
-
setRequiresMethodProcessing
public void setRequiresMethodProcessing(boolean shouldPreProcess) Description copied from interface:BeanDefinitionVisitor
Sets whether theBeanType.requiresMethodProcessing()
returns true.- Specified by:
setRequiresMethodProcessing
in interfaceBeanDefinitionVisitor
- Parameters:
shouldPreProcess
- True if they should be pre-processed
-
visitTypeArguments
Description copied from interface:BeanDefinitionVisitor
Visits the type arguments for the bean.- Specified by:
visitTypeArguments
in interfaceBeanDefinitionVisitor
- Parameters:
typeArguments
- The type arguments
-
requiresMethodProcessing
public boolean requiresMethodProcessing()Description copied from interface:BeanDefinitionVisitor
By default, when theBeanContext
is started, theBeanDefinition.getExecutableMethods()
are not processed by registeredExecutableMethodProcessor
instances unless this method returns true.- Specified by:
requiresMethodProcessing
in interfaceBeanDefinitionVisitor
- Returns:
- Whether the bean definition requires method processing
- See Also:
-
visitFieldInjectionPoint
public void visitFieldInjectionPoint(TypedElement declaringType, FieldElement fieldElement, boolean requiresReflection, VisitorContext visitorContext) Description copied from interface:BeanDefinitionVisitor
Visits a field injection point.- Specified by:
visitFieldInjectionPoint
in interfaceBeanDefinitionVisitor
- Parameters:
declaringType
- The declaring type. Either a Class or a string representing the name of the typefieldElement
- The field elementrequiresReflection
- Whether accessing the field requires reflectionvisitorContext
- The visitor context
-
visitAnnotationMemberPropertyInjectionPoint
public void visitAnnotationMemberPropertyInjectionPoint(TypedElement annotationMemberBeanType, String annotationMemberProperty, @Nullable @Nullable String requiredValue, @Nullable @Nullable String notEqualsValue) Description copied from interface:BeanDefinitionVisitor
Visits an annotation injection point.- Specified by:
visitAnnotationMemberPropertyInjectionPoint
in interfaceBeanDefinitionVisitor
- Parameters:
annotationMemberBeanType
- The type of the injected beanannotationMemberProperty
- Required property of the injected beanrequiredValue
- Required value of the bean property for the bean to be loadednotEqualsValue
- The bean property value which should not be equal to present value for the bean to be loaded
-
visitFieldValue
public void visitFieldValue(TypedElement declaringType, FieldElement fieldElement, boolean requiresReflection, boolean isOptional) Description copied from interface:BeanDefinitionVisitor
Visits a field injection point.- Specified by:
visitFieldValue
in interfaceBeanDefinitionVisitor
- Parameters:
declaringType
- The declaring type. Either a Class or a string representing the name of the typefieldElement
- The field elementrequiresReflection
- Whether accessing the field requires reflectionisOptional
- Is the value optional
-
getName
-
isProtected
public boolean isProtected()- Specified by:
isProtected
in interfaceElement
- Returns:
- True if the element is protected.
-
isPublic
public boolean isPublic() -
getNativeType
Description copied from interface:Element
Returns the native underlying type. This API is extended by all inject language implementations. The object returned by this method will be the language native type the information is being retrieved from.- Specified by:
getNativeType
in interfaceElement
- Returns:
- The native type
-
getInjectionPoints
Description copied from interface:BeanElement
Returns all injection points for the bean. These will be a combination ofFieldElement
andMethodElement
instances.- Specified by:
getInjectionPoints
in interfaceBeanElement
- Returns:
- The injection points for the bean.
-
isAbstract
public boolean isAbstract()- Specified by:
isAbstract
in interfaceElement
- Returns:
- True if the element is abstract.
-
annotate
public <T extends Annotation> Element annotate(String annotationType, Consumer<AnnotationValueBuilder<T>> consumer) Description copied from interface:MutableAnnotationMetadataDelegate
Annotate 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:
annotate
in interfaceElement
- Specified by:
annotate
in interfaceMutableAnnotationMetadataDelegate<Element>
- Type Parameters:
T
- The annotation generic type- Parameters:
annotationType
- The annotation typeconsumer
- A function that receives theAnnotationValueBuilder
- Returns:
- This element
-
removeAnnotation
Description copied from interface:MutableAnnotationMetadataDelegate
Removes 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:
removeAnnotation
in interfaceElement
- Specified by:
removeAnnotation
in interfaceMutableAnnotationMetadataDelegate<Element>
- Parameters:
annotationType
- The annotation type- Returns:
- This element
-
removeAnnotationIf
Description copied from interface:MutableAnnotationMetadataDelegate
Removes all annotations that pass the given predicate.- Specified by:
removeAnnotationIf
in interfaceElement
- Specified by:
removeAnnotationIf
in interfaceMutableAnnotationMetadataDelegate<Element>
- Type Parameters:
T
- The annotation generic type- Parameters:
predicate
- The predicate- Returns:
- This element
-
removeStereotype
Description copied from interface:MutableAnnotationMetadataDelegate
Removes a stereotype of the given name from the element.- Specified by:
removeStereotype
in interfaceElement
- Specified by:
removeStereotype
in interfaceMutableAnnotationMetadataDelegate<Element>
- Parameters:
annotationType
- The annotation type- Returns:
- This element
-
getDeclaringClass
Description copied from interface:BeanElement
Returns the declaringClassElement
which may differ from theBeanElement.getBeanTypes()
in the case of factory beans.- Specified by:
getDeclaringClass
in interfaceBeanElement
- Returns:
- The declaring class of the bean.
-
getProducingElement
Description copied from interface:BeanElement
The element that produces the bean, this could be aClassElement
for regular beans, or either aMethodElement
orFieldElement
for factory beans.- Specified by:
getProducingElement
in interfaceBeanElement
- Returns:
- The producing element
-
getBeanTypes
Description copied from interface:BeanElement
The type names produced by the bean.- Specified by:
getBeanTypes
in interfaceBeanElement
- Returns:
- A set of types
-
getScope
Description copied from interface:BeanElement
The scope of the bean.- Specified by:
getScope
in interfaceBeanElement
- Returns:
- The fully qualified name of the scope or empty if no scope is defined.
-
getQualifiers
- Specified by:
getQualifiers
in interfaceBeanElement
- Returns:
- One or more fully qualified qualifier types defined by the bean.
-
addAssociatedBean
Description copied from interface:BeanElement
This method adds an associated bean using this class element as the originating element.Note that this method can only be called on classes being directly compiled by Micronaut. If the ClassElement is loaded from pre-compiled code an
UnsupportedOperationException
will be thrown.- Specified by:
addAssociatedBean
in interfaceBeanElement
- Parameters:
type
- The type of the beanvisitorContext
- The visitor context- Returns:
- A bean builder
-
getOriginatingElements
- Specified by:
getOriginatingElements
in interfaceOriginatingElements
- Overrides:
getOriginatingElements
in classAbstractClassFileWriter
- Returns:
- The elements where the bean definition originated from as an array.
-
setProxiedBean
public void setProxiedBean(boolean proxiedBean, boolean isProxyTarget) Sets whether this bean is a proxied type.- Parameters:
proxiedBean
- True if it proxiedisProxyTarget
- True if the proxied bean is a retained target
-
isProxyTarget
public boolean isProxyTarget()Description copied from interface:BeanDefinitionVisitor
Returns whether another bean is a proxy target that needs to be retained.- Specified by:
isProxyTarget
in interfaceBeanDefinitionVisitor
- Returns:
- Is the reference a proxy target.
-
isProxiedBean
public boolean isProxiedBean()Description copied from interface:BeanDefinitionVisitor
Returns whether another bean exists that proxies this bean. In other words this bean is the target of a proxy.- Specified by:
isProxiedBean
in interfaceBeanDefinitionVisitor
- Returns:
- Is the reference a proxy target.
-
finish
Finish any work writing beans.
-