dragome/dragome-sdk

[Suggestion] DragomeConfigurator Class Iterator

Opened this issue · 4 comments

A class iterator method is needed for DragomeConfigurator. Whenever a class is detected and queued for conversion to javascript, it may be passed to this method. Only the used classes should be passed. This may be useful for replacing classes or methods as well as pre processing of class annotations.

Suggested would be addition to the DragomeConfigurator interface;

void classIterator(Class<?> usedClass);

There is a mechanism for transforming any processed class bytecode that can be configured at DragomeConfigurator:

public interface BytecodeTransformer
{
    byte[] transform(String className, byte[] bytecode);
    boolean requiresTransformation(String className);
}

com.dragome.commons.ChainedInstrumentationDragomeConfigurator uses the set of configured bytecode transformers to process original class and return an enhanced one, then bytecode2js compiler create js from it.

compiler architecture

Shall I override the getBytecodeTransformer? How do I use the ByteCodeTransformer?

I think I will override it and return a new implementation of the ByteCodeTransformer. Can I access the actual class in requiresTransformation method using the findClass method of Instrumentation ClassLoader? So that I can process its annotations.

No you can't, if you try to load a class whose dependencies are not satisfied in current classloader the application will crash, that's why you need to use a bytecode instrumentation framework to process the bytecode passed by param and take all the information from there. Take a look at https://github.com/dragome/dragome-sdk/blob/05d7a406b9588f4935154c8da3d50e448beb68fe/dragome-bytecode-js-compiler/src/main/java/com/dragome/compiler/invokedynamic/InvokeDynamicBackporter.java