Package ch.usi.si.seart.treesitter
Class QueryCursor
- java.lang.Object
-
- ch.usi.si.seart.treesitter.QueryCursor
-
- All Implemented Interfaces:
AutoCloseable,Iterable<QueryMatch>
public class QueryCursor extends Object implements Iterable<QueryMatch>
Cursor used for executing queries, carrying the state needed to process them.The query cursor should not be shared between threads, but can be reused for many query executions.
- Since:
- 1.0.0
- Author:
- Ozren Dabić
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Delete the external resource, freeing all the memory that it used.booleanequals(Object obj)voidexecute()Start running a query against a node.inthashCode()booleanisNull()Checks whether the memory address associated with this external resource isnullptr.@NotNull Iterator<QueryMatch>iterator()Returns an iterator over the query matches, starting from the firstQueryMatch.QueryMatchnextMatch()Advance to the next match of the currently running query.voidsetRange(int startByte, int endByte)Set the range of bytes positions in which the query will be executed.voidsetRange(@NotNull Point startPoint, @NotNull Point endPoint)Set the range of row-column coordinates in which the query will be executed.StringtoString()-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
execute
public void execute()
Start running a query against a node.
-
setRange
public void setRange(int startByte, int endByte)Set the range of bytes positions in which the query will be executed.- Parameters:
startByte- The start byte of the query rangeendByte- The end byte of the query range- Throws:
ByteOffsetOutOfBoundsException- if either argument is outside the queried node's byte rangeIllegalArgumentException- if:startByte< 0endByte< 0startByte>endByte
- Since:
- 1.9.0
-
setRange
public void setRange(@NotNull @NotNull Point startPoint, @NotNull @NotNull Point endPoint)Set the range of row-column coordinates in which the query will be executed.- Parameters:
startPoint- The start point of the query rangeendPoint- The end point of the query range- Throws:
NullPointerException- if either argument is nullIllegalArgumentException- if any point coordinates are negative, or ifstartPointis a position that comes afterendPointPointOutOfBoundsException- if any of the arguments is outside the queried node's position range- Since:
- 1.9.0
-
nextMatch
public QueryMatch nextMatch()
Advance to the next match of the currently running query.- Returns:
- A match if there is one, null otherwise
- Throws:
IllegalStateException- if the query was not executed beforehand- See Also:
execute()
-
iterator
@NotNull public @NotNull Iterator<QueryMatch> iterator()
Returns an iterator over the query matches, starting from the firstQueryMatch. Implicitly callsexecute().- Specified by:
iteratorin interfaceIterable<QueryMatch>- Returns:
- an iterator over query cursor matches
-
isNull
public final boolean isNull()
Checks whether the memory address associated with this external resource isnullptr.- Returns:
trueif the memory address is 0, otherwisefalse
-
close
public void close()
Delete the external resource, freeing all the memory that it used.- Specified by:
closein interfaceAutoCloseable
-
-