Class BeanDefinitionWriter
- java.lang.Object
-
- io.micronaut.inject.writer.AbstractClassFileWriter
-
- io.micronaut.inject.writer.BeanDefinitionWriter
-
- 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
,io.micronaut.core.util.Toggleable
,BeanElement
,Element
,BeanDefinitionVisitor
,ClassOutputWriter
,OriginatingElements
,org.objectweb.asm.Opcodes
@Internal public class BeanDefinitionWriter extends AbstractClassFileWriter implements BeanDefinitionVisitor, BeanElement, io.micronaut.core.util.Toggleable
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", "javax.inject.Singleton", true) writer.visitBeanDefinitionConstructor() writer.visitFieldInjectionPoint("my.Qualifier", false, "my.package.MyDependency", "myfield" ) writer.visitBeanDefinitionEnd() writer.writeTo(new File(..))
- Since:
- 1.0
- See Also:
BeanDefinition
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BeanDefinitionWriter.MethodVisitData
Data used when visiting method.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CLASS_SUFFIX
static java.lang.String
OMIT_CONFPROP_INJECTION_POINTS
-
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.inject.writer.BeanDefinitionVisitor
PROXY_SUFFIX
-
Fields inherited from interface io.micronaut.inject.ast.Element
EMPTY_ELEMENT_ARRAY
-
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, V9
-
-
Constructor Summary
Constructors Constructor Description BeanDefinitionWriter(ClassElement classElement, ConfigurationMetadataBuilder<?> metadataBuilder, VisitorContext visitorContext)
Creates a bean definition writer.BeanDefinitionWriter(ClassElement classElement, OriginatingElements originatingElements, ConfigurationMetadataBuilder<?> metadataBuilder, VisitorContext visitorContext)
Creates a bean definition writer.BeanDefinitionWriter(Element beanProducingElement, OriginatingElements originatingElements, ConfigurationMetadataBuilder<?> metadataBuilder, VisitorContext visitorContext, java.lang.Integer uniqueIdentifier)
Creates a bean definition writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(ClassWriterOutputVisitor visitor)
Write the class to output via a visitor that manages output destination.BeanElementBuilder
addAssociatedBean(ClassElement type, VisitorContext visitorContext)
This method adds an associated bean using this class element as the originating element.<T extends java.lang.annotation.Annotation>
Elementannotate(java.lang.String annotationType, java.util.function.Consumer<io.micronaut.core.annotation.AnnotationValueBuilder<T>> consumer)
Annotate this element with the given annotation type.io.micronaut.core.annotation.AnnotationMetadata
getAnnotationMetadata()
java.lang.String
getBeanDefinitionName()
java.lang.String
getBeanDefinitionReferenceClassName()
java.lang.String
getBeanSimpleName()
java.lang.String
getBeanTypeName()
java.util.Set<ClassElement>
getBeanTypes()
The type names produced by the bean.org.objectweb.asm.ClassVisitor
getClassWriter()
ClassElement
getDeclaringClass()
Returns the declaringClassElement
which may differ from theBeanElement.getBeanTypes()
in the case of factory beans.ExecutableMethodsDefinitionWriter
getExecutableMethodsWriter()
ReturnsExecutableMethodsDefinitionWriter
of one exists.java.util.Collection<Element>
getInjectionPoints()
Returns all of the injection points for the bean.java.util.Optional<org.objectweb.asm.Type>
getInterceptedType()
java.lang.String
getName()
java.lang.Object
getNativeType()
Returns the native underlying type.Element[]
getOriginatingElements()
java.lang.String
getPackageName()
java.util.List<BeanDefinitionWriter.MethodVisitData>
getPostConstructMethodVisits()
Element
getProducingElement()
The element that produces the bean, this could be aClassElement
for regular beans, or either aMethodElement
orFieldElement
for factory beans.org.objectweb.asm.Type
getProvidedType()
The provided type of the bean.java.util.Collection<java.lang.String>
getQualifiers()
java.util.Optional<java.lang.String>
getScope()
The scope of the bean.ClassElement[]
getTypeArguments()
boolean
isAbstract()
boolean
isEnabled()
boolean
isInterface()
boolean
isProtected()
boolean
isPublic()
boolean
isSingleton()
boolean
isValidated()
Element
removeAnnotation(java.lang.String annotationType)
Removes an annotation of the given type from the element.<T extends java.lang.annotation.Annotation>
ElementremoveAnnotationIf(java.util.function.Predicate<io.micronaut.core.annotation.AnnotationValue<T>> predicate)
Removes all annotations that pass the given predicate.Element
removeStereotype(java.lang.String annotationType)
Removes a stereotype of the given name from the element.boolean
requiresMethodProcessing()
By default, when theBeanContext
is started, theBeanDefinition.getExecutableMethods()
are not processed by registeredExecutableMethodProcessor
instances unless this method returns true.void
setInterceptedType(java.lang.String typeName)
Sets the name of the intercepted type.void
setRequiresMethodProcessing(boolean shouldPreProcess)
Sets whether theBeanType.requiresMethodProcessing()
returns true.void
setValidated(boolean validated)
Make the bean definition as validated by javax.validation.byte[]
toByteArray()
java.lang.String
toString()
void
visitAnnotationMemberPropertyInjectionPoint(TypedElement annotationMemberBeanType, java.lang.String annotationMemberProperty, java.lang.String requiredValue, java.lang.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
visitBeanDefinitionEnd()
Finalize the bean definition to the given output stream.void
visitBeanDefinitionInterface(java.lang.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(java.lang.String prefix, ClassElement returnType, java.lang.String methodName, java.lang.String path)
Visit a configuration builder method that accepts a long and a TimeUnit.void
visitConfigBuilderEnd()
Finalize a configuration builder field.void
visitConfigBuilderField(ClassElement type, java.lang.String field, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, ConfigurationMetadataBuilder metadataBuilder, boolean isInterface)
Begin defining a configuration builder.void
visitConfigBuilderMethod(ClassElement type, java.lang.String methodName, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, ConfigurationMetadataBuilder metadataBuilder, boolean isInterface)
Begin defining a configuration builder.void
visitConfigBuilderMethod(java.lang.String prefix, ClassElement returnType, java.lang.String methodName, ClassElement paramType, java.util.Map<java.lang.String,ClassElement> generics, java.lang.String path)
Visit a configuration builder method.void
visitDefaultConstructor(io.micronaut.core.annotation.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, java.lang.String interceptedProxyClassName, java.lang.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)
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, boolean requiresReflection, boolean isOptional)
Visits an injection point for a setter.void
visitSuperBeanDefinition(java.lang.String name)
Alter the super class of this bean definition.void
visitSuperBeanDefinitionFactory(java.lang.String beanName)
Alter the super class of this bean definition to use another factory bean.void
visitTypeArguments(java.util.Map<java.lang.String,java.util.Map<java.lang.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, 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, 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
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.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, removeAnnotation, removeStereotype
-
Methods inherited from interface io.micronaut.inject.writer.OriginatingElements
addOriginatingElement
-
-
-
-
Field Detail
-
OMIT_CONFPROP_INJECTION_POINTS
public static final java.lang.String OMIT_CONFPROP_INJECTION_POINTS
- See Also:
- Constant Field Values
-
CLASS_SUFFIX
public static final java.lang.String CLASS_SUFFIX
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BeanDefinitionWriter
public BeanDefinitionWriter(ClassElement classElement, ConfigurationMetadataBuilder<?> metadataBuilder, VisitorContext visitorContext)
Creates a bean definition writer.- Parameters:
classElement
- The class elementmetadataBuilder
- The configuration metadata buildervisitorContext
- The visitor context
-
BeanDefinitionWriter
public BeanDefinitionWriter(ClassElement classElement, OriginatingElements originatingElements, ConfigurationMetadataBuilder<?> metadataBuilder, VisitorContext visitorContext)
Creates a bean definition writer.- Parameters:
classElement
- The class elementoriginatingElements
- The originating elementsmetadataBuilder
- The configuration metadata buildervisitorContext
- The visitor context
-
BeanDefinitionWriter
public BeanDefinitionWriter(Element beanProducingElement, OriginatingElements originatingElements, ConfigurationMetadataBuilder<?> metadataBuilder, VisitorContext visitorContext, @Nullable java.lang.Integer uniqueIdentifier)
Creates a bean definition writer.- Parameters:
beanProducingElement
- The bean producing elementoriginatingElements
- The originating elementsmetadataBuilder
- The configuration metadata buildervisitorContext
- The visitor contextuniqueIdentifier
- An optional unique identifier to include in the bean name
-
-
Method Detail
-
isEnabled
public boolean isEnabled()
- Specified by:
isEnabled
in interfaceio.micronaut.core.util.Toggleable
-
getExecutableMethodsWriter
@Nullable public ExecutableMethodsDefinitionWriter getExecutableMethodsWriter()
ReturnsExecutableMethodsDefinitionWriter
of one exists.- Returns:
- An instance of
ExecutableMethodsDefinitionWriter
-
getTypeArguments
@NonNull public ClassElement[] getTypeArguments()
- Specified by:
getTypeArguments
in interfaceBeanDefinitionVisitor
- Returns:
- The generic type arguments for the bean type.
-
getBeanDefinitionReferenceClassName
@NonNull public java.lang.String getBeanDefinitionReferenceClassName()
- Specified by:
getBeanDefinitionReferenceClassName
in interfaceBeanDefinitionVisitor
- Returns:
- The name of the bean definition reference class.
-
getPostConstructMethodVisits
public final java.util.List<BeanDefinitionWriter.MethodVisitData> 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
public void visitBeanDefinitionInterface(java.lang.Class<? extends BeanDefinition> interfaceType)
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
public void visitSuperBeanDefinition(java.lang.String name)
Description copied from interface:BeanDefinitionVisitor
Alter the super class of this bean definition. The passed class should be a subclass ofAbstractBeanDefinition
.- Specified by:
visitSuperBeanDefinition
in interfaceBeanDefinitionVisitor
- Parameters:
name
- The super type
-
visitSuperBeanDefinitionFactory
public void visitSuperBeanDefinitionFactory(java.lang.String beanName)
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
public java.lang.String 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 javax.validation.- Specified by:
setValidated
in interfaceBeanDefinitionVisitor
- Parameters:
validated
- Whether the bean definition is validated
-
setInterceptedType
public void setInterceptedType(java.lang.String typeName)
Description copied from interface:BeanDefinitionVisitor
Sets the name of the intercepted type.- Specified by:
setInterceptedType
in interfaceBeanDefinitionVisitor
- Parameters:
typeName
- The type name
-
getInterceptedType
public java.util.Optional<org.objectweb.asm.Type> 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
public java.lang.String getBeanDefinitionName()
- Specified by:
getBeanDefinitionName
in interfaceBeanDefinitionVisitor
- Returns:
- The name of the bean definition class
-
visitBeanFactoryMethod
public void visitBeanFactoryMethod(ClassElement factoryClass, MethodElement factoryMethod)
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
public void visitBeanFactoryField(ClassElement factoryClass, FieldElement factoryField)
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(io.micronaut.core.annotation.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
public void accept(ClassWriterOutputVisitor visitor) throws java.io.IOException
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:
java.io.IOException
- If an error occurs
-
visitSetterValue
public void visitSetterValue(TypedElement declaringType, MethodElement methodElement, 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 elementrequiresReflection
- 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, java.lang.String interceptedProxyClassName, java.lang.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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getPackageName
public java.lang.String getPackageName()
- Specified by:
getPackageName
in interfaceBeanDefinitionVisitor
- Returns:
- The package name of the bean
-
getBeanSimpleName
public java.lang.String getBeanSimpleName()
- Specified by:
getBeanSimpleName
in interfaceBeanDefinitionVisitor
- Returns:
- The short name of the bean
-
getAnnotationMetadata
public io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata()
- Specified by:
getAnnotationMetadata
in interfaceio.micronaut.core.annotation.AnnotationMetadataProvider
- Specified by:
getAnnotationMetadata
in interfaceBeanDefinitionVisitor
- Returns:
- The annotation metadata
-
visitConfigBuilderField
public void visitConfigBuilderField(ClassElement type, java.lang.String field, io.micronaut.core.annotation.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:
ConfigurationBuilder
-
visitConfigBuilderMethod
public void visitConfigBuilderMethod(ClassElement type, java.lang.String methodName, io.micronaut.core.annotation.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:
ConfigurationBuilder
-
visitConfigBuilderDurationMethod
public void visitConfigBuilderDurationMethod(java.lang.String prefix, ClassElement returnType, java.lang.String methodName, java.lang.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:
prefix
- The prefix used for the methodreturnType
- The return typemethodName
- The method namepath
- The property path- See Also:
ConfigurationBuilder
-
visitConfigBuilderMethod
public void visitConfigBuilderMethod(java.lang.String prefix, ClassElement returnType, java.lang.String methodName, ClassElement paramType, java.util.Map<java.lang.String,ClassElement> generics, java.lang.String path)
Description copied from interface:BeanDefinitionVisitor
Visit a configuration builder method.- Specified by:
visitConfigBuilderMethod
in interfaceBeanDefinitionVisitor
- Parameters:
prefix
- The prefix used for the methodreturnType
- The return typemethodName
- The method nameparamType
- The method typegenerics
- The generic types of the methodpath
- The property path- See Also:
ConfigurationBuilder
-
visitConfigBuilderEnd
public void visitConfigBuilderEnd()
Description copied from interface:BeanDefinitionVisitor
Finalize a configuration builder field.- Specified by:
visitConfigBuilderEnd
in interfaceBeanDefinitionVisitor
- See Also:
ConfigurationBuilder
-
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
public void visitTypeArguments(java.util.Map<java.lang.String,java.util.Map<java.lang.String,ClassElement>> typeArguments)
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:
Executable.processOnStartup()
-
visitFieldInjectionPoint
public void visitFieldInjectionPoint(TypedElement declaringType, FieldElement fieldElement, boolean requiresReflection)
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 reflection
-
visitAnnotationMemberPropertyInjectionPoint
public void visitAnnotationMemberPropertyInjectionPoint(TypedElement annotationMemberBeanType, java.lang.String annotationMemberProperty, @Nullable java.lang.String requiredValue, @Nullable java.lang.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
public java.lang.String getName()
-
isProtected
public boolean isProtected()
- Specified by:
isProtected
in interfaceElement
- Returns:
- True if the element is protected.
-
isPublic
public boolean isPublic()
-
getNativeType
public java.lang.Object getNativeType()
Description copied from interface:Element
Returns 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:
getNativeType
in interfaceElement
- Returns:
- The native type
-
getInjectionPoints
public java.util.Collection<Element> getInjectionPoints()
Description copied from interface:BeanElement
Returns all of the 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 java.lang.annotation.Annotation> Element annotate(java.lang.String annotationType, java.util.function.Consumer<io.micronaut.core.annotation.AnnotationValueBuilder<T>> consumer)
Description copied from interface:Element
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.
-
removeAnnotation
public Element removeAnnotation(java.lang.String annotationType)
Description copied from interface:Element
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
- Parameters:
annotationType
- The annotation type- Returns:
- This element
-
removeAnnotationIf
public <T extends java.lang.annotation.Annotation> Element removeAnnotationIf(java.util.function.Predicate<io.micronaut.core.annotation.AnnotationValue<T>> predicate)
Description copied from interface:Element
Removes all annotations that pass the given predicate.- Specified by:
removeAnnotationIf
in interfaceElement
- Type Parameters:
T
- The annotation generic type- Parameters:
predicate
- The predicate- Returns:
- This element
-
removeStereotype
public Element removeStereotype(java.lang.String annotationType)
Description copied from interface:Element
Removes a stereotype of the given name from the element.- Specified by:
removeStereotype
in interfaceElement
- Parameters:
annotationType
- The annotation type- Returns:
- This element
-
getDeclaringClass
public ClassElement 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
public Element 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
public java.util.Set<ClassElement> getBeanTypes()
Description copied from interface:BeanElement
The type names produced by the bean.- Specified by:
getBeanTypes
in interfaceBeanElement
- Returns:
- A set of types
-
getScope
public java.util.Optional<java.lang.String> 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
public java.util.Collection<java.lang.String> getQualifiers()
- Specified by:
getQualifiers
in interfaceBeanElement
- Returns:
- One or more fully qualified qualifier types defined by the bean.
-
addAssociatedBean
public BeanElementBuilder addAssociatedBean(ClassElement type, VisitorContext visitorContext)
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
public Element[] getOriginatingElements()
- Specified by:
getOriginatingElements
in interfaceOriginatingElements
- Overrides:
getOriginatingElements
in classAbstractClassFileWriter
- Returns:
- The elements where the bean definition originated from as an array.
-
-