Package io.github.treesitter.jtreesitter
Class TreeCursor
java.lang.Object
io.github.treesitter.jtreesitter.TreeCursor
- All Implemented Interfaces:
AutoCloseable
,Cloneable
A class that can be used to efficiently walk a syntax tree.
-
Method Summary
Modifier and TypeMethodDescriptionclone()
Create a shallow copy of the tree cursor.void
close()
int
Get the depth of the cursor's current node relative to the original node that the cursor was constructed with.int
Get the index of the cursor's current node out of the descendants of the original node that the cursor was constructed with.short
Get the field ID of the tree cursor's current node, or0
.Get the field name of the tree cursor's current node, ornull
.Get the current node of the cursor.void
gotoDescendant
(int index) Move the cursor to the node that is the nth descendant of the original node that the cursor was constructed with.boolean
Move the cursor to the first child of its current node.gotoFirstChildForByte
(int offset) Move the cursor to the first child of its current node that extends beyond the given byte offset.gotoFirstChildForPoint
(Point point) Move the cursor to the first child of its current node that extends beyond the given point.boolean
Move the cursor to the last child of its current node.boolean
Move the cursor to the next sibling of its current node.boolean
Move the cursor to the parent of its current node.boolean
Move the cursor to the previous sibling of its current node.void
Reset the cursor to start at a different node.void
reset
(TreeCursor cursor) Reset the cursor to start at the same position as another cursor.toString()
-
Method Details
-
getCurrentNode
Get the current node of the cursor. -
getCurrentDepth
Get the depth of the cursor's current node relative to the original node that the cursor was constructed with. -
getCurrentFieldId
Get the field ID of the tree cursor's current node, or0
.- See Also:
-
getCurrentFieldName
-
getCurrentDescendantIndex
Get the index of the cursor's current node out of the descendants of the original node that the cursor was constructed with. -
gotoFirstChild
public boolean gotoFirstChild()Move the cursor to the first child of its current node.- Returns:
true
if the cursor successfully moved, orfalse
if there were no children.
-
gotoLastChild
public boolean gotoLastChild()Move the cursor to the last child of its current node.- Returns:
true
if the cursor successfully moved, orfalse
if there were no children.
-
gotoParent
public boolean gotoParent()Move the cursor to the parent of its current node.- Returns:
true
if the cursor successfully moved, orfalse
if there was no parent node.
-
gotoNextSibling
public boolean gotoNextSibling()Move the cursor to the next sibling of its current node.- Returns:
true
if the cursor successfully moved, orfalse
if there was no next sibling node.
-
gotoPreviousSibling
public boolean gotoPreviousSibling()Move the cursor to the previous sibling of its current node.- Returns:
true
if the cursor successfully moved, orfalse
if there was no previous sibling node.
-
gotoDescendant
Move the cursor to the node that is the nth descendant of the original node that the cursor was constructed with.- API Note:
- The index
0
represents the original node itself.
-
gotoFirstChildForByte
Move the cursor to the first child of its current node that extends beyond the given byte offset.- Returns:
- The index of the child node, if found.
-
gotoFirstChildForPoint
Move the cursor to the first child of its current node that extends beyond the given point.- Returns:
- The index of the child node, if found.
-
reset
Reset the cursor to start at a different node. -
reset
Reset the cursor to start at the same position as another cursor. -
clone
Create a shallow copy of the tree cursor. -
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
RuntimeException
-
toString
-