@Override
    public Expression<?> visit(Path<?> expr, C context) {
        if (expr.getMetadata().isRoot()) {
            return expr;
        } else {
            PathMetadata metadata = expr.getMetadata();
            Path<?> parent = (Path) metadata.getParent().accept(this, context);
            Object element = metadata.getElement();
            if (element instanceof Expression<?>) {
                element = ((Expression<?>) element).accept(this, context);
            }
            if (parent.equals(metadata.getParent()) && Objects.equals(element, metadata.getElement())) {
                return expr;
            } else {
                metadata = new PathMetadata(parent, element, metadata.getPathType());
                return ExpressionUtils.path(expr.getType(), metadata);
            }
        }
    }
{@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