public static Query toQuery(Reader<?> reader) {
    Objects.requireNonNull(reader, "reader");
    Preconditions.checkArgument(reader instanceof AbstractReader,
            "expected %s to be instance of %s", reader.getClass().getName(), AbstractReader.class.getName());

    return ((AbstractReader) reader).query();
  }
Extract current query from the reader
criteria/common/src/org/immutables/criteria/repository/Repositories.java