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
BeanDefinitioninstances 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 classBeanDefinitionWriter.MethodVisitDataData used when visiting method.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCLASS_SUFFIXstatic java.lang.StringOMIT_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 voidaccept(ClassWriterOutputVisitor visitor)Write the class to output via a visitor that manages output destination.BeanElementBuilderaddAssociatedBean(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.AnnotationMetadatagetAnnotationMetadata()java.lang.StringgetBeanDefinitionName()java.lang.StringgetBeanDefinitionReferenceClassName()java.lang.StringgetBeanSimpleName()java.lang.StringgetBeanTypeName()java.util.Set<ClassElement>getBeanTypes()The type names produced by the bean.org.objectweb.asm.ClassVisitorgetClassWriter()ClassElementgetDeclaringClass()Returns the declaringClassElementwhich may differ from theBeanElement.getBeanTypes()in the case of factory beans.ExecutableMethodsDefinitionWritergetExecutableMethodsWriter()ReturnsExecutableMethodsDefinitionWriterof 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.StringgetName()java.lang.ObjectgetNativeType()Returns the native underlying type.Element[]getOriginatingElements()java.lang.StringgetPackageName()java.util.List<BeanDefinitionWriter.MethodVisitData>getPostConstructMethodVisits()ElementgetProducingElement()The element that produces the bean, this could be aClassElementfor regular beans, or either aMethodElementorFieldElementfor factory beans.org.objectweb.asm.TypegetProvidedType()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()booleanisAbstract()booleanisEnabled()booleanisInterface()booleanisProtected()booleanisPublic()booleanisSingleton()booleanisValidated()ElementremoveAnnotation(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.ElementremoveStereotype(java.lang.String annotationType)Removes a stereotype of the given name from the element.booleanrequiresMethodProcessing()By default, when theBeanContextis started, theBeanDefinition.getExecutableMethods()are not processed by registeredExecutableMethodProcessorinstances unless this method returns true.voidsetInterceptedType(java.lang.String typeName)Sets the name of the intercepted type.voidsetRequiresMethodProcessing(boolean shouldPreProcess)Sets whether theBeanType.requiresMethodProcessing()returns true.voidsetValidated(boolean validated)Make the bean definition as validated by javax.validation.byte[]toByteArray()java.lang.StringtoString()voidvisitAnnotationMemberPropertyInjectionPoint(TypedElement annotationMemberBeanType, java.lang.String annotationMemberProperty, java.lang.String requiredValue, java.lang.String notEqualsValue)Visits an annotation injection point.voidvisitBeanDefinitionConstructor(MethodElement constructor, boolean requiresReflection, VisitorContext visitorContext)Visits the constructor used to create the bean definition.voidvisitBeanDefinitionEnd()Finalize the bean definition to the given output stream.voidvisitBeanDefinitionInterface(java.lang.Class<? extends BeanDefinition> interfaceType)Visit a marker interface on the generated bean definition.voidvisitBeanFactoryField(ClassElement factoryClass, FieldElement factoryField)In the case where the produced class is produced by a factory field annotated withBeanthis method should be called.voidvisitBeanFactoryMethod(ClassElement factoryClass, MethodElement factoryMethod)In the case where the produced class is produced by a factory method annotated withBeanthis method should be called.voidvisitBeanFactoryMethod(ClassElement factoryClass, MethodElement factoryMethod, ParameterElement[] parameters)In the case where the produced class is produced by a factory method annotated withBeanthis method should be called.voidvisitConfigBuilderDurationMethod(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.voidvisitConfigBuilderEnd()Finalize a configuration builder field.voidvisitConfigBuilderField(ClassElement type, java.lang.String field, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, ConfigurationMetadataBuilder metadataBuilder, boolean isInterface)Begin defining a configuration builder.voidvisitConfigBuilderMethod(ClassElement type, java.lang.String methodName, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, ConfigurationMetadataBuilder metadataBuilder, boolean isInterface)Begin defining a configuration builder.voidvisitConfigBuilderMethod(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.voidvisitDefaultConstructor(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.intvisitExecutableMethod(TypedElement declaringBean, MethodElement methodElement, VisitorContext visitorContext)Visit a method that is to be made executable allow invocation of said method without reflection.intvisitExecutableMethod(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.voidvisitFieldInjectionPoint(TypedElement declaringType, FieldElement fieldElement, boolean requiresReflection)Visits a field injection point.voidvisitFieldValue(TypedElement declaringType, FieldElement fieldElement, boolean requiresReflection, boolean isOptional)Visits a field injection point.voidvisitMethodInjectionPoint(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, VisitorContext visitorContext)Visits a method injection point.voidvisitPostConstructMethod(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, VisitorContext visitorContext)Visits a method injection point.voidvisitPreDestroyMethod(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, VisitorContext visitorContext)Visits a method injection point.voidvisitSetterValue(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, boolean isOptional)Visits an injection point for a setter.voidvisitSuperBeanDefinition(java.lang.String name)Alter the super class of this bean definition.voidvisitSuperBeanDefinitionFactory(java.lang.String beanName)Alter the super class of this bean definition to use another factory bean.voidvisitTypeArguments(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:
isEnabledin interfaceio.micronaut.core.util.Toggleable
-
getExecutableMethodsWriter
@Nullable public ExecutableMethodsDefinitionWriter getExecutableMethodsWriter()
ReturnsExecutableMethodsDefinitionWriterof one exists.- Returns:
- An instance of
ExecutableMethodsDefinitionWriter
-
getTypeArguments
@NonNull public ClassElement[] getTypeArguments()
- Specified by:
getTypeArgumentsin interfaceBeanDefinitionVisitor- Returns:
- The generic type arguments for the bean type.
-
getBeanDefinitionReferenceClassName
@NonNull public java.lang.String getBeanDefinitionReferenceClassName()
- Specified by:
getBeanDefinitionReferenceClassNamein 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:
isInterfacein interfaceBeanDefinitionVisitor- Returns:
- Whether the provided type an interface
-
isSingleton
public boolean isSingleton()
- Specified by:
isSingletonin interfaceBeanDefinitionVisitor- Returns:
- Is the bean singleton
-
visitBeanDefinitionInterface
public void visitBeanDefinitionInterface(java.lang.Class<? extends BeanDefinition> interfaceType)
Description copied from interface:BeanDefinitionVisitorVisit a marker interface on the generated bean definition.- Specified by:
visitBeanDefinitionInterfacein interfaceBeanDefinitionVisitor- Parameters:
interfaceType- The interface type
-
visitSuperBeanDefinition
public void visitSuperBeanDefinition(java.lang.String name)
Description copied from interface:BeanDefinitionVisitorAlter the super class of this bean definition. The passed class should be a subclass ofAbstractBeanDefinition.- Specified by:
visitSuperBeanDefinitionin interfaceBeanDefinitionVisitor- Parameters:
name- The super type
-
visitSuperBeanDefinitionFactory
public void visitSuperBeanDefinitionFactory(java.lang.String beanName)
Description copied from interface:BeanDefinitionVisitorAlter the super class of this bean definition to use another factory bean.- Specified by:
visitSuperBeanDefinitionFactoryin interfaceBeanDefinitionVisitor- Parameters:
beanName- The bean name
-
getBeanTypeName
public java.lang.String getBeanTypeName()
- Specified by:
getBeanTypeNamein interfaceBeanDefinitionVisitor- Returns:
- The full class name of the bean
-
getProvidedType
public org.objectweb.asm.Type getProvidedType()
Description copied from interface:BeanDefinitionVisitorThe 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:
getProvidedTypein interfaceBeanDefinitionVisitor- Returns:
- The provided type
-
setValidated
public void setValidated(boolean validated)
Description copied from interface:BeanDefinitionVisitorMake the bean definition as validated by javax.validation.- Specified by:
setValidatedin interfaceBeanDefinitionVisitor- Parameters:
validated- Whether the bean definition is validated
-
setInterceptedType
public void setInterceptedType(java.lang.String typeName)
Description copied from interface:BeanDefinitionVisitorSets the name of the intercepted type.- Specified by:
setInterceptedTypein interfaceBeanDefinitionVisitor- Parameters:
typeName- The type name
-
getInterceptedType
public java.util.Optional<org.objectweb.asm.Type> getInterceptedType()
- Specified by:
getInterceptedTypein interfaceBeanDefinitionVisitor- Returns:
- The intercepted type
-
isValidated
public boolean isValidated()
- Specified by:
isValidatedin interfaceBeanDefinitionVisitor- Returns:
- Return whether the bean definition is validated.
-
getBeanDefinitionName
public java.lang.String getBeanDefinitionName()
- Specified by:
getBeanDefinitionNamein 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
Beanthis method should be called.- Specified by:
visitBeanFactoryMethodin 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
Beanthis method should be called.- Specified by:
visitBeanFactoryMethodin 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
Beanthis method should be called.- Specified by:
visitBeanFactoryFieldin 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:
visitBeanDefinitionConstructorin 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:BeanDefinitionVisitorVisits 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:
visitDefaultConstructorin 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:
visitBeanDefinitionEndin 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:BeanDefinitionVisitorWrite the class to output via a visitor that manages output destination.- Specified by:
acceptin interfaceBeanDefinitionVisitor- Specified by:
acceptin 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:BeanDefinitionVisitorVisits an injection point for a setter.- Specified by:
visitSetterValuein 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:BeanDefinitionVisitorVisits a method injection point.- Specified by:
visitPostConstructMethodin 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:BeanDefinitionVisitorVisits a method injection point.- Specified by:
visitPreDestroyMethodin 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:BeanDefinitionVisitorVisits a method injection point.- Specified by:
visitMethodInjectionPointin 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:BeanDefinitionVisitorVisit a method that is to be made executable allow invocation of said method without reflection.- Specified by:
visitExecutableMethodin 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:
toStringin classjava.lang.Object
-
getPackageName
public java.lang.String getPackageName()
- Specified by:
getPackageNamein interfaceBeanDefinitionVisitor- Returns:
- The package name of the bean
-
getBeanSimpleName
public java.lang.String getBeanSimpleName()
- Specified by:
getBeanSimpleNamein interfaceBeanDefinitionVisitor- Returns:
- The short name of the bean
-
getAnnotationMetadata
public io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata()
- Specified by:
getAnnotationMetadatain interfaceio.micronaut.core.annotation.AnnotationMetadataProvider- Specified by:
getAnnotationMetadatain 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:BeanDefinitionVisitorBegin defining a configuration builder.- Specified by:
visitConfigBuilderFieldin interfaceBeanDefinitionVisitor- Parameters:
type- The type of the builderfield- The name of the field that represents the builderannotationMetadata- The annotation metadata associated with the fieldmetadataBuilder- TheConfigurationMetadataBuilderisInterface- 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:BeanDefinitionVisitorBegin defining a configuration builder.- Specified by:
visitConfigBuilderMethodin interfaceBeanDefinitionVisitor- Parameters:
type- The type of the buildermethodName- The name of the method that returns the builderannotationMetadata- The annotation metadata associated with the fieldmetadataBuilder- TheConfigurationMetadataBuilderisInterface- 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:BeanDefinitionVisitorVisit a configuration builder method that accepts a long and a TimeUnit.- Specified by:
visitConfigBuilderDurationMethodin 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:BeanDefinitionVisitorVisit a configuration builder method.- Specified by:
visitConfigBuilderMethodin 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:BeanDefinitionVisitorFinalize a configuration builder field.- Specified by:
visitConfigBuilderEndin interfaceBeanDefinitionVisitor- See Also:
ConfigurationBuilder
-
setRequiresMethodProcessing
public void setRequiresMethodProcessing(boolean shouldPreProcess)
Description copied from interface:BeanDefinitionVisitorSets whether theBeanType.requiresMethodProcessing()returns true.- Specified by:
setRequiresMethodProcessingin 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:BeanDefinitionVisitorVisits the type arguments for the bean.- Specified by:
visitTypeArgumentsin interfaceBeanDefinitionVisitor- Parameters:
typeArguments- The type arguments
-
requiresMethodProcessing
public boolean requiresMethodProcessing()
Description copied from interface:BeanDefinitionVisitorBy default, when theBeanContextis started, theBeanDefinition.getExecutableMethods()are not processed by registeredExecutableMethodProcessorinstances unless this method returns true.- Specified by:
requiresMethodProcessingin 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:BeanDefinitionVisitorVisits a field injection point.- Specified by:
visitFieldInjectionPointin 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:BeanDefinitionVisitorVisits an annotation injection point.- Specified by:
visitAnnotationMemberPropertyInjectionPointin 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:BeanDefinitionVisitorVisits a field injection point.- Specified by:
visitFieldValuein 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:
isProtectedin interfaceElement- Returns:
- True if the element is protected.
-
isPublic
public boolean isPublic()
-
getNativeType
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
-
getInjectionPoints
public java.util.Collection<Element> getInjectionPoints()
Description copied from interface:BeanElementReturns all of the injection points for the bean. These will be a combination ofFieldElementandMethodElementinstances.- Specified by:
getInjectionPointsin interfaceBeanElement- Returns:
- The injection points for the bean.
-
isAbstract
public boolean isAbstract()
- Specified by:
isAbstractin 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: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 Element removeAnnotation(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 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:ElementRemoves all annotations that pass the given predicate.- Specified by:
removeAnnotationIfin 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:ElementRemoves a stereotype of the given name from the element.- Specified by:
removeStereotypein interfaceElement- Parameters:
annotationType- The annotation type- Returns:
- This element
-
getDeclaringClass
public ClassElement getDeclaringClass()
Description copied from interface:BeanElementReturns the declaringClassElementwhich may differ from theBeanElement.getBeanTypes()in the case of factory beans.- Specified by:
getDeclaringClassin interfaceBeanElement- Returns:
- The declaring class of the bean.
-
getProducingElement
public Element getProducingElement()
Description copied from interface:BeanElementThe element that produces the bean, this could be aClassElementfor regular beans, or either aMethodElementorFieldElementfor factory beans.- Specified by:
getProducingElementin interfaceBeanElement- Returns:
- The producing element
-
getBeanTypes
public java.util.Set<ClassElement> getBeanTypes()
Description copied from interface:BeanElementThe type names produced by the bean.- Specified by:
getBeanTypesin interfaceBeanElement- Returns:
- A set of types
-
getScope
public java.util.Optional<java.lang.String> getScope()
Description copied from interface:BeanElementThe scope of the bean.- Specified by:
getScopein 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:
getQualifiersin 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:BeanElementThis 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
UnsupportedOperationExceptionwill be thrown.- Specified by:
addAssociatedBeanin interfaceBeanElement- Parameters:
type- The type of the beanvisitorContext- The visitor context- Returns:
- A bean builder
-
getOriginatingElements
public Element[] getOriginatingElements()
- Specified by:
getOriginatingElementsin interfaceOriginatingElements- Overrides:
getOriginatingElementsin classAbstractClassFileWriter- Returns:
- The elements where the bean definition originated from as an array.
-
-