@Override public void visitClosureExpression(ClosureExpression expr) { super.visitClosureExpression(expr); AstUtil.fixUpLocalVariables(dataProcessorVars, expr.getVariableScope(), true); }
private void adjustToClassVar(VariableExpression expr) { // we only need to check the variable name because the Groovy compiler // already fails if a variable with the same name already exists in the scope. // this means that a closure cannot shadow a class variable expr.setAccessedVariable(fieldNode); final VariableScope variableScope = currentClosure.getVariableScope(); final Iterator<Variable> iterator = variableScope.getReferencedLocalVariablesIterator(); while (iterator.hasNext()) { Variable next = iterator.next(); if (next.getName().equals(variableName)) iterator.remove(); } variableScope.putReferencedClassVariable(fieldNode); }
protected Parameter[] getClosureSharedVariables(ClosureExpression ce) { VariableScope scope = ce.getVariableScope(); Parameter[] ret = new Parameter[scope.getReferencedLocalVariablesCount()]; int index = 0; for (Iterator iter = scope.getReferencedLocalVariablesIterator(); iter.hasNext();) { Variable element = (org.codehaus.groovy.ast.Variable) iter.next(); Parameter p = new Parameter(element.getType(), element.getName()); p.setOriginType(element.getOriginType()); p.setClosureSharedVariable(element.isClosureSharedVariable()); ret[index] = p; index++; } return ret; }
private boolean handleOldCall(MethodCallExpression expr) { if (!currSpecialMethodCall.isOldCall(expr)) return false; if (!(block instanceof ThenBlock)) { resources.getErrorReporter().error(expr, "old() is only allowed in 'then' blocks"); return true; } expr.setMethod(new ConstantExpression(expr.getMethodAsString() + "Impl")); List<Expression> args = AstUtil.getArgumentList(expr); VariableExpression oldValue = resources.captureOldValue(args.get(0)); args.set(0, oldValue); if (currClosure != null) { oldValue.setClosureSharedVariable(true); currClosure.getVariableScope().putReferencedLocalVariable(oldValue); } return true; }
@Override protected void doVisitClosureExpression(ClosureExpression expr) { if (resources.getCurrentMethod() instanceof FeatureMethod) { AstUtil.fixUpLocalVariables(resources.getCurrentMethod().getAst().getParameters(), expr.getVariableScope(), true); } super.doVisitClosureExpression(expr); if (conditionFound || groupConditionFound) defineRecorders(expr, groupConditionFound); }
ce.getVariableScope().putReferencedLocalVariable((Parameter) parameter.get()); Parameter[] params = ce.getParameters(); if (params == null) {
Variable ref = expression.getVariableScope().getDeclaredVariable("it"); if (ref!=null) it.setClosureSharedVariable(ref.isClosureSharedVariable()); method.setSourcePosition(expression); VariableScope varScope = expression.getVariableScope(); if (varScope == null) { throw new RuntimeException(
protected Parameter[] getClosureSharedVariables(ClosureExpression ce) { VariableScope scope = ce.getVariableScope(); Parameter[] ret = new Parameter[scope.getReferencedLocalVariablesCount()]; int index = 0; for (Iterator iter = scope.getReferencedLocalVariablesIterator(); iter.hasNext();) { org.codehaus.groovy.ast.Variable element = (org.codehaus.groovy.ast.Variable) iter.next(); Parameter p = new Parameter(element.getType(), element.getName()); ret[index] = p; index++; } return ret; }
protected Parameter[] getClosureSharedVariables(ClosureExpression ce) { VariableScope scope = ce.getVariableScope(); Parameter[] ret = new Parameter[scope.getReferencedLocalVariablesCount()]; int index = 0; for (Iterator iter = scope.getReferencedLocalVariablesIterator(); iter.hasNext();) { org.codehaus.groovy.ast.Variable element = (org.codehaus.groovy.ast.Variable) iter.next(); Parameter p = new Parameter(element.getType(), element.getName()); ret[index] = p; index++; } return ret; }
protected Parameter[] getClosureSharedVariables(ClosureExpression ce) { VariableScope scope = ce.getVariableScope(); Parameter[] ret = new Parameter[scope.getReferencedLocalVariablesCount()]; int index = 0; for (Iterator iter = scope.getReferencedLocalVariablesIterator(); iter.hasNext();) { org.codehaus.groovy.ast.Variable element = (org.codehaus.groovy.ast.Variable) iter.next(); Parameter p = new Parameter(element.getType(), element.getName()); ret[index] = p; index++; } return ret; }
Statement code = ex.getCode(); code = createImplicitReturn(code); ex.setCode(new BlockStatement(new Statement[] {startStats,new TryCatchStatement(code,endStats)},ex.getVariableScope()));
protected Parameter[] getClosureSharedVariables(ClosureExpression ce) { VariableScope scope = ce.getVariableScope(); Parameter[] ret = new Parameter[scope.getReferencedLocalVariablesCount()]; int index = 0; for (Iterator iter = scope.getReferencedLocalVariablesIterator(); iter.hasNext();) { Variable element = (org.codehaus.groovy.ast.Variable) iter.next(); Parameter p = new Parameter(element.getType(), element.getName()); p.setOriginType(element.getOriginType()); p.setClosureSharedVariable(element.isClosureSharedVariable()); ret[index] = p; index++; } return ret; }
Statement code = ex.getCode(); code = createImplicitReturn(code); ex.setCode(new BlockStatement(new Statement[] {startStats,new TryCatchStatement(code,endStats)},ex.getVariableScope()));
final VariableScope variableScope = currentClosure.getVariableScope(); final Iterator<Variable> iterator = variableScope.getReferencedLocalVariablesIterator(); while (iterator.hasNext()) {
ce.getVariableScope().putReferencedLocalVariable((Parameter) parameter.get()); Parameter[] params = ce.getParameters(); if (params == null) {
public void transformClosureExpression(ClassNode classNode, ClosureExpression closureExpression) { if (closureExpression.getNodeMetaData(TRANSFORMED_MARKER) != null) return; ClassNode previousClassNode = this.currentClassNode; try { this.currentClassNode = classNode; List<String> propertyNames = AstPropertyResolveUtils.getPropertyNames(classNode); Statement code = closureExpression.getCode(); BlockStatement newCode = new BlockStatement(); boolean addAll = false; if (code instanceof BlockStatement) { BlockStatement bs = (BlockStatement) code; addBlockStatementToNewQuery(bs, newCode, addAll, propertyNames, closureExpression.getVariableScope()); newCode.setVariableScope(bs.getVariableScope()); } if (!newCode.getStatements().isEmpty()) { closureExpression.putNodeMetaData(TRANSFORMED_MARKER, Boolean.TRUE); closureExpression.setCode(newCode); } } finally { this.currentClassNode = previousClassNode; } }
ce.getVariableScope().putReferencedLocalVariable((Parameter) parameter.get()); Parameter[] params = ce.getParameters(); if (params==null){
rewrittenClosureExpression.setDeclaringClass(closureExpression.getDeclaringClass()); rewrittenClosureExpression.setSynthetic(true); rewrittenClosureExpression.setVariableScope(correctVariableScope(closureExpression.getVariableScope(), methodNode)); rewrittenClosureExpression.setType(closureExpression.getType());
rewrittenClosureExpression.setDeclaringClass(closureExpression.getDeclaringClass()); rewrittenClosureExpression.setSynthetic(true); rewrittenClosureExpression.setVariableScope(closureExpression.getVariableScope()); rewrittenClosureExpression.setType(closureExpression.getType());
ASTNode scope = it.next(); if (scope instanceof ClosureExpression) { VariableScope variableScope = ((ClosureExpression) scope).getVariableScope(); if (variableScope.getDeclaredVariable(variable.getName()) != null) { return scope;