@Override
  public void visitCastExpression(CastExpression expr) {
    CastExpression result = new CastExpression(
        expr.getType(),
        replaceExpr(expr.getExpression()),
        expr.isIgnoringAutoboxing()
    );
    result.setCoerce(expr.isCoerce());
    result.setType(expr.getType());
    result.setSourcePosition(expr);
    replaceVisitedExpressionWith(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