Package ch.usi.si.seart.treesitter
Class TreeCursor
- java.lang.Object
-
- ch.usi.si.seart.treesitter.TreeCursor
-
- All Implemented Interfaces:
AutoCloseable
public class TreeCursor extends Object
A tree cursor is a stateful object that allows you to walk a syntax tree with maximum efficiency.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Delete the tree cursor, freeing all the memory that it used.booleanequals(Object obj)StringgetCurrentFieldName()NodegetCurrentNode()TreeCursorNodegetCurrentTreeCursorNode()booleangotoFirstChild()Move the cursor to the first child of its current node.booleangotoNextSibling()Move the cursor to the next sibling of its current node.booleangotoParent()Move the cursor to the parent of its current node.inthashCode()booleanisNull()voidpreorderTraversal(Consumer<Node> callback)Iteratively traverse over the parse tree, applying a callback to the nodes before they are visited.StringtoString()
-
-
-
Method Detail
-
close
public void close()
Delete the tree cursor, freeing all the memory that it used.- Specified by:
closein interfaceAutoCloseable
-
getCurrentNode
public Node getCurrentNode()
- Returns:
- The tree cursor's current node.
-
getCurrentFieldName
public String getCurrentFieldName()
- Returns:
- The field name of the tree cursor's current node. Will return null if the current node doesn't have a field.
-
getCurrentTreeCursorNode
public TreeCursorNode getCurrentTreeCursorNode()
- Returns:
- The tree cursor's current node.
-
gotoFirstChild
public boolean gotoFirstChild()
Move the cursor to the first child of its current node.- Returns:
- true if the cursor successfully moved, and false if there were no children.
-
gotoNextSibling
public boolean gotoNextSibling()
Move the cursor to the next sibling of its current node.- Returns:
- true if the cursor successfully moved, and false if there was no next sibling node.
-
gotoParent
public boolean gotoParent()
Move the cursor to the parent of its current node.- Returns:
- true if the cursor successfully moved, and false if there was no parent node (the cursor was already on the root node).
-
preorderTraversal
public void preorderTraversal(Consumer<Node> callback)
Iteratively traverse over the parse tree, applying a callback to the nodes before they are visited.- Parameters:
callback- The callback consumer which will execute upon visiting a node.
-
isNull
public final boolean isNull()
-
-