Class RPCImplementationGenerator

java.lang.Object
eu.cloudnetservice.driver.impl.network.rpc.generation.RPCImplementationGenerator

final class RPCImplementationGenerator extends Object
The generator for rpc api implementations.
Since:
4.0
  • Field Details

  • Constructor Details

    • RPCImplementationGenerator

      RPCImplementationGenerator(@NonNull @NonNull RPCGenerationContext context, @NonNull @NonNull RPCClassMetadata targetClassMeta, int generationFlags)
      Constructs a new rpc implementation generator.
      Parameters:
      context - the generation context to use for the process.
      targetClassMeta - the metadata of the class for which the implementation is being generated.
      generationFlags - the option flags to customize the generation process.
      Throws:
      NullPointerException - if the given context or target class meta is null.
  • Method Details

    • generateObjectArgumentStore

      static void generateObjectArgumentStore(@NonNull @NonNull CodeBuilder codeBuilder, @NonNull @NonNull MethodType methodType)
      Generates a set of instructions into the given code builder that stores all parameters of the given method into an object array.
      Parameters:
      codeBuilder - the code builder into which the parameter store instruction should be generated.
      methodType - the information about the method for which the instructions are generated.
      Throws:
      NullPointerException - if the given code builder or method type is null.
    • generateImplementation

      @NonNull public MethodHandles.Lookup generateImplementation()
      Runs the actual class implementation process.
      Returns:
      a method handle with full access to the generated target class.
      Throws:
      IllegalStateException - if something went wrong generating the implementation class.
    • flagEnabled

      private boolean flagEnabled(int flag)
      Checks if the given flag is enabled in this implementation generator.
      Parameters:
      flag - the flag to check the status of.
      Returns:
      true if the given flag is enabled, false otherwise.
    • resolveBaseConstructorInformation

      @NonNull private @NonNull Tuple2<ClassDesc, MethodTypeDesc> resolveBaseConstructorInformation()
      Tries to find the super constructor that should be invoked from the generated implementation class.
      Returns:
      the super constructor to invoke from the generated class.
      Throws:
      IllegalStateException - if no target constructor for rpc found in target class.
    • generateBridgeRPCInvokeMethod

      private void generateBridgeRPCInvokeMethod(@NonNull @NonNull ClassBuilder classBuilder)
      Generates a local utility method that can be used to invoke a method in this target class. The method automatically joins the base rpc with the newly constructed rpc, if any is provided.
      Parameters:
      classBuilder - the class builder into which the method should be generated.
      Throws:
      NullPointerException - if the given class builder is null.
    • generateBridgeChannelGetterMethod

      private void generateBridgeChannelGetterMethod(@NonNull @NonNull ClassBuilder classBuilder)
      Generates a utility method to get the channel into which all rpc requests should be sent, which internally just calls the channel supplier.
      Parameters:
      classBuilder - the class builder into which the method should be generated.
      Throws:
      NullPointerException - if the given class builder is null.
    • generateConstructor

      private void generateConstructor(@NonNull @NonNull ClassBuilder classBuilder, @NonNull @NonNull ClassDesc superClass, @NonNull @NonNull MethodTypeDesc superConstructorDesc)
      Generates the constructor and the constructor code into the given target class builder.
      Parameters:
      classBuilder - the builder of the class to generate the constructor in.
      superClass - the super class in which the target constructor is located.
      superConstructorDesc - the descriptor of the constructor in the super class.
      Throws:
      NullPointerException - if the given class builder, super class or super constructor descriptor is null.