Search in sources :

Example 1 with AstStringCompiler

use of org.codehaus.groovy.ast.builder.AstStringCompiler in project groovy by apache.

the class StaticTypesLambdaWriter method addDeserializeLambdaMethod.

private void addDeserializeLambdaMethod() {
    ClassNode enclosingClass = controller.getClassNode();
    Parameter[] parameters = createDeserializeLambdaMethodParams();
    if (enclosingClass.hasMethod("$deserializeLambda$", parameters)) {
        return;
    }
    Statement code = block(declS(localVarX("enclosingClass", OBJECT_TYPE), classX(enclosingClass)), ((BlockStatement) new AstStringCompiler().compile("return enclosingClass" + ".getDeclaredMethod(\"\\$deserializeLambda_${serializedLambda.getImplClass().replace('/', '$')}\\$\", serializedLambda.getClass())" + ".invoke(null, serializedLambda)").get(0)).getStatements().get(0));
    enclosingClass.addSyntheticMethod("$deserializeLambda$", ACC_PRIVATE | ACC_STATIC, OBJECT_TYPE, parameters, ClassNode.EMPTY_ARRAY, code);
}
Also used : 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) AstStringCompiler(org.codehaus.groovy.ast.builder.AstStringCompiler) Parameter(org.codehaus.groovy.ast.Parameter) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement)

Aggregations

ClassNode (org.codehaus.groovy.ast.ClassNode)1 InnerClassNode (org.codehaus.groovy.ast.InnerClassNode)1 Parameter (org.codehaus.groovy.ast.Parameter)1 AstStringCompiler (org.codehaus.groovy.ast.builder.AstStringCompiler)1 BlockStatement (org.codehaus.groovy.ast.stmt.BlockStatement)1 Statement (org.codehaus.groovy.ast.stmt.Statement)1