Class DispatchWriter
java.lang.Object
io.micronaut.inject.writer.DispatchWriter
- All Implemented Interfaces:
ClassOutputWriter
@Internal
@NullUnmarked
public final class DispatchWriter
extends Object
implements ClassOutputWriter
Switch based dispatch writer.
- Since:
- 4.7
- Author:
- Denis Stepanov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDispatch target implementation writer.static interfaceDispatch target implementation writer.static final classField get dispatch target.static final classField get dispatch target.static final classField set dispatch target.static final classField set dispatch target.static final classInterceptable method invocation dispatch target.static final classMethod invocation dispatch target.static final classMethod invocation dispatch target.static final classMethod invocation dispatch target. -
Constructor Summary
ConstructorsConstructorDescriptionDispatchWriter(String thisType) DispatchWriter(String thisType, boolean propagateReflectiveExceptions) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(ClassWriterOutputVisitor classWriterOutputVisitor) Accept a ClassWriterOutputVisitor to write this writer to disk.intaddDispatchTarget(DispatchWriter.DispatchTarget dispatchTarget) Adds new custom dispatch target.intaddGetField(FieldElement beanField) Adds new get field dispatch target.intaddGetHiddenField(FieldElement beanField) Adds a dispatch target reading a field hidden by a field of the same name in a sub class: the field is read through the class declaring it, where a read through the owning type finds the field hiding it.intaddMethod(TypedElement declaringType, MethodElement methodElement) Adds new method dispatch target.intaddMethod(TypedElement declaringType, MethodElement methodElement, boolean useOneDispatch) Adds new method dispatch target.intaddOrGetInterceptedMethod(TypedElement declaringType, MethodElement methodElement, MethodElement proxyMethod) Ensures an intercepted dispatch entry exists for the given method and returns its index.intaddOrGetMethod(TypedElement declaringType, MethodElement methodElement) Ensures a dispatch target exists for the given method and returns its index.intaddSetField(FieldElement beanField) Adds new set field dispatch target.@Nullable io.micronaut.sourcegen.model.MethodDefio.micronaut.sourcegen.model.MethodDefbuildDispatchMethod(io.micronaut.sourcegen.model.ClassTypeDef interceptedProxy, io.micronaut.sourcegen.model.FieldDef interceptableField) @Nullable io.micronaut.sourcegen.model.MethodDef@Nullable io.micronaut.sourcegen.model.MethodDef@Nullable io.micronaut.sourcegen.model.MethodDef@Nullable io.micronaut.sourcegen.model.MethodDefbuildPrimitiveGetMethod(String methodName, io.micronaut.sourcegen.model.TypeDef.Primitive primitiveType) @Nullable io.micronaut.sourcegen.model.MethodDefbuildPrimitiveSetMethod(String methodName, io.micronaut.sourcegen.model.TypeDef.Primitive primitiveType) @Nullable io.micronaut.sourcegen.model.MethodDefbuildPrimitiveSetVoidMethod(String methodName, io.micronaut.sourcegen.model.TypeDef.Primitive primitiveType) intfindMethodIndex(MethodElement methodElement) Finds the dispatch index for the given method.static io.micronaut.sourcegen.model.ExpressionDefgetTypeUtilsGetRequiredMethod(io.micronaut.sourcegen.model.ClassTypeDef declaringType, MethodElement methodElement) boolean
-
Constructor Details
-
DispatchWriter
-
DispatchWriter
- Parameters:
thisType- The type of the generated classpropagateReflectiveExceptions- Whether a method dispatched through reflection throws what the method threw, as a directly dispatched method does, instead of wrapping it in anInvocationException- Since:
- 5.2.1
-
-
Method Details
-
addSetField
Adds new set field dispatch target.- Parameters:
beanField- The field- Returns:
- the target index
-
addGetField
Adds new get field dispatch target.- Parameters:
beanField- The field- Returns:
- the target index
-
addGetHiddenField
Adds a dispatch target reading a field hidden by a field of the same name in a sub class: the field is read through the class declaring it, where a read through the owning type finds the field hiding it. The generated code names the declaring class, so the field can only be read when that class is accessible from the generated type.- Parameters:
beanField- The hidden field- Returns:
- The dispatch index, or -1 when the declaring class cannot be named
- Since:
- 5.2.0
-
addMethod
Adds new method dispatch target.- Parameters:
declaringType- The declaring typemethodElement- The method element- Returns:
- the target index
-
addMethod
public int addMethod(TypedElement declaringType, MethodElement methodElement, boolean useOneDispatch) Adds new method dispatch target.- Parameters:
declaringType- The declaring typemethodElement- The method elementuseOneDispatch- If method should be dispatched using "dispatchOne"- Returns:
- the target index
-
addOrGetMethod
Ensures a dispatch target exists for the given method and returns its index.- Parameters:
declaringType- The declaring typemethodElement- The method element- Returns:
- The dispatch index
-
addOrGetInterceptedMethod
public int addOrGetInterceptedMethod(TypedElement declaringType, MethodElement methodElement, MethodElement proxyMethod) Ensures an intercepted dispatch entry exists for the given method and returns its index.- Parameters:
declaringType- The declaring typemethodElement- The method elementproxyMethod- The proxyMethod- Returns:
- The dispatch index for the intercepted entry
-
addDispatchTarget
Adds new custom dispatch target.- Parameters:
dispatchTarget- The dispatch target implementation- Returns:
- the target index
-
buildDispatchMethod
public io.micronaut.sourcegen.model.MethodDef buildDispatchMethod(io.micronaut.sourcegen.model.ClassTypeDef interceptedProxy, io.micronaut.sourcegen.model.FieldDef interceptableField) -
buildDispatchMethod
public @Nullable io.micronaut.sourcegen.model.MethodDef buildDispatchMethod() -
buildDispatchOneMethod
public @Nullable io.micronaut.sourcegen.model.MethodDef buildDispatchOneMethod() -
buildDispatchOneVoidMethod
public @Nullable io.micronaut.sourcegen.model.MethodDef buildDispatchOneVoidMethod() -
buildPrimitiveGetMethod
public @Nullable io.micronaut.sourcegen.model.MethodDef buildPrimitiveGetMethod(String methodName, io.micronaut.sourcegen.model.TypeDef.Primitive primitiveType) -
buildPrimitiveSetMethod
public @Nullable io.micronaut.sourcegen.model.MethodDef buildPrimitiveSetMethod(String methodName, io.micronaut.sourcegen.model.TypeDef.Primitive primitiveType) -
buildPrimitiveSetVoidMethod
public @Nullable io.micronaut.sourcegen.model.MethodDef buildPrimitiveSetVoidMethod(String methodName, io.micronaut.sourcegen.model.TypeDef.Primitive primitiveType) -
buildGetTargetMethodByIndex
public @Nullable io.micronaut.sourcegen.model.MethodDef buildGetTargetMethodByIndex() -
getTypeUtilsGetRequiredMethod
public static io.micronaut.sourcegen.model.ExpressionDef getTypeUtilsGetRequiredMethod(io.micronaut.sourcegen.model.ClassTypeDef declaringType, MethodElement methodElement) -
accept
Description copied from interface:ClassOutputWriterAccept a ClassWriterOutputVisitor to write this writer to disk.- Specified by:
acceptin interfaceClassOutputWriter- Parameters:
classWriterOutputVisitor- TheClassWriterOutputVisitor- Throws:
IOException- if there is an error writing to disk
-
getDispatchTargets
- Returns:
- all added dispatch targets
-
findMethodIndex
Finds the dispatch index for the given method.- Parameters:
methodElement- The method element- Returns:
- The dispatch index or -1 if not tracked
-
isHasInterceptedMethod
public boolean isHasInterceptedMethod()- Returns:
- if intercepted method dispatch have been added
-