public Expression replaceExpr(Expression expr) {
    replacementExpr = null;
    expr.visit(this);
    Expression result = replacementExpr == null ? expr : replacementExpr;
    replacementExpr = null;
    return result;
  }
Groovy AST visitor that allows to replace both statements and expressions.

@author Peter Niederwieser
spock-core/src/main/java/org/spockframework/compiler/ExpressionReplacingVisitorSupport.java