@Override
    public Expression<?> visit(TemplateExpression<?> expr, Context context) {
        Object[] args = new Object[expr.getArgs().size()];
        for (int i = 0; i < args.length; i++) {
            Context c = new Context();
            if (expr.getArg(i) instanceof Expression) {
                args[i] = ((Expression<?>) expr.getArg(i)).accept(this, c);
            } else {
                args[i] = expr.getArg(i);
            }
            context.add(c);
        }
        if (context.replace) {
            if (expr.getType().equals(Boolean.class)) {
                Predicate predicate = Expressions.booleanTemplate(expr.getTemplate(), args);
                return !context.paths.isEmpty() ? exists(context, predicate) : predicate;
            } else {
                return ExpressionUtils.template(expr.getType(), expr.getTemplate(), args);
            }
        } else {
            return expr;
        }
    }
{@code CollectionAnyVisitor} is an expression visitor which transforms any() path expressions which are
often transformed into subqueries

@author tiwe
querydsl-core/src/main/java/com/querydsl/core/support/CollectionAnyVisitor.java