Class ApiImplementationGenerator

java.lang.Object
eu.cloudnetservice.driver.network.rpc.defaults.generation.ApiImplementationGenerator

public final class ApiImplementationGenerator extends Object
The generator for api implementations based on rpc.
Since:
4.0
See Also:
  • Field Details

    • DEFAULT_SUPER

      static final String DEFAULT_SUPER
      See Also:
    • CHANNEL_TYPE

      static final org.objectweb.asm.Type CHANNEL_TYPE
    • NET_CHANNEL_TYPE

      static final String NET_CHANNEL_TYPE
    • SUPPLIER_DESC

      static final String SUPPLIER_DESC
    • SUPPLIER_TYPE

      static final String SUPPLIER_TYPE
    • GET_METHOD_DESC

      static final String GET_METHOD_DESC
    • SENDER_DESC

      static final String SENDER_DESC
    • SENDER_TYPE

      static final String SENDER_TYPE
    • INVOKE_METHOD_DESC

      static final String INVOKE_METHOD_DESC
    • INJECT_ANNOTATION_DESC

      static final String INJECT_ANNOTATION_DESC
    • EXECUTABLE_NAME

      static final String EXECUTABLE_NAME
    • EXECUTABLE_FIRE_FORGET

      static final String EXECUTABLE_FIRE_FORGET
    • EXECUTABLE_FIRE

      static final String EXECUTABLE_FIRE
    • EXECUTABLE_FIRE_SYNC

      static final String EXECUTABLE_FIRE_SYNC
    • EXECUTABLE_FIRE_FORGET_CHANNEL

      static final String EXECUTABLE_FIRE_FORGET_CHANNEL
    • EXECUTABLE_FIRE_CHANNEL

      static final String EXECUTABLE_FIRE_CHANNEL
    • EXECUTABLE_FIRE_SYNC_CHANNEL

      static final String EXECUTABLE_FIRE_SYNC_CHANNEL
    • GENERATED_CLASS_NAME_FORMAT

      static final String GENERATED_CLASS_NAME_FORMAT
      See Also:
    • SHOULD_GENERATE_IMPL

      static final Predicate<Method> SHOULD_GENERATE_IMPL
  • Constructor Details

    • ApiImplementationGenerator

      private ApiImplementationGenerator()
  • Method Details

    • generateApiImplementation

      @NonNull public static <T> @NonNull InstanceFactory<T> generateApiImplementation(@NonNull @NonNull Class<T> baseClass, @NonNull @NonNull GenerationContext context, @NonNull @NonNull RPCSender sender)
      Generates an implementation of a class sending rpc requests based on the given generation context.
      Type Parameters:
      T - the type which gets generated.
      Parameters:
      baseClass - the return type model class.
      context - the generation context.
      sender - the rpc sender to use for the class.
      Returns:
      a supplier to create an instance of the class which has all requested methods rpc based implemented.
      Throws:
      NullPointerException - if the given base class, context or rpc sender is null.
      ClassCreationException - if the generator is unable to generate an implementation of the class.
    • visitInvokeMethod

      static void visitInvokeMethod(@NonNull @NonNull String className, @NonNull @NonNull Method method, @NonNull @NonNull org.objectweb.asm.MethodVisitor mv)
      Generates the RPCSender.invokeMethod(String) method to gather the rpc result.
      Parameters:
      className - the name of the class owning the method.
      method - the method to generate the invoke method in.
      mv - the method visitor for the method.
      Throws:
      NullPointerException - if the given class name, method or method visitor is null.
    • visitFireMethod

      static void visitFireMethod(@NonNull @NonNull Method method, @NonNull @NonNull org.objectweb.asm.MethodVisitor mv, @NonNull @NonNull String className, @NonNull @NonNull GenerationContext context)
      Decides which RPCExecutable.fire() method is appropriate to call for the return type of this method and generates the call on the RPC that was generated previously.
      Parameters:
      method - the method to invoke using the rpc.
      mv - the method visitor for the current method.
      className - the name of the class owning the method.
      context - the generation context for this generation step.
      Throws:
      NullPointerException - if the given method, method visitor, class name or context is null.
    • collectMethodsToVisit

      @NonNull static @NonNull Collection<Method> collectMethodsToVisit(@NonNull @NonNull GenerationContext context)
      Collects all methods based on the given context which should get implemented.
      Parameters:
      context - the context.
      Returns:
      all methods which need to get implemented.
      Throws:
      NullPointerException - if the given context is null.
    • travelClassHierarchy

      private static void travelClassHierarchy(@NonNull @NonNull Class<?> start, @NonNull @NonNull Consumer<Method> handler)
      Travels down the class hierarchy of the given class, first visiting all superclasses (except Object) and then all interfaces, posting all public, non-static methods to the given handler.
      Parameters:
      start - the class to start the travel from.
      handler - the handler to accept all methods.
      Throws:
      NullPointerException - if the given start class or handler is null.
    • travelInterfaces

      private static void travelInterfaces(@NonNull @NonNull Class<?> start, @NonNull @NonNull Consumer<Method> handler)
      Travels over all interfaces of the given class.
      Parameters:
      start - the class to start the travel from.
      handler - the handler to accept all methods.
      Throws:
      NullPointerException - if the given start class or handler is null.