Class ApiImplementationGenerator
java.lang.Object
eu.cloudnetservice.driver.network.rpc.defaults.generation.ApiImplementationGenerator
The generator for api implementations based on rpc.
- Since:
- 4.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final org.objectweb.asm.Type(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static @NonNull Collection<Method>Collects all methods based on the given context which should get implemented.static <T> @NonNull InstanceFactory<T>generateApiImplementation(@NonNull Class<T> baseClass, @NonNull GenerationContext context, @NonNull RPCSender sender) Generates an implementation of a class sending rpc requests based on the given generation context.private static voidTravels 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.private static voidTravels over all interfaces of the given class.(package private) static voidvisitFireMethod(@NonNull Method method, @NonNull org.objectweb.asm.MethodVisitor mv, @NonNull String className, @NonNull GenerationContext context) Decides whichRPCExecutable.fire()method is appropriate to call for the return type of this method and generates the call on theRPCthat was generated previously.(package private) static voidvisitInvokeMethod(@NonNull String className, @NonNull Method method, @NonNull org.objectweb.asm.MethodVisitor mv) Generates theRPCSender.invokeMethod(String)method to gather the rpc result.
-
Field Details
-
DEFAULT_SUPER
- See Also:
-
CHANNEL_TYPE
static final org.objectweb.asm.Type CHANNEL_TYPE -
NET_CHANNEL_TYPE
-
SUPPLIER_DESC
-
SUPPLIER_TYPE
-
GET_METHOD_DESC
-
SENDER_DESC
-
SENDER_TYPE
-
INVOKE_METHOD_DESC
-
INJECT_ANNOTATION_DESC
-
EXECUTABLE_NAME
-
EXECUTABLE_FIRE_FORGET
-
EXECUTABLE_FIRE
-
EXECUTABLE_FIRE_SYNC
-
EXECUTABLE_FIRE_FORGET_CHANNEL
-
EXECUTABLE_FIRE_CHANNEL
-
EXECUTABLE_FIRE_SYNC_CHANNEL
-
GENERATED_CLASS_NAME_FORMAT
- See Also:
-
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 theRPCSender.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 whichRPCExecutable.fire()method is appropriate to call for the return type of this method and generates the call on theRPCthat 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.
-