Package io.micronaut.aop.writer
Class AopProxyWriter
java.lang.Object
io.micronaut.aop.writer.AopProxyWriter
- All Implemented Interfaces:
Toggleable,BeanDefinitionVisitor,ClassOutputWriter,OriginatingElements,ProxyingBeanDefinitionVisitor
@Internal
public class AopProxyWriter
extends Object
implements ProxyingBeanDefinitionVisitor, ClassOutputWriter
A class that generates AOP proxy classes at compile time.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
FieldsFields inherited from interface io.micronaut.inject.writer.BeanDefinitionVisitor
PROXY_SUFFIX -
Constructor Summary
ConstructorsConstructorDescriptionAopProxyWriter(BeanDefinitionWriter parent, OptionalValues<Boolean> settings, VisitorContext visitorContext, AnnotationValue<?>... interceptorBinding) Constructs a newAopProxyWriterfor the given parentBeanDefinitionWriterand starting interceptors types.AopProxyWriter(String packageName, String className, boolean isInterface, boolean implementInterface, Element originatingElement, AnnotationMetadata annotationMetadata, ClassElement[] interfaceTypes, VisitorContext visitorContext, AnnotationValue<?>... interceptorBinding) Constructs a newAopProxyWriterfor the purposes of writingIntroductionadvise.AopProxyWriter(String packageName, String className, boolean isInterface, Element originatingElement, AnnotationMetadata annotationMetadata, ClassElement[] interfaceTypes, VisitorContext visitorContext, AnnotationValue<?>... interceptorBinding) Constructs a newAopProxyWriterfor the purposes of writingIntroductionadvise. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(ClassWriterOutputVisitor visitor) Write the class to output via a visitor that manages output destination.voidaddOriginatingElement(Element element) Add another element that should be included in the originating elements.static intfindInterceptorsListParameterIndex(List<ParameterElement> parameters) Find the interceptors list constructor parameter index.booleanbooleanbooleanIs the target bean being proxied.booleanbooleanbooleanBy default, when theBeanContextis started, theBeanDefinition.getExecutableMethods()are not processed by registeredExecutableMethodProcessorinstances unless this method returns true.voidsetInterceptedType(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 jakarta.validation.voidvisitAnnotationMemberPropertyInjectionPoint(TypedElement annotationMemberBeanType, String annotationMemberProperty, String requiredValue, String notEqualsValue) Visits an annotation injection point.voidvisitAroundMethod(TypedElement beanType, MethodElement methodElement) Visit a method that is to be proxied.voidvisitBeanDefinitionConstructor(MethodElement constructor, boolean requiresReflection, VisitorContext visitorContext) Visits a constructor.voidFinalizes the proxy.voidvisitBeanDefinitionInterface(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(String propertyName, ClassElement returnType, String methodName, String propertyPath) Visit a configuration builder method that accepts a long and a TimeUnit.voidFinalize a configuration builder field.voidvisitConfigBuilderField(ClassElement type, String field, AnnotationMetadata annotationMetadata, ConfigurationMetadataBuilder metadataBuilder, boolean isInterface) Begin defining a configuration builder.voidvisitConfigBuilderMethod(ClassElement type, String methodName, AnnotationMetadata annotationMetadata, ConfigurationMetadataBuilder metadataBuilder, boolean isInterface) Begin defining a configuration builder.voidvisitConfigBuilderMethod(String propertyName, ClassElement returnType, String methodName, ClassElement paramType, Map<String, ClassElement> generics, String propertyPath) Visit a configuration builder method.voidvisitDefaultConstructor(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.voidvisitFieldInjectionPoint(TypedElement declaringType, FieldElement fieldType, boolean requiresReflection, VisitorContext visitorContext) Visits a field injection point.voidvisitFieldValue(TypedElement declaringType, FieldElement fieldType, boolean requiresReflection, boolean isOptional) Visits a field injection point.voidvisitInterceptorBinding(AnnotationValue<?>... interceptorBinding) visitInterceptorTypes.voidvisitIntroductionMethod(TypedElement declaringBean, MethodElement methodElement) Visit an abstract method that is to be implemented.voidvisitMethodInjectionPoint(TypedElement beanType, 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, AnnotationMetadata annotationMetadata, boolean requiresReflection, boolean isOptional) Visits an injection point for a setter.voidAlter the super class of this bean definition.voidvisitSuperBeanDefinitionFactory(String beanName) Alter the super class of this bean definition to use another factory bean.voidvisitTypeArguments(Map<String, Map<String, ClassElement>> typeArguments) Visits the type arguments for the bean.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.inject.writer.BeanDefinitionVisitor
isProxiedBean, writeTo
-
Field Details
-
ADDITIONAL_PARAMETERS_COUNT
public static final int ADDITIONAL_PARAMETERS_COUNT- See Also:
-
-
Constructor Details
-
AopProxyWriter
public AopProxyWriter(BeanDefinitionWriter parent, OptionalValues<Boolean> settings, VisitorContext visitorContext, AnnotationValue<?>... interceptorBinding) Constructs a new
AopProxyWriterfor the given parentBeanDefinitionWriterand starting interceptors types.Additional
Interceptortypes can be added downstream withvisitInterceptorBinding(AnnotationValue[]).- Parameters:
parent- The parentBeanDefinitionWritersettings- optional settingvisitorContext- The visitor contextinterceptorBinding- The interceptor binding of theInterceptorinstances to be injected
-
AopProxyWriter
public AopProxyWriter(String packageName, String className, boolean isInterface, Element originatingElement, AnnotationMetadata annotationMetadata, ClassElement[] interfaceTypes, VisitorContext visitorContext, AnnotationValue<?>... interceptorBinding) Constructs a newAopProxyWriterfor the purposes of writingIntroductionadvise.- Parameters:
packageName- The package nameclassName- The class nameisInterface- Is the target of the advice an interfaceoriginatingElement- The originating elementannotationMetadata- The annotation metadatainterfaceTypes- The additional interfaces to implementvisitorContext- The visitor contextinterceptorBinding- The interceptor types
-
AopProxyWriter
public AopProxyWriter(String packageName, String className, boolean isInterface, boolean implementInterface, Element originatingElement, AnnotationMetadata annotationMetadata, ClassElement[] interfaceTypes, VisitorContext visitorContext, AnnotationValue<?>... interceptorBinding) Constructs a newAopProxyWriterfor the purposes of writingIntroductionadvise.- Parameters:
packageName- The package nameclassName- The class nameisInterface- Is the target of the advice an interfaceimplementInterface- Whether the interface should be implemented. If false theinterfaceTypesargument should contain at least one entryoriginatingElement- The originating elementsannotationMetadata- The annotation metadatainterfaceTypes- The additional interfaces to implementvisitorContext- The visitor contextinterceptorBinding- The interceptor binding
-
-
Method Details
-
findInterceptorsListParameterIndex
Find the interceptors list constructor parameter index.- Parameters:
parameters- The constructor parameters- Returns:
- the index
-
isEnabled
public boolean isEnabled()- Specified by:
isEnabledin interfaceToggleable- Returns:
- Whether the component is enabled
-
isProxyTarget
public boolean isProxyTarget()Is the target bean being proxied.- Specified by:
isProxyTargetin interfaceBeanDefinitionVisitor- Returns:
- True if the target bean is being proxied
-
getOriginatingElement
- Specified by:
getOriginatingElementin interfaceBeanDefinitionVisitor- Returns:
- The element where the bean definition originated from.
-
visitBeanFactoryMethod
Description copied from interface:BeanDefinitionVisitorIn 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) Description copied from interface:BeanDefinitionVisitorIn 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
Description copied from interface:BeanDefinitionVisitorIn 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
-
isSingleton
public boolean isSingleton()- Specified by:
isSingletonin interfaceBeanDefinitionVisitor- Returns:
- Is the bean singleton
-
isInterface
public boolean isInterface()- Specified by:
isInterfacein interfaceBeanDefinitionVisitor- Returns:
- Whether the provided type an interface
-
visitBeanDefinitionInterface
Description copied from interface:BeanDefinitionVisitorVisit a marker interface on the generated bean definition.- Specified by:
visitBeanDefinitionInterfacein interfaceBeanDefinitionVisitor- Parameters:
interfaceType- The interface type
-
getBeanTypeName
- Specified by:
getBeanTypeNamein interfaceBeanDefinitionVisitor- Returns:
- The full class name of the bean
-
setValidated
public void setValidated(boolean validated) Description copied from interface:BeanDefinitionVisitorMake the bean definition as validated by jakarta.validation.- Specified by:
setValidatedin interfaceBeanDefinitionVisitor- Parameters:
validated- Whether the bean definition is validated
-
setInterceptedType
Description copied from interface:BeanDefinitionVisitorSets the name of the intercepted type.- Specified by:
setInterceptedTypein interfaceBeanDefinitionVisitor- Parameters:
typeName- The type name
-
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
- Specified by:
getBeanDefinitionNamein interfaceBeanDefinitionVisitor- Returns:
- The name of the bean definition class
-
visitBeanDefinitionConstructor
public void visitBeanDefinitionConstructor(MethodElement constructor, boolean requiresReflection, VisitorContext visitorContext) Visits a constructor.- Specified by:
visitBeanDefinitionConstructorin interfaceBeanDefinitionVisitor- Parameters:
constructor- The constructorrequiresReflection- Whether reflection is requiredvisitorContext- The visitor context
-
visitDefaultConstructor
public void visitDefaultConstructor(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
-
getBeanDefinitionReferenceClassName
- Specified by:
getBeanDefinitionReferenceClassNamein interfaceBeanDefinitionVisitor- Returns:
- The name of the bean definition reference class.
-
visitIntroductionMethod
Visit an abstract method that is to be implemented.- Parameters:
declaringBean- The declaring bean of the method.methodElement- The method element
-
visitAroundMethod
Visit a method that is to be proxied.- Parameters:
beanType- The bean type.methodElement- The method element
-
visitBeanDefinitionEnd
public void visitBeanDefinitionEnd()Finalizes the proxy. This method should be called before writing the proxy to disk withBeanDefinitionVisitor.writeTo(File)- Specified by:
visitBeanDefinitionEndin interfaceBeanDefinitionVisitor
-
getTypeArguments
- Specified by:
getTypeArgumentsin interfaceBeanDefinitionVisitor- Returns:
- The generic type arguments for the bean type.
-
getTypeArgumentMap
- Specified by:
getTypeArgumentMapin interfaceBeanDefinitionVisitor- Returns:
- A map of the type arguments for the bean.
-
accept
Write 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:
IOException- If an error occurs
-
visitSuperBeanDefinition
Description copied from interface:BeanDefinitionVisitorAlter the super class of this bean definition. The passed class should be a subclass ofAbstractInitializableBeanDefinition.- Specified by:
visitSuperBeanDefinitionin interfaceBeanDefinitionVisitor- Parameters:
name- The super type
-
visitSuperBeanDefinitionFactory
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
-
visitSetterValue
public void visitSetterValue(TypedElement declaringType, MethodElement methodElement, AnnotationMetadata annotationMetadata, 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 elementannotationMetadata- The annotationMetadatarequiresReflection- Whether the setter requires reflectionisOptional- Whether the setter is optional
-
visitPostConstructMethod
public void visitPostConstructMethod(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, VisitorContext visitorContext) Description copied from interface: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 beanType, MethodElement methodElement, boolean requiresReflection, VisitorContext visitorContext) Description copied from interface:BeanDefinitionVisitorVisits a method injection point.- Specified by:
visitMethodInjectionPointin interfaceBeanDefinitionVisitor- Parameters:
beanType- 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
-
visitFieldInjectionPoint
public void visitFieldInjectionPoint(TypedElement declaringType, FieldElement fieldType, boolean requiresReflection, VisitorContext visitorContext) 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 typefieldType- The field elementrequiresReflection- Whether accessing the field requires reflectionvisitorContext- The visitor context
-
visitAnnotationMemberPropertyInjectionPoint
public void visitAnnotationMemberPropertyInjectionPoint(TypedElement annotationMemberBeanType, String annotationMemberProperty, String requiredValue, 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 fieldType, 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 typefieldType- The field elementrequiresReflection- Whether accessing the field requires reflectionisOptional- Is the value optional
-
getPackageName
- Specified by:
getPackageNamein interfaceBeanDefinitionVisitor- Returns:
- The package name of the bean
-
getBeanSimpleName
- Specified by:
getBeanSimpleNamein interfaceBeanDefinitionVisitor- Returns:
- The short name of the bean
-
getAnnotationMetadata
- Specified by:
getAnnotationMetadatain interfaceBeanDefinitionVisitor- Returns:
- The annotation metadata
-
visitConfigBuilderField
public void visitConfigBuilderField(ClassElement type, String field, 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:
-
visitConfigBuilderMethod
public void visitConfigBuilderMethod(ClassElement type, String methodName, 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:
-
visitConfigBuilderMethod
public void visitConfigBuilderMethod(String propertyName, ClassElement returnType, String methodName, ClassElement paramType, Map<String, ClassElement> generics, String propertyPath) Description copied from interface:BeanDefinitionVisitorVisit a configuration builder method.- Specified by:
visitConfigBuilderMethodin interfaceBeanDefinitionVisitor- Parameters:
propertyName- The property namereturnType- The return typemethodName- The method nameparamType- The method typegenerics- The generic types of the methodpropertyPath- The property path- See Also:
-
visitConfigBuilderDurationMethod
public void visitConfigBuilderDurationMethod(String propertyName, ClassElement returnType, String methodName, String propertyPath) Description copied from interface:BeanDefinitionVisitorVisit a configuration builder method that accepts a long and a TimeUnit.- Specified by:
visitConfigBuilderDurationMethodin interfaceBeanDefinitionVisitor- Parameters:
propertyName- The property namereturnType- The return typemethodName- The method namepropertyPath- The property path- See Also:
-
visitConfigBuilderEnd
public void visitConfigBuilderEnd()Description copied from interface:BeanDefinitionVisitorFinalize a configuration builder field.- Specified by:
visitConfigBuilderEndin interfaceBeanDefinitionVisitor- See Also:
-
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
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:
-
getProxiedTypeName
- Specified by:
getProxiedTypeNamein interfaceProxyingBeanDefinitionVisitor- Returns:
- The fully qualified name of the class being proxied
-
getProxiedBeanDefinitionName
- Specified by:
getProxiedBeanDefinitionNamein interfaceProxyingBeanDefinitionVisitor- Returns:
- The bean definition that is proxied
-
visitInterceptorBinding
visitInterceptorTypes.- Parameters:
interceptorBinding- the interceptor binding
-
getOriginatingElements
- Specified by:
getOriginatingElementsin interfaceOriginatingElements- Returns:
- The elements where the bean definition originated from as an array.
-
addOriginatingElement
Description copied from interface:OriginatingElementsAdd another element that should be included in the originating elements.- Specified by:
addOriginatingElementin interfaceOriginatingElements- Parameters:
element- The element to add
-