@Override
    public String visit(Path<?> p, Templates templates) {
        final Path<?> parent = p.getMetadata().getParent();
        final Object elem = p.getMetadata().getElement();
        if (parent != null) {
            Template pattern = templates.getTemplate(p.getMetadata().getPathType());
            if (pattern != null) {
                final List<?> args = Arrays.asList(parent, elem);
                final StringBuilder builder = new StringBuilder();
                for (Template.Element element : pattern.getElements()) {
                    Object rv = element.convert(args);
                    if (rv instanceof Expression) {
                        builder.append(((Expression<?>) rv).accept(this, templates));
                    } else {
                        builder.append(rv.toString());
                    }
                }
                return builder.toString();
            } else {
                throw new IllegalArgumentException("No pattern for " + p.getMetadata().getPathType());
            }
        } else {
            return elem.toString();
        }
    }
{@code ToStringVisitor} is used for toString() serialization in {@link Expression} implementations.

@author tiwe
querydsl-core/src/main/java/com/querydsl/core/types/ToStringVisitor.java