Skip to content

Commit 541d1ba

Browse files
fix(querycursor): make options nullable
1 parent becee9a commit 541d1ba

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/main/java/io/github/treesitter/jtreesitter/QueryCursor.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private void exec(Node node, @Nullable Options options) {
173173
* @implNote The lifetime of the matches is bound to that of the cursor.
174174
*/
175175
public Stream<SimpleImmutableEntry<Integer, QueryMatch>> findCaptures(Node node) {
176-
return findCaptures(node, arena, new Options(null, null));
176+
return findCaptures(node, arena, null);
177177
}
178178

179179
/**
@@ -183,6 +183,7 @@ public Stream<SimpleImmutableEntry<Integer, QueryMatch>> findCaptures(Node node)
183183
* and just want a single, ordered sequence of captures.
184184
*
185185
* @param node The node that the query will run on.
186+
* @param options The options of the query cursor.
186187
*
187188
* @implNote The lifetime of the matches is bound to that of the cursor.
188189
*/
@@ -197,11 +198,13 @@ public Stream<SimpleImmutableEntry<Integer, QueryMatch>> findCaptures(Node node,
197198
* and just want a single, ordered sequence of captures.
198199
*
199200
* @param node The node that the query will run on.
201+
* @param options The options of the query cursor.
200202
*/
201203
public Stream<SimpleImmutableEntry<Integer, QueryMatch>> findCaptures(
202-
Node node, SegmentAllocator allocator, Options options) {
204+
Node node, SegmentAllocator allocator, @Nullable Options options) {
203205
exec(node, options);
204-
var iterator = new CapturesIterator(query, self, node.getTree(), allocator, options.predicateCallback);
206+
var callback = options != null ? options.predicateCallback : null;
207+
var iterator = new CapturesIterator(query, self, node.getTree(), allocator, callback);
205208
return StreamSupport.stream(iterator, false);
206209
}
207210

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

222225
/**
@@ -238,6 +241,7 @@ public Stream<QueryMatch> findMatches(Node node) {
238241
*}
239242
*
240243
* @param node The node that the query will run on.
244+
* @param options The options of the query cursor.
241245
*
242246
* @implNote The lifetime of the matches is bound to that of the cursor.
243247
*/
@@ -252,12 +256,14 @@ public Stream<QueryMatch> findMatches(Node node, Options options) {
252256
* captures that appear <em>before</em> some of the captures from a previous match.
253257
*
254258
* @param node The node that the query will run on.
259+
* @param options The options of the query cursor.
255260
*
256261
* @see #findMatches(Node, Options)
257262
*/
258-
public Stream<QueryMatch> findMatches(Node node, SegmentAllocator allocator, Options options) {
263+
public Stream<QueryMatch> findMatches(Node node, SegmentAllocator allocator, @Nullable Options options) {
259264
exec(node, options);
260-
var iterator = new MatchesIterator(query, self, node.getTree(), allocator, options.predicateCallback);
265+
var callback = options != null ? options.predicateCallback : null;
266+
var iterator = new MatchesIterator(query, self, node.getTree(), allocator, callback);
261267
return StreamSupport.stream(iterator, false);
262268
}
263269

@@ -297,7 +303,7 @@ public static class Options {
297303
* {@code false} to continue query execution.
298304
* @param predicateCallback Custom predicate handler.
299305
*/
300-
private Options(
306+
public Options(
301307
@Nullable Predicate<State> progressCallback,
302308
@Nullable BiPredicate<QueryPredicate, QueryMatch> predicateCallback) {
303309
this.progressCallback = progressCallback;

0 commit comments

Comments
 (0)