@Internal public class BeanDefinitionWriter extends AbstractClassFileWriter implements BeanDefinitionVisitor
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(..))
BeanDefinition| Modifier and Type | Class and Description |
|---|---|
static class |
BeanDefinitionWriter.MethodVisitData
Data used when visiting method.
|
ARRAY_PATTERN, CONSTRUCTOR_NAME, DEFAULT_MAX_STACK, DESCRIPTOR_DEFAULT_CONSTRUCTOR, METHOD_DEFAULT_CONSTRUCTOR, TYPE_ARGUMENT, TYPE_ARGUMENT_ARRAY, TYPE_CLASS, TYPE_GENERATED, TYPE_OBJECT, ZERO_ARGUMENTS_CONSTANTPROXY_SUFFIXAALOAD, 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_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, ASM4, ASM5, ASM6, ASM7, 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, V9| Constructor and Description |
|---|
BeanDefinitionWriter(ClassElement classElement,
ConfigurationMetadataBuilder<?> metadataBuilder)
Creates a bean definition writer.
|
BeanDefinitionWriter(java.lang.String packageName,
java.lang.String className,
boolean isInterface,
OriginatingElements originatingElements,
AnnotationMetadata annotationMetadata,
ConfigurationMetadataBuilder<?> metadataBuilder)
Creates a bean definition writer.
|
BeanDefinitionWriter(java.lang.String packageName,
java.lang.String className,
java.lang.String beanDefinitionName,
java.lang.String providedClassName,
boolean isInterface,
OriginatingElements originatingElements,
AnnotationMetadata annotationMetadata,
ConfigurationMetadataBuilder<?> metadataBuilder)
Creates a bean definition writer.
|
| Modifier and Type | Method and Description |
|---|---|
void |
accept(ClassWriterOutputVisitor visitor)
Accept a ClassWriterOutputVisitor to write this writer to disk.
|
AnnotationMetadata |
getAnnotationMetadata() |
java.lang.String |
getBeanDefinitionClassFile() |
java.lang.String |
getBeanDefinitionName() |
java.lang.String |
getBeanDefinitionReferenceClassName() |
java.lang.String |
getBeanSimpleName() |
java.lang.String |
getBeanTypeName() |
org.objectweb.asm.ClassVisitor |
getClassWriter() |
java.util.Optional<org.objectweb.asm.Type> |
getInterceptedType() |
java.lang.String |
getPackageName() |
java.util.List<BeanDefinitionWriter.MethodVisitData> |
getPostConstructMethodVisits() |
java.util.List<BeanDefinitionWriter.MethodVisitData> |
getPreDestroyMethodVisits() |
org.objectweb.asm.Type |
getProvidedType()
The provided type of the bean.
|
boolean |
isInterface() |
boolean |
isSingleton() |
boolean |
isValidated() |
boolean |
requiresMethodProcessing()
By default, when the
BeanContext is started, the
BeanDefinition.getExecutableMethods() are not processed by registered
ExecutableMethodProcessor 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 the
BeanType.requiresMethodProcessing() returns true. |
void |
setValidated(boolean validated)
Make the bean definition as validated by javax.validation.
|
byte[] |
toByteArray() |
java.lang.String |
toString() |
void |
visitBeanDefinitionConstructor(MethodElement constructor,
boolean requiresReflection)
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 |
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. |
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,
AnnotationMetadata annotationMetadata,
ConfigurationMetadataBuilder metadataBuilder,
boolean isInterface)
Begin defining a configuration builder.
|
void |
visitConfigBuilderMethod(ClassElement type,
java.lang.String methodName,
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(AnnotationMetadata annotationMetadata)
Visits the constructor used to create the bean definition in the case where no constructor is present.
|
ExecutableMethodWriter |
visitExecutableMethod(TypedElement declaringBean,
MethodElement methodElement)
Visit a method that is to be made executable allow invocation of said method without reflection.
|
ExecutableMethodWriter |
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)
Visits a method injection point.
|
void |
visitPostConstructMethod(TypedElement declaringType,
MethodElement methodElement,
boolean requiresReflection)
Visits a method injection point.
|
void |
visitPreDestroyMethod(TypedElement declaringType,
MethodElement methodElement,
boolean requiresReflection)
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.
|
addOriginatingElement, buildArgument, buildArgumentWithGenerics, generateServiceDescriptor, getClassFileName, getConstructorDescriptor, getConstructorDescriptor, getInternalName, getInternalNameForCast, getInternalNameForCast, getInternalNameForCast, getMethodDescriptor, getMethodDescriptor, getMethodDescriptor, getMethodDescriptor, getMethodDescriptorForReturnType, getMethodSignature, getObjectType, getOriginatingElement, getOriginatingElements, getTypeDescriptor, getTypeDescriptor, getTypeDescriptor, getTypeDescriptor, getTypeReference, getTypeReferenceForName, getTypes, implementInterceptedTypeMethod, invokeConstructor, invokeInterfaceStaticMethod, invokeMethod, newClassWriterOutputVisitor, pushBoxPrimitiveIfNecessary, pushBoxPrimitiveIfNecessary, pushBoxPrimitiveIfNecessary, pushBuildArgumentsForMethod, pushCastToType, pushCastToType, pushCastToType, pushCreateArgument, pushMethodNameAndTypesArguments, pushNewArray, pushNewInstance, pushReturnValue, pushStoreInArray, pushStoreStringInArray, pushStoreTypeInArray, pushTypeArgumentElements, returnVoid, startClass, startClass, startConstructor, startConstructor, startFinalClass, startProtectedMethod, startPublicClass, startPublicFinalClass, startPublicFinalMethodZeroArgs, startPublicMethod, startPublicMethod, startPublicMethodZeroArgs, startService, startService, visitStaticInitializer, writeBooleanMethod, writeClassToDisk, writeClassToDisk, writeToclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetOriginatingElement, writeToaddOriginatingElement, getOriginatingElements, ofpublic BeanDefinitionWriter(java.lang.String packageName,
java.lang.String className,
boolean isInterface,
OriginatingElements originatingElements,
AnnotationMetadata annotationMetadata,
ConfigurationMetadataBuilder<?> metadataBuilder)
packageName - The package name of the beanclassName - The class name, without the package, of the beanisInterface - Whether the writer is for an interface.originatingElements - The originating elementsannotationMetadata - The annotation metadatametadataBuilder - The configuration metadata builderpublic BeanDefinitionWriter(ClassElement classElement, ConfigurationMetadataBuilder<?> metadataBuilder)
classElement - The class elementmetadataBuilder - The configuration metadata builderpublic BeanDefinitionWriter(java.lang.String packageName,
java.lang.String className,
java.lang.String beanDefinitionName,
java.lang.String providedClassName,
boolean isInterface,
OriginatingElements originatingElements,
AnnotationMetadata annotationMetadata,
ConfigurationMetadataBuilder<?> metadataBuilder)
packageName - The package name of the beanclassName - The class name, without the package, of the beanbeanDefinitionName - The name of the bean definitionprovidedClassName - The type this bean definition provides, which differs from the class name in the case of factory beansisInterface - Whether the provided type is an interfaceoriginatingElements - The originating elementsannotationMetadata - The annotation metadatametadataBuilder - The configuration metadata builder@NonNull public java.lang.String getBeanDefinitionReferenceClassName()
getBeanDefinitionReferenceClassName in interface BeanDefinitionVisitorpublic final java.util.List<BeanDefinitionWriter.MethodVisitData> getPostConstructMethodVisits()
public java.util.List<BeanDefinitionWriter.MethodVisitData> getPreDestroyMethodVisits()
public org.objectweb.asm.ClassVisitor getClassWriter()
public boolean isInterface()
isInterface in interface BeanDefinitionVisitorpublic boolean isSingleton()
isSingleton in interface BeanDefinitionVisitorpublic void visitBeanDefinitionInterface(java.lang.Class<? extends BeanDefinition> interfaceType)
BeanDefinitionVisitorvisitBeanDefinitionInterface in interface BeanDefinitionVisitorinterfaceType - The interface typepublic void visitSuperBeanDefinition(java.lang.String name)
BeanDefinitionVisitorAbstractBeanDefinition.visitSuperBeanDefinition in interface BeanDefinitionVisitorname - The super typepublic void visitSuperBeanDefinitionFactory(java.lang.String beanName)
BeanDefinitionVisitorvisitSuperBeanDefinitionFactory in interface BeanDefinitionVisitorbeanName - The bean namepublic java.lang.String getBeanTypeName()
getBeanTypeName in interface BeanDefinitionVisitorpublic org.objectweb.asm.Type getProvidedType()
BeanDefinitionVisitorBeanDefinitionVisitor.getBeanTypeName(), except in the case of
factory beans which produce a different type.getProvidedType in interface BeanDefinitionVisitorpublic void setValidated(boolean validated)
BeanDefinitionVisitorsetValidated in interface BeanDefinitionVisitorvalidated - Whether the bean definition is validatedpublic void setInterceptedType(java.lang.String typeName)
BeanDefinitionVisitorsetInterceptedType in interface BeanDefinitionVisitortypeName - The type namepublic java.util.Optional<org.objectweb.asm.Type> getInterceptedType()
getInterceptedType in interface BeanDefinitionVisitorpublic boolean isValidated()
isValidated in interface BeanDefinitionVisitorpublic java.lang.String getBeanDefinitionName()
getBeanDefinitionName in interface BeanDefinitionVisitorpublic java.lang.String getBeanDefinitionClassFile()
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.
factoryClass - The factory classfactoryMethod - The factor methodpublic void visitBeanDefinitionConstructor(MethodElement constructor, boolean requiresReflection)
visitBeanDefinitionConstructor in interface BeanDefinitionVisitorconstructor - The constructorrequiresReflection - Whether invoking the constructor requires reflectionpublic void visitDefaultConstructor(AnnotationMetadata annotationMetadata)
BeanDefinitionVisitorvisitDefaultConstructor in interface BeanDefinitionVisitorannotationMetadata - The annotation metadata for the constructorpublic void visitBeanDefinitionEnd()
visitBeanDefinitionEnd in interface BeanDefinitionVisitorpublic byte[] toByteArray()
public void accept(ClassWriterOutputVisitor visitor) throws java.io.IOException
AbstractClassFileWriteraccept in interface BeanDefinitionVisitoraccept in class AbstractClassFileWritervisitor - The ClassWriterOutputVisitorjava.io.IOException - if there is an error writing to diskpublic void visitSetterValue(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, boolean isOptional)
BeanDefinitionVisitorvisitSetterValue in interface BeanDefinitionVisitordeclaringType - The declaring typemethodElement - The method elementrequiresReflection - Whether the setter requires reflectionisOptional - Whether the setter is optionalpublic void visitPostConstructMethod(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection)
BeanDefinitionVisitorvisitPostConstructMethod in interface BeanDefinitionVisitordeclaringType - 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 reflectionpublic void visitPreDestroyMethod(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection)
BeanDefinitionVisitorvisitPreDestroyMethod in interface BeanDefinitionVisitordeclaringType - The bean type of the methodmethodElement - The method elementrequiresReflection - Whether the method requires reflectionpublic void visitMethodInjectionPoint(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection)
BeanDefinitionVisitorvisitMethodInjectionPoint in interface BeanDefinitionVisitordeclaringType - The bean type of the methodmethodElement - The method elementrequiresReflection - Whether the method requires reflectionpublic ExecutableMethodWriter visitExecutableMethod(TypedElement declaringBean, MethodElement methodElement)
BeanDefinitionVisitorvisitExecutableMethod in interface BeanDefinitionVisitordeclaringBean - The declaring bean of the method. Note this may differ from MemberElement.getDeclaringType() in the case of the method coming from a super class or interface.methodElement - The method elementExecutableMethodWriter.public ExecutableMethodWriter visitExecutableMethod(TypedElement declaringType, MethodElement methodElement, java.lang.String interceptedProxyClassName, java.lang.String interceptedProxyBridgeMethodName)
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 nameExecutableMethodWriter.public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String getPackageName()
getPackageName in interface BeanDefinitionVisitorpublic java.lang.String getBeanSimpleName()
getBeanSimpleName in interface BeanDefinitionVisitorpublic AnnotationMetadata getAnnotationMetadata()
getAnnotationMetadata in interface BeanDefinitionVisitorpublic void visitConfigBuilderField(ClassElement type, java.lang.String field, AnnotationMetadata annotationMetadata, ConfigurationMetadataBuilder metadataBuilder, boolean isInterface)
BeanDefinitionVisitorvisitConfigBuilderField in interface BeanDefinitionVisitortype - The type of the builderfield - The name of the field that represents the builderannotationMetadata - The annotation metadata associated with the fieldmetadataBuilder - The ConfigurationMetadataBuilderisInterface - Whether the builder type is an interface or notConfigurationBuilderpublic void visitConfigBuilderMethod(ClassElement type, java.lang.String methodName, AnnotationMetadata annotationMetadata, ConfigurationMetadataBuilder metadataBuilder, boolean isInterface)
BeanDefinitionVisitorvisitConfigBuilderMethod in interface BeanDefinitionVisitortype - The type of the buildermethodName - The name of the method that returns the builderannotationMetadata - The annotation metadata associated with the fieldmetadataBuilder - The ConfigurationMetadataBuilderisInterface - Whether the builder type is an interface or notConfigurationBuilderpublic void visitConfigBuilderDurationMethod(java.lang.String prefix,
ClassElement returnType,
java.lang.String methodName,
java.lang.String path)
BeanDefinitionVisitorvisitConfigBuilderDurationMethod in interface BeanDefinitionVisitorprefix - The prefix used for the methodreturnType - The return typemethodName - The method namepath - The property pathConfigurationBuilderpublic 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)
BeanDefinitionVisitorvisitConfigBuilderMethod in interface BeanDefinitionVisitorprefix - The prefix used for the methodreturnType - The return typemethodName - The method nameparamType - The method typegenerics - The generic types of the methodpath - The property pathConfigurationBuilderpublic void visitConfigBuilderEnd()
BeanDefinitionVisitorvisitConfigBuilderEnd in interface BeanDefinitionVisitorConfigurationBuilderpublic void setRequiresMethodProcessing(boolean shouldPreProcess)
BeanDefinitionVisitorBeanType.requiresMethodProcessing() returns true.setRequiresMethodProcessing in interface BeanDefinitionVisitorshouldPreProcess - True if they should be pre-processedpublic void visitTypeArguments(java.util.Map<java.lang.String,java.util.Map<java.lang.String,ClassElement>> typeArguments)
BeanDefinitionVisitorvisitTypeArguments in interface BeanDefinitionVisitortypeArguments - The type argumentspublic boolean requiresMethodProcessing()
BeanDefinitionVisitorBeanContext is started, the
BeanDefinition.getExecutableMethods() are not processed by registered
ExecutableMethodProcessor instances unless this method returns true.requiresMethodProcessing in interface BeanDefinitionVisitorExecutable.processOnStartup()public void visitFieldInjectionPoint(TypedElement declaringType, FieldElement fieldElement, boolean requiresReflection)
BeanDefinitionVisitorvisitFieldInjectionPoint in interface BeanDefinitionVisitordeclaringType - The declaring type. Either a Class or a string representing the name of the typefieldElement - The field elementrequiresReflection - Whether accessing the field requires reflectionpublic void visitFieldValue(TypedElement declaringType, FieldElement fieldElement, boolean requiresReflection, boolean isOptional)
BeanDefinitionVisitorvisitFieldValue in interface BeanDefinitionVisitordeclaringType - 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