use of org.codehaus.groovy.ast.ClassHelper.CLOSURE_TYPE in project groovy by apache.
the class StaticTypesLambdaWriter method newGroovyLambdaWrapperAndLoad.
private void newGroovyLambdaWrapperAndLoad(final ClassNode lambdaClass, final LambdaExpression expression, final boolean accessingInstanceMembers) {
CompileStack compileStack = controller.getCompileStack();
OperandStack operandStack = controller.getOperandStack();
MethodVisitor mv = controller.getMethodVisitor();
String lambdaClassInternalName = BytecodeHelper.getClassInternalName(lambdaClass);
mv.visitTypeInsn(NEW, lambdaClassInternalName);
mv.visitInsn(DUP);
if (controller.isStaticMethod() || compileStack.isInSpecialConstructorCall() || !accessingInstanceMembers) {
classX(controller.getThisType()).visit(controller.getAcg());
} else {
loadThis();
}
operandStack.dup();
loadSharedVariables(expression);
Optional<ConstructorNode> generatedConstructor = lambdaClass.getDeclaredConstructors().stream().filter(ctor -> Boolean.TRUE.equals(ctor.getNodeMetaData(IS_GENERATED_CONSTRUCTOR))).findFirst();
if (!generatedConstructor.isPresent()) {
throw new GroovyBugError("Failed to find the generated constructor");
}
Parameter[] lambdaClassConstructorParameters = generatedConstructor.get().getParameters();
mv.visitMethodInsn(INVOKESPECIAL, lambdaClassInternalName, "<init>", BytecodeHelper.getMethodDescriptor(VOID_TYPE, lambdaClassConstructorParameters), lambdaClass.isInterface());
operandStack.replace(CLOSURE_TYPE, lambdaClassConstructorParameters.length);
}
Aggregations