@SuppressWarnings("unchecked")
    @Override
    protected void visitOperation(Class<?> type, Operator operator, List<? extends Expression<?>> args) {
        boolean pathAdded = false;
        if (args.size() == 2
         && !useLiterals
         && args.get(0) instanceof Path<?>
         && args.get(1) instanceof Constant<?>
         && operator != Ops.NUMCAST) {
            Object constant = ((Constant<?>) args.get(1)).getConstant();
            if (!Collection.class.isInstance(constant) || !((Collection) constant).isEmpty()) {
                for (Element element : templates.getTemplate(operator).getElements()) {
                    if (element instanceof Template.ByIndex && ((Template.ByIndex) element).getIndex() == 1) {
                        constantPaths.add((Path<?>) args.get(0));
                        pathAdded = true;
                        break;
                    }
                }
            }
        }

        if (operator == Ops.SET && args.get(0) instanceof SubQueryExpression) {
            boolean oldUnion = inUnion;
            inUnion = true;
            super.visitOperation(type, SQLOps.UNION, args);
            inUnion = oldUnion;

        } else if (operator == SQLOps.UNION || operator == SQLOps.UNION_ALL) {
            boolean oldUnion = inUnion;
            inUnion = true;
            super.visitOperation(type, operator, args);
            inUnion = oldUnion;

        } else if (operator == Ops.LIKE && args.get(1) instanceof Constant<?>) {
            final String escape = String.valueOf(templates.getEscapeChar());
            final String escaped = args.get(1).toString().replace(escape, escape + escape);
            super.visitOperation(String.class, Ops.LIKE,
                    Arrays.asList(args.get(0), ConstantImpl.create(escaped)));

        } else if (operator == Ops.STRING_CAST) {
            final String typeName = configuration.getTypeNameForCast(String.class);
            super.visitOperation(String.class, SQLOps.CAST,
                    Arrays.asList(args.get(0), ConstantImpl.create(typeName)));

        } else if (operator == Ops.NUMCAST) {
            @SuppressWarnings("unchecked") //this is the second argument's type
            Constant<Class<?>> expectedConstant = (Constant<Class<?>>) args.get(1);

            final Class<?> targetType = expectedConstant.getConstant();
            final String typeName = configuration.getTypeNameForCast(targetType);
            super.visitOperation(targetType, SQLOps.CAST,
                    Arrays.asList(args.get(0), ConstantImpl.create(typeName)));

        } else if (operator == Ops.ALIAS) {
            if (stage == Stage.SELECT || stage == Stage.FROM) {
                if (args.get(1) instanceof Path && !((Path<?>) args.get(1)).getMetadata().isRoot()) {
                    Path<?> path = (Path<?>) args.get(1);
                    args = Arrays.asList(args.get(0),
                            ExpressionUtils.path(path.getType(), path.getMetadata().getName()));
                }
                super.visitOperation(type, operator, args);
            } else {
                // handle only target
                handle(args.get(1));
            }

        } else if ((operator == Ops.IN || operator == Ops.NOT_IN)
                && args.get(0) instanceof Path<?>
                && args.get(1) instanceof Constant<?>) {
            //The type of the constant expression is compatible with the left
            //expression, since the compile time checking mandates it to be.
            @SuppressWarnings("unchecked")
            Collection<Object> coll = ((Constant<Collection<Object>>) args.get(1)).getConstant();
            if (coll.isEmpty()) {
                super.visitOperation(type, operator == Ops.IN ? Ops.EQ : Ops.NE,
                        Arrays.asList(Expressions.ONE, Expressions.TWO));
            } else {
                if (templates.getListMaxSize() == 0 || coll.size() <= templates.getListMaxSize()) {
                    super.visitOperation(type, operator, args);
                } else {
                    //The type of the path is compatible with the constant
                    //expression, since the compile time checking mandates it to be
                    @SuppressWarnings("unchecked")
                    Expression<Object> path = (Expression<Object>) args.get(0);
                    if (pathAdded) {
                        constantPaths.removeLast();
                    }
                    Iterable<List<Object>> partitioned = CollectionUtils.partition(new ArrayList<>(coll), templates.getListMaxSize());
                    Predicate result;
                    if (operator == Ops.IN) {
                        result = ExpressionUtils.inAny(path, partitioned);
                    } else {
                        result = ExpressionUtils.notInAny(path, partitioned);
                    }
                    append("(");
                    result.accept(this, null);
                    append(")");
                }
            }

        } else if (operator == SQLOps.WITH_COLUMNS) {
            boolean oldSkipParent = skipParent;
            skipParent = true;
            super.visitOperation(type, operator, args);
            skipParent = oldSkipParent;

        } else if (operator == Ops.ORDER) {
            List<OrderSpecifier<?>> order = ((Constant<List<OrderSpecifier<?>>>) args.get(0)).getConstant();
            handleOrderBy(order);

        } else {
            super.visitOperation(type, operator, args);
        }

        if (operator == SQLOps.WITH_ALIAS || operator == SQLOps.WITH_COLUMNS) {
            if (args.get(0) instanceof Path) {
                withAliases.add((Path<?>) args.get(0));
            } else {
                withAliases.add((Path<?>) ((Operation<?>) args.get(0)).getArg(0));
            }
        }
    }
Return a list of expressions that can be used to uniquely define the query sources

@param joins
@return identifier columns
querydsl-sql/src/main/java/com/querydsl/sql/SQLSerializer.java