public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); ret.addAnnotations(getAnnotations()); ret.setDeclaringClass(getDeclaringClass()); ret.copyNodeMetaData(this); return ret; }
declaration.getOperation(), declaration.getRightExpression()); assignment.setSourcePosition(declaration);
BinaryExpression be = new BinaryExpression( de.getLeftExpression(), de.getOperation(), de.getRightExpression()); expressions.set(i, be);
protected Expression transformDeclarationExpression(DeclarationExpression de) { visitAnnotations(de); Expression oldLeft = de.getLeftExpression(); checkingVariableTypeInDeclaration = true; Expression left = transform(oldLeft); checkingVariableTypeInDeclaration = false; if (left instanceof ClassExpression) { ClassExpression ce = (ClassExpression) left; addError("you tried to assign a value to the class " + ce.getType().getName(), oldLeft); return de; } Expression right = transform(de.getRightExpression()); if (right == de.getRightExpression()) { fixDeclaringClass(de); return de; } DeclarationExpression newDeclExpr = new DeclarationExpression(left, de.getOperation(), right); newDeclExpr.setDeclaringClass(de.getDeclaringClass()); fixDeclaringClass(newDeclExpr); newDeclExpr.setSourcePosition(de); newDeclExpr.addAnnotations(de.getAnnotations()); return newDeclExpr; }
Expression left = de.getLeftExpression(); Expression right = transform(de.getRightExpression()); DeclarationExpression newDecl = new DeclarationExpression(left, de.getOperation(), right); newDecl.addAnnotations(de.getAnnotations()); return newDecl;
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new DeclarationExpression((VariableExpression) transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); return ret; } }
public Expression transformExpression(ExpressionTransformer transformer) { Expression left = getLeftExpression(); Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); return ret; }
public Expression transformExpression(ExpressionTransformer transformer) { Expression left = getLeftExpression(); Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); return ret; }
if (declarationExpression.getOperation().getType() == Types.ASSIGN) { Expression rightExpression = declarationExpression.getRightExpression(); if (rightExpression instanceof ClassExpression) {
@Override public Expression transform(Expression exp) { if (exp instanceof DeclarationExpression) { // info: http://stackoverflow.com/questions/8158637/using-asttransformation-to-remove-def-to-change-scope-in-groovy-script // DeclarationExpression is used when something is declared like this: // def a = "hi"; // Long b = 1; // // When we change it to use BinaryExpression, we "remove" the def or Long, making it "behave" like this: // a = "hi"; // b = 1; // This changes the scope BinaryExpression e = new BinaryExpression(((DeclarationExpression) exp).getLeftExpression(), ((DeclarationExpression) exp).getOperation(), ((DeclarationExpression) exp).getRightExpression()); // setting source position e.setSourcePosition( exp); return e.transformExpression(this); } else { return super.transform(exp); } } }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); ret.addAnnotations(getAnnotations()); ret.setDeclaringClass(getDeclaringClass()); return ret; }
protected Expression transformDeclarationExpression(DeclarationExpression de) { Expression oldLeft = de.getLeftExpression(); Expression left = transform(oldLeft); if (left != oldLeft) { ClassExpression ce = (ClassExpression) left; addError("you tried to assign a value to the class " + ce.getType().getName(), oldLeft); return de; } Expression right = transform(de.getRightExpression()); if (right == de.getRightExpression()) return de; DeclarationExpression newDeclExpr = new DeclarationExpression((VariableExpression) left, de.getOperation(), right); newDeclExpr.setSourcePosition(de); return newDeclExpr; }
@Override public void visitExpressionStatement(ExpressionStatement es) { Expression exp = es.getExpression(); if (exp instanceof DeclarationExpression) { DeclarationExpression de = (DeclarationExpression) exp; Expression leftExpression = de.getLeftExpression(); if (leftExpression instanceof VariableExpression) { // Only cast and transform if the RHS is *not* an EmptyExpression, i.e., "String foo;" would not be cast/transformed. if (!(de.getRightExpression() instanceof EmptyExpression) && mightBePositionalArgumentConstructor((VariableExpression) leftExpression)) { CastExpression ce = new CastExpression(leftExpression.getType(), de.getRightExpression()); ce.setCoerce(true); es.setExpression(transform(new DeclarationExpression(leftExpression, de.getOperation(), ce))); return; } } else { throw new UnsupportedOperationException("not supporting tuples yet"); // cf. "Unexpected LHS of an assignment" above } } super.visitExpressionStatement(es); }
protected Expression transformDeclarationExpression(DeclarationExpression de) { Expression oldLeft = de.getLeftExpression(); Expression left = transform(oldLeft); if (left instanceof ClassExpression) { ClassExpression ce = (ClassExpression) left; addError("you tried to assign a value to the class " + ce.getType().getName(), oldLeft); return de; } Expression right = transform(de.getRightExpression()); if (right == de.getRightExpression()) return de; DeclarationExpression newDeclExpr = new DeclarationExpression(left, de.getOperation(), right); newDeclExpr.setSourcePosition(de); return newDeclExpr; }
protected Expression transformDeclarationExpression(DeclarationExpression de) { Expression oldLeft = de.getLeftExpression(); checkingVariableTypeInDeclaration = true; Expression left = transform(oldLeft); checkingVariableTypeInDeclaration = false; if (left instanceof ClassExpression) { ClassExpression ce = (ClassExpression) left; addError("you tried to assign a value to the class " + ce.getType().getName(), oldLeft); return de; } Expression right = transform(de.getRightExpression()); if (right == de.getRightExpression()) return de; DeclarationExpression newDeclExpr = new DeclarationExpression(left, de.getOperation(), right); newDeclExpr.setSourcePosition(de); return newDeclExpr; }
declaration.getOperation(), declaration.getRightExpression()); assignment.setSourcePosition(declaration);
BinaryExpression be = new BinaryExpression( de.getLeftExpression(), de.getOperation(), de.getRightExpression()); expressions.set(i, be);
protected Expression transformDeclarationExpression(DeclarationExpression de) { visitAnnotations(de); Expression oldLeft = de.getLeftExpression(); checkingVariableTypeInDeclaration = true; Expression left = transform(oldLeft); checkingVariableTypeInDeclaration = false; if (left instanceof ClassExpression) { ClassExpression ce = (ClassExpression) left; addError("you tried to assign a value to the class " + ce.getType().getName(), oldLeft); return de; } Expression right = transform(de.getRightExpression()); if (right == de.getRightExpression()) { fixDeclaringClass(de); return de; } DeclarationExpression newDeclExpr = new DeclarationExpression(left, de.getOperation(), right); newDeclExpr.setDeclaringClass(de.getDeclaringClass()); fixDeclaringClass(newDeclExpr); newDeclExpr.setSourcePosition(de); newDeclExpr.addAnnotations(de.getAnnotations()); return newDeclExpr; }
protected Expression transformDeclarationExpression(DeclarationExpression de) { visitAnnotations(de); Expression oldLeft = de.getLeftExpression(); checkingVariableTypeInDeclaration = true; Expression left = transform(oldLeft); checkingVariableTypeInDeclaration = false; if (left instanceof ClassExpression) { ClassExpression ce = (ClassExpression) left; addError("you tried to assign a value to the class " + ce.getType().getName(), oldLeft); return de; } Expression right = transform(de.getRightExpression()); if (right == de.getRightExpression()) { fixDeclaringClass(de); return de; } DeclarationExpression newDeclExpr = new DeclarationExpression(left, de.getOperation(), right); newDeclExpr.setDeclaringClass(de.getDeclaringClass()); fixDeclaringClass(newDeclExpr); newDeclExpr.setSourcePosition(de); newDeclExpr.addAnnotations(de.getAnnotations()); return newDeclExpr; }
public Expression transform(Expression expr) { if (expr == null) return null; if (expr instanceof MethodCallExpression && candidate == null) { MethodCallExpression mce = (MethodCallExpression) expr; Expression args = transform(mce.getArguments()); if (isNewifyCandidate(mce)) { Expression transformed = transformMethodCall(mce, args); transformed.setSourcePosition(mce); return transformed; } Expression method = transform(mce.getMethod()); Expression object = transform(mce.getObjectExpression()); MethodCallExpression transformed = new MethodCallExpression(object, method, args); transformed.setSourcePosition(mce); return transformed; } else if (expr instanceof DeclarationExpression) { DeclarationExpression de = (DeclarationExpression) expr; if (de == candidate) { candidate = null; Expression left = de.getLeftExpression(); Expression right = transform(de.getRightExpression()); DeclarationExpression newDecl = new DeclarationExpression(left, de.getOperation(), right); newDecl.addAnnotations(de.getAnnotations()); return newDecl; } return de; } return expr.transformExpression(this); }