@SuppressWarnings("unchecked")
    @Override
    public Expression<?> visit(TemplateExpression<?> expr, C context) {
        ArrayList args = new ArrayList<>();
        for (Object arg : expr.getArgs()) {
            if (arg instanceof Expression) {
                args.add(((Expression<?>) arg).accept(this, context));
            } else {
                args.add(arg);
            }
        }
        if (args.equals(expr.getArgs())) {
            return expr;
        } else {
            if (expr instanceof Predicate) {
                return Expressions.booleanTemplate(expr.getTemplate(), args);
            } else {
                return ExpressionUtils.template(expr.getType(), expr.getTemplate(), args);
            }
        }
    }
{@code ReplaceVisitor} is a deep visitor that can be customized to replace segments of
expression trees

@param <C> context type
querydsl-core/src/main/java/com/querydsl/core/support/ReplaceVisitor.java