public static Optional<Path> maybePath(Expression expression) {
    Objects.requireNonNull(expression, "expression");
    return expression.accept(new AbstractExpressionVisitor<Optional<Path>>(Optional.empty()) {
      @Override
      public Optional<Path> visit(Path path) {
        return Optional.of(path);
      }
    });
  }
If {@code expression} is {@link Path} returns optional describing found constant
otherwise it is an empty optional.
criteria/common/src/org/immutables/criteria/expression/Visitors.java