Search in sources :

Example 6 with SootMethodType

use of soot.SootMethodType in project robovm by robovm.

the class LambdaClassGenerator method generate.

public LambdaClass generate(SootClass caller, String invokedName, SootMethodRef invokedType, SootMethodType samMethodType, SootMethodHandle implMethod, SootMethodType instantiatedMethodType, List<Type> markerInterfaces, List<SootMethodType> bridgeMethods) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    String lambdaClassName = caller.getName().replace('.', '/') + "$$Lambda$" + (counter++);
    String functionalInterface = invokedType.returnType().toString().replace('.', '/');
    List<String> interfaces = new ArrayList<String>();
    interfaces.add(functionalInterface);
    for (Type markerInterface : markerInterfaces) {
        interfaces.add(markerInterface.toString().replace('.', '/'));
    }
    cw.visit(CLASS_VERSION, ACC_FINAL + ACC_SUPER + ACC_SYNTHETIC, lambdaClassName, null, "java/lang/Object", interfaces.toArray(new String[interfaces.size()]));
    String targetMethod = "<init>";
    createFieldsAndConstructor(lambdaClassName, cw, invokedType, samMethodType, implMethod, instantiatedMethodType);
    // of the lambda by LambdaPlugin.
    if (!invokedType.parameterTypes().isEmpty()) {
        targetMethod = createFactory(lambdaClassName, cw, invokedType, samMethodType, implMethod, instantiatedMethodType);
    }
    // forward the lambda method
    createForwardingMethod(caller, lambdaClassName, cw, invokedName, samMethodType.getParameterTypes(), samMethodType.getReturnType(), invokedType.parameterTypes(), samMethodType, implMethod, instantiatedMethodType, false);
    // create any bridge methods necessary
    for (SootMethodType bridgeMethod : bridgeMethods) {
        createForwardingMethod(caller, lambdaClassName, cw, invokedName, bridgeMethod.getParameterTypes(), bridgeMethod.getReturnType(), invokedType.parameterTypes(), samMethodType, implMethod, instantiatedMethodType, true);
    }
    cw.visitEnd();
    return new LambdaClass(lambdaClassName, cw.toByteArray(), targetMethod, invokedType.parameterTypes(), invokedType.returnType());
}
Also used : RefType(soot.RefType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) Type(soot.Type) PrimType(soot.PrimType) VoidType(soot.VoidType) LongType(soot.LongType) SootMethodType(soot.SootMethodType) SootMethodType(soot.SootMethodType) ArrayList(java.util.ArrayList) ClassWriter(org.objectweb.asm.ClassWriter)

Aggregations

RefType (soot.RefType)6 SootMethodType (soot.SootMethodType)6 Type (soot.Type)6 DoubleType (soot.DoubleType)5 FloatType (soot.FloatType)5 LongType (soot.LongType)5 PrimType (soot.PrimType)5 VoidType (soot.VoidType)5 ArrayList (java.util.ArrayList)3 MethodVisitor (org.objectweb.asm.MethodVisitor)3 CompilerException (org.robovm.compiler.CompilerException)2 File (java.io.File)1 LinkedList (java.util.LinkedList)1 ClassWriter (org.objectweb.asm.ClassWriter)1 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)1 Body (soot.Body)1 Local (soot.Local)1 SootClass (soot.SootClass)1 SootField (soot.SootField)1 SootMethod (soot.SootMethod)1