Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/main/java/io/github/treesitter/jtreesitter/QueryCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void exec(Node node, @Nullable Options options) {
* @implNote The lifetime of the matches is bound to that of the cursor.
*/
public Stream<SimpleImmutableEntry<Integer, QueryMatch>> findCaptures(Node node) {
return findCaptures(node, arena, new Options(null, null));
return findCaptures(node, arena, null);
}

/**
Expand All @@ -183,6 +183,7 @@ public Stream<SimpleImmutableEntry<Integer, QueryMatch>> findCaptures(Node node)
* and just want a single, ordered sequence of captures.
*
* @param node The node that the query will run on.
* @param options The options of the query cursor.
*
* @implNote The lifetime of the matches is bound to that of the cursor.
*/
Expand All @@ -197,11 +198,13 @@ public Stream<SimpleImmutableEntry<Integer, QueryMatch>> findCaptures(Node node,
* and just want a single, ordered sequence of captures.
*
* @param node The node that the query will run on.
* @param options The options of the query cursor.
*/
public Stream<SimpleImmutableEntry<Integer, QueryMatch>> findCaptures(
Node node, SegmentAllocator allocator, Options options) {
Node node, SegmentAllocator allocator, @Nullable Options options) {
exec(node, options);
var iterator = new CapturesIterator(query, self, node.getTree(), allocator, options.predicateCallback);
var callback = options != null ? options.predicateCallback : null;
var iterator = new CapturesIterator(query, self, node.getTree(), allocator, callback);
return StreamSupport.stream(iterator, false);
}

Expand All @@ -216,7 +219,7 @@ public Stream<SimpleImmutableEntry<Integer, QueryMatch>> findCaptures(
* @implNote The lifetime of the matches is bound to that of the cursor.
*/
public Stream<QueryMatch> findMatches(Node node) {
return findMatches(node, arena, new Options(null, null));
return findMatches(node, arena, null);
}

/**
Expand All @@ -238,6 +241,7 @@ public Stream<QueryMatch> findMatches(Node node) {
*}
*
* @param node The node that the query will run on.
* @param options The options of the query cursor.
*
* @implNote The lifetime of the matches is bound to that of the cursor.
*/
Expand All @@ -252,12 +256,14 @@ public Stream<QueryMatch> findMatches(Node node, Options options) {
* captures that appear <em>before</em> some of the captures from a previous match.
*
* @param node The node that the query will run on.
* @param options The options of the query cursor.
*
* @see #findMatches(Node, Options)
*/
public Stream<QueryMatch> findMatches(Node node, SegmentAllocator allocator, Options options) {
public Stream<QueryMatch> findMatches(Node node, SegmentAllocator allocator, @Nullable Options options) {
exec(node, options);
var iterator = new MatchesIterator(query, self, node.getTree(), allocator, options.predicateCallback);
var callback = options != null ? options.predicateCallback : null;
var iterator = new MatchesIterator(query, self, node.getTree(), allocator, callback);
return StreamSupport.stream(iterator, false);
}

Expand Down Expand Up @@ -297,7 +303,7 @@ public static class Options {
* {@code false} to continue query execution.
* @param predicateCallback Custom predicate handler.
*/
private Options(
public Options(
@Nullable Predicate<State> progressCallback,
@Nullable BiPredicate<QueryPredicate, QueryMatch> predicateCallback) {
this.progressCallback = progressCallback;
Expand Down