Search in sources :

Example 1 with BytecodeInstruction

use of org.codehaus.groovy.classgen.BytecodeInstruction in project groovy by apache.

the class StaticTypesLambdaWriter method addDeserializeLambdaMethodForEachLambdaExpression.

private void addDeserializeLambdaMethodForEachLambdaExpression(final LambdaExpression expression, final ClassNode lambdaClass) {
    ClassNode enclosingClass = controller.getClassNode();
    Statement code = block(new BytecodeSequence(new BytecodeInstruction() {

        @Override
        public void visit(final MethodVisitor mv) {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitInsn(ICONST_0);
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/SerializedLambda", "getCapturedArg", "(I)Ljava/lang/Object;", false);
            mv.visitTypeInsn(CHECKCAST, BytecodeHelper.getClassInternalName(lambdaClass));
            OperandStack operandStack = controller.getOperandStack();
            operandStack.push(lambdaClass);
        }
    }), returnS(expression));
    enclosingClass.addSyntheticMethod(createDeserializeLambdaMethodName(lambdaClass), ACC_PUBLIC | ACC_STATIC, OBJECT_TYPE, createDeserializeLambdaMethodParams(), ClassNode.EMPTY_ARRAY, code);
}
Also used : OperandStack(org.codehaus.groovy.classgen.asm.OperandStack) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) ClassNode(org.codehaus.groovy.ast.ClassNode) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) Statement(org.codehaus.groovy.ast.stmt.Statement) BytecodeInstruction(org.codehaus.groovy.classgen.BytecodeInstruction) BytecodeSequence(org.codehaus.groovy.classgen.BytecodeSequence) MethodVisitor(org.objectweb.asm.MethodVisitor)

Aggregations

ClassNode (org.codehaus.groovy.ast.ClassNode)1 InnerClassNode (org.codehaus.groovy.ast.InnerClassNode)1 BlockStatement (org.codehaus.groovy.ast.stmt.BlockStatement)1 Statement (org.codehaus.groovy.ast.stmt.Statement)1 BytecodeInstruction (org.codehaus.groovy.classgen.BytecodeInstruction)1 BytecodeSequence (org.codehaus.groovy.classgen.BytecodeSequence)1 OperandStack (org.codehaus.groovy.classgen.asm.OperandStack)1 MethodVisitor (org.objectweb.asm.MethodVisitor)1