Class QueryCursor
- All Implemented Interfaces:
AutoCloseable
- Since:
- 0.25.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A class representing the query cursor options.static final class
A class representing the current state of the query cursor. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
boolean
Check if the query exceeded its maximum number of in-progress matches during its last execution.findCaptures
(Node node) Iterate over all the captures in the order that they were found.findCaptures
(Node node, QueryCursor.Options options) Iterate over all the captures in the order that they were found.findCaptures
(Node node, SegmentAllocator allocator, QueryCursor.Options options) Iterate over all the captures in the order that they were found.findMatches
(Node node) Iterate over all the matches in the order that they were found.findMatches
(Node node, QueryCursor.Options options) Iterate over all the matches in the order that they were found.findMatches
(Node node, SegmentAllocator allocator, QueryCursor.Options options) Iterate over all the matches in the order that they were found, using the given allocator.int
Get the maximum number of in-progress matches.long
Deprecated.setByteRange
(int startByte, int endByte) Set the range of bytes in which the query will be executed.setMatchLimit
(int matchLimit) Get the maximum number of in-progress matches.setMaxStartDepth
(int maxStartDepth) Set the maximum start depth for the query.setPointRange
(Point startPoint, Point endPoint) Set the range of points in which the query will be executed.setTimeoutMicros
(long timeoutMicros) Deprecated.UseQueryCursor.Options
instead.
-
Constructor Details
-
QueryCursor
Create a new cursor for the given query.
-
-
Method Details
-
getMatchLimit
Get the maximum number of in-progress matches.- API Note:
- Defaults to
-1
(unlimited).
-
setMatchLimit
Get the maximum number of in-progress matches.- Throws:
IllegalArgumentException
- IfmatchLimit == 0
.
-
getTimeoutMicros
Deprecated.UseQueryCursor.Options
instead.Get the maximum duration in microseconds that query execution should be allowed to take before halting.- API Note:
- Defaults to
0
(unlimited).
-
setTimeoutMicros
Deprecated.UseQueryCursor.Options
instead.Set the maximum duration in microseconds that query execution should be allowed to take before halting. -
setMaxStartDepth
Set the maximum start depth for the query.This prevents cursors from exploring children nodes at a certain depth.
Note that if a pattern includes many children, then they will still be checked. -
setByteRange
public QueryCursor setByteRange(@Unsigned int startByte, @Unsigned int endByte) throws IllegalArgumentException Set the range of bytes in which the query will be executed.The query cursor will return matches that intersect with the given range. This means that a match may be returned even if some of its captures fall outside the specified range, as long as at least part of the match overlaps with the range.
For example, if a query pattern matches a node that spans a larger area than the specified range, but part of that node intersects with the range, the entire match will be returned.
- Throws:
IllegalArgumentException
- If `endByte > startByte`.
-
setPointRange
Set the range of points in which the query will be executed.The query cursor will return matches that intersect with the given range. This means that a match may be returned even if some of its captures fall outside the specified range, as long as at least part of the match overlaps with the range.
For example, if a query pattern matches a node that spans a larger area than the specified range, but part of that node intersects with the range, the entire match will be returned.
- Throws:
IllegalArgumentException
- If `endPoint > startPoint`.
-
didExceedMatchLimit
public boolean didExceedMatchLimit()Check if the query exceeded its maximum number of in-progress matches during its last execution. -
findCaptures
Iterate over all the captures in the order that they were found.This is useful if you don't care about which pattern matched, and just want a single, ordered sequence of captures.
- Parameters:
node
- The node that the query will run on.- Implementation Note:
- The lifetime of the matches is bound to that of the cursor.
-
findCaptures
public Stream<AbstractMap.SimpleImmutableEntry<Integer,QueryMatch>> findCaptures(Node node, QueryCursor.Options options) Iterate over all the captures in the order that they were found.This is useful if you don't care about which pattern matched, and just want a single, ordered sequence of captures.
- Parameters:
node
- The node that the query will run on.- Implementation Note:
- The lifetime of the matches is bound to that of the cursor.
-
findCaptures
public Stream<AbstractMap.SimpleImmutableEntry<Integer,QueryMatch>> findCaptures(Node node, SegmentAllocator allocator, QueryCursor.Options options) Iterate over all the captures in the order that they were found.This is useful if you don't care about which pattern matched, and just want a single, ordered sequence of captures.
- Parameters:
node
- The node that the query will run on.
-
findMatches
Iterate over all the matches in the order that they were found.Because multiple patterns can match the same set of nodes, one match may contain captures that appear before some of the captures from a previous match.
- Parameters:
node
- The node that the query will run on.- Implementation Note:
- The lifetime of the matches is bound to that of the cursor.
-
findMatches
Iterate over all the matches in the order that they were found.Because multiple patterns can match the same set of nodes, one match may contain captures that appear before some of the captures from a previous match.
Predicate Example
QueryCursor.Options options = new QueryCursor.Options((predicate, match) -> { if (!predicate.getName().equals("ieq?")) return true; List<QueryPredicateArg> args = predicate.getArgs(); Node node = match.findNodes(args.getFirst().value()).getFirst(); return args.getLast().value().equalsIgnoreCase(node.getText()); }); Stream<QueryMatch> matches = self.findMatches(tree.getRootNode(), options);
- Parameters:
node
- The node that the query will run on.- Implementation Note:
- The lifetime of the matches is bound to that of the cursor.
-
findMatches
public Stream<QueryMatch> findMatches(Node node, SegmentAllocator allocator, QueryCursor.Options options) Iterate over all the matches in the order that they were found, using the given allocator.Because multiple patterns can match the same set of nodes, one match may contain captures that appear before some of the captures from a previous match.
- Parameters:
node
- The node that the query will run on.- See Also:
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
RuntimeException
-
QueryCursor.Options
instead.