"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main/java/org/codehaus/groovy/classgen/asm/ClosureWriter.java" between
apache-groovy-src-3.0.8.zip and apache-groovy-src-3.0.9.zip

About: Groovy is an agile dynamic (scripting) language for the Java Platform. It has features similar to those of Python, Ruby, Perl, and Smalltalk. Source release.

ClosureWriter.java  (apache-groovy-src-3.0.8):ClosureWriter.java  (apache-groovy-src-3.0.9)
skipping to change at line 41 skipping to change at line 41
import org.codehaus.groovy.ast.VariableScope; import org.codehaus.groovy.ast.VariableScope;
import org.codehaus.groovy.ast.expr.ClassExpression; import org.codehaus.groovy.ast.expr.ClassExpression;
import org.codehaus.groovy.ast.expr.ClosureExpression; import org.codehaus.groovy.ast.expr.ClosureExpression;
import org.codehaus.groovy.ast.expr.ConstantExpression; import org.codehaus.groovy.ast.expr.ConstantExpression;
import org.codehaus.groovy.ast.expr.ConstructorCallExpression; import org.codehaus.groovy.ast.expr.ConstructorCallExpression;
import org.codehaus.groovy.ast.expr.Expression; import org.codehaus.groovy.ast.expr.Expression;
import org.codehaus.groovy.ast.expr.FieldExpression; import org.codehaus.groovy.ast.expr.FieldExpression;
import org.codehaus.groovy.ast.expr.TupleExpression; import org.codehaus.groovy.ast.expr.TupleExpression;
import org.codehaus.groovy.ast.expr.VariableExpression; import org.codehaus.groovy.ast.expr.VariableExpression;
import org.codehaus.groovy.ast.stmt.BlockStatement; import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.ast.tools.GenericsUtils;
import org.codehaus.groovy.classgen.AsmClassGenerator; import org.codehaus.groovy.classgen.AsmClassGenerator;
import org.codehaus.groovy.classgen.Verifier; import org.codehaus.groovy.classgen.Verifier;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.apache.groovy.ast.tools.AnnotatedNodeUtils.markAsGenerated; import static org.apache.groovy.ast.tools.AnnotatedNodeUtils.markAsGenerated;
import static org.apache.groovy.ast.tools.ClassNodeUtils.addGeneratedMethod; import static org.apache.groovy.ast.tools.ClassNodeUtils.addGeneratedMethod;
import static org.codehaus.groovy.ast.tools.GeneralUtils.args; import static org.codehaus.groovy.ast.tools.GeneralUtils.args;
import static org.codehaus.groovy.ast.tools.GeneralUtils.callThisX; import static org.codehaus.groovy.ast.tools.GeneralUtils.callThisX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorSuperX; import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorSuperX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.fieldX; import static org.codehaus.groovy.ast.tools.GeneralUtils.fieldX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.param; import static org.codehaus.groovy.ast.tools.GeneralUtils.param;
import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS; import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS;
import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt; import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt;
import static org.codehaus.groovy.ast.tools.GeneralUtils.varX; import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
import static org.codehaus.groovy.transform.stc.StaticTypesMarker.INFERRED_RETUR N_TYPE;
import static org.objectweb.asm.Opcodes.ACC_FINAL; import static org.objectweb.asm.Opcodes.ACC_FINAL;
import static org.objectweb.asm.Opcodes.ACC_PRIVATE; import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC; import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ACC_STATIC; import static org.objectweb.asm.Opcodes.ACC_STATIC;
import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC; import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC;
import static org.objectweb.asm.Opcodes.ALOAD; import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.DUP; import static org.objectweb.asm.Opcodes.DUP;
import static org.objectweb.asm.Opcodes.GETFIELD; import static org.objectweb.asm.Opcodes.GETFIELD;
import static org.objectweb.asm.Opcodes.INVOKESPECIAL; import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL; import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
skipping to change at line 191 skipping to change at line 193
InnerClassNode inner = (InnerClassNode) classNode; InnerClassNode inner = (InnerClassNode) classNode;
return inner.isAnonymous(); return inner.isAnonymous();
} }
return false; return false;
} }
protected ClassNode createClosureClass(final ClosureExpression expression, f inal int modifiers) { protected ClassNode createClosureClass(final ClosureExpression expression, f inal int modifiers) {
ClassNode classNode = controller.getClassNode(); ClassNode classNode = controller.getClassNode();
ClassNode outerClass = controller.getOutermostClass(); ClassNode outerClass = controller.getOutermostClass();
String name = genClosureClassName(); String name = genClosureClassName();
boolean staticMethodOrInStaticClass = controller.isStaticMethod() || cla ssNode.isStaticClass();
Parameter[] parameters = expression.getParameters(); Parameter[] parameters = expression.getParameters();
if (parameters == null) { if (parameters == null) {
parameters = Parameter.EMPTY_ARRAY; parameters = Parameter.EMPTY_ARRAY;
} else if (parameters.length == 0) { } else if (parameters.length == 0) {
// let's create a default 'it' parameter // let's create a default 'it' parameter
Parameter it = param(ClassHelper.OBJECT_TYPE, "it", ConstantExpressi on.NULL); Parameter it = param(ClassHelper.OBJECT_TYPE, "it", ConstantExpressi on.NULL);
parameters = new Parameter[]{it}; parameters = new Parameter[]{it};
Variable ref = expression.getVariableScope().getDeclaredVariable("it "); Variable ref = expression.getVariableScope().getDeclaredVariable("it ");
if (ref != null) it.setClosureSharedVariable(ref.isClosureSharedVari able()); if (ref != null) it.setClosureSharedVariable(ref.isClosureSharedVari able());
} }
Parameter[] localVariableParams = getClosureSharedVariables(expression); Parameter[] localVariableParams = getClosureSharedVariables(expression);
removeInitialValues(localVariableParams); removeInitialValues(localVariableParams);
// GROOVY-9971: closure return type is mapped to Groovy cast by classgen
ClassNode returnType = expression.getNodeMetaData(INFERRED_RETURN_TYPE);
if (returnType == null) returnType = ClassHelper.OBJECT_TYPE; // not STC
or unknown path
else if (returnType.isPrimaryClassNode()) returnType = returnType.getPla
inNodeReference();
else if (ClassHelper.isPrimitiveType(returnType)) returnType = ClassHelp
er.getWrapper(returnType);
else if (GenericsUtils.hasUnresolvedGenerics(returnType)) returnType = G
enericsUtils.nonGeneric(returnType);
InnerClassNode answer = new InnerClassNode(classNode, name, modifiers, C lassHelper.CLOSURE_TYPE.getPlainNodeReference()); InnerClassNode answer = new InnerClassNode(classNode, name, modifiers, C lassHelper.CLOSURE_TYPE.getPlainNodeReference());
answer.setEnclosingMethod(controller.getMethodNode()); answer.setEnclosingMethod(controller.getMethodNode());
answer.setScriptBody(controller.isInScriptBody());
answer.setSourcePosition(expression);
answer.setStaticClass(controller.isStaticMethod() || classNode.isStaticC
lass());
answer.setSynthetic(true); answer.setSynthetic(true);
answer.setUsingGenerics(outerClass.isUsingGenerics()); answer.setUsingGenerics(outerClass.isUsingGenerics());
answer.setSourcePosition(expression);
if (staticMethodOrInStaticClass) { MethodNode method = answer.addMethod("doCall", ACC_PUBLIC, returnType, p
answer.setStaticClass(true); arameters, ClassNode.EMPTY_ARRAY, expression.getCode());
}
if (controller.isInScriptBody()) {
answer.setScriptBody(true);
}
MethodNode method =
answer.addMethod("doCall", ACC_PUBLIC, ClassHelper.OBJECT_TYPE,
parameters, ClassNode.EMPTY_ARRAY, expression.getCode());
method.setSourcePosition(expression); method.setSourcePosition(expression);
VariableScope varScope = expression.getVariableScope(); VariableScope varScope = expression.getVariableScope();
if (varScope == null) { if (varScope == null) {
throw new RuntimeException( throw new RuntimeException(
"Must have a VariableScope by now! for expression: " + expre ssion + " class: " + name); "Must have a VariableScope by now! for expression: " + expre ssion + " class: " + name);
} else { } else {
method.setVariableScope(varScope.copy()); method.setVariableScope(varScope.copy());
} }
if (parameters.length > 1 if (parameters.length > 1
|| (parameters.length == 1 || (parameters.length == 1
&& parameters[0].getType() != null && parameters[0].getType() != null
&& parameters[0].getType() != ClassHelper.OBJECT_TYPE && !ClassHelper.OBJECT_TYPE.equals(parameters[0].getType())
&& !ClassHelper.OBJECT_TYPE.equals(parameters[0].getType().getCo && !ClassHelper.OBJECT_TYPE.equals(parameters[0].getType().g
mponentType()))) { etComponentType()))) {
// let's add a typesafe call method // let's add a typesafe call method
MethodNode call = new MethodNode( MethodNode call = new MethodNode(
"call", "call",
ACC_PUBLIC, ACC_PUBLIC,
ClassHelper.OBJECT_TYPE, returnType,
parameters, parameters,
ClassNode.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY,
returnS(callThisX("doCall", args(parameters)))); returnS(callThisX("doCall", args(parameters))));
addGeneratedMethod(answer, call, true); addGeneratedMethod(answer, call, true);
call.setSourcePosition(expression); call.setSourcePosition(expression);
} }
// let's make the constructor // let's make the constructor
BlockStatement block = createBlockStatementForConstructor(expression, ou terClass, classNode); BlockStatement block = createBlockStatementForConstructor(expression, ou terClass, classNode);
 End of changes. 9 change blocks. 
16 lines changed or deleted 24 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)