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
  • Constructor Details

    • DispatchWriter

      public DispatchWriter(String thisType)
    • DispatchWriter

      public DispatchWriter(String thisType, boolean propagateReflectiveExceptions)
      Parameters:
      thisType - The type of the generated class
      propagateReflectiveExceptions - Whether a method dispatched through reflection throws what the method threw, as a directly dispatched method does, instead of wrapping it in an InvocationException
      Since:
      5.2.1
  • Method Details

    • addSetField

      public int addSetField(FieldElement beanField)
      Adds new set field dispatch target.
      Parameters:
      beanField - The field
      Returns:
      the target index
    • addGetField

      public int addGetField(FieldElement beanField)
      Adds new get field dispatch target.
      Parameters:
      beanField - The field
      Returns:
      the target index
    • addGetHiddenField

      public int addGetHiddenField(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. 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

      public int addMethod(TypedElement declaringType, MethodElement methodElement)
      Adds new method dispatch target.
      Parameters:
      declaringType - The declaring type
      methodElement - 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 type
      methodElement - The method element
      useOneDispatch - If method should be dispatched using "dispatchOne"
      Returns:
      the target index
    • addOrGetMethod

      public int addOrGetMethod(TypedElement declaringType, MethodElement methodElement)
      Ensures a dispatch target exists for the given method and returns its index.
      Parameters:
      declaringType - The declaring type
      methodElement - 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 type
      methodElement - The method element
      proxyMethod - The proxyMethod
      Returns:
      The dispatch index for the intercepted entry
    • addDispatchTarget

      public int addDispatchTarget(DispatchWriter.DispatchTarget dispatchTarget)
      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

      public void accept(ClassWriterOutputVisitor classWriterOutputVisitor) throws IOException
      Description copied from interface: ClassOutputWriter
      Accept a ClassWriterOutputVisitor to write this writer to disk.
      Specified by:
      accept in interface ClassOutputWriter
      Parameters:
      classWriterOutputVisitor - The ClassWriterOutputVisitor
      Throws:
      IOException - if there is an error writing to disk
    • getDispatchTargets

      public List<DispatchWriter.DispatchTarget> getDispatchTargets()
      Returns:
      all added dispatch targets
    • findMethodIndex

      public int findMethodIndex(MethodElement methodElement)
      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