Package ch.usi.si.seart.treesitter
Class OffsetTreeCursor
- java.lang.Object
-
- ch.usi.si.seart.treesitter.TreeCursor
-
- ch.usi.si.seart.treesitter.OffsetTreeCursor
-
- All Implemented Interfaces:
AutoCloseable
public class OffsetTreeCursor extends TreeCursor
Specialization ofTreeCursorthat applies a positional offset to visited nodes. Retrieving nodes by eithergetCurrentNode()orgetCurrentTreeCursorNode()applies the offset to a copy of the original node, meaning that the tree is not mutated during traversal.So what exactly is the purpose of this cursor? Imagine a scenario in which we need to print out the node positions of a source code file that begins with
nblank lines. Rather than modifying the original file, we can just use this cursor with a positional offset ofnew Position(-n, 0). Likewise, when printing node positions of an indented function, thenspaces of indentation can be negated with a positional offset ofnew Position(0, -n). Row and column offsets can be combined with various positive and negative arrangements.- Since:
- 1.2.0
- Author:
- Ozren Dabić
-
-
Constructor Summary
Constructors Constructor Description OffsetTreeCursor(@NotNull Node node, @NotNull Point offset)
-
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(@NotNull Consumer<Node> callback)Iteratively traverse over the parse tree, applying a callback to the nodes before they are visited.-
Methods inherited from class ch.usi.si.seart.treesitter.TreeCursor
toString
-
-
-
-
Method Detail
-
close
public void close()
Description copied from class:TreeCursorDelete the tree cursor, freeing all the memory that it used.- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classTreeCursor
-
getCurrentFieldName
public String getCurrentFieldName()
- Overrides:
getCurrentFieldNamein classTreeCursor- Returns:
- The field name of the tree cursor's current node,
nullif the current node doesn't have a field
-
gotoFirstChild
public boolean gotoFirstChild()
Description copied from class:TreeCursorMove the cursor to the first child of its current node.- Overrides:
gotoFirstChildin classTreeCursor- Returns:
- true if the cursor successfully moved, and false if there were no children
-
gotoNextSibling
public boolean gotoNextSibling()
Description copied from class:TreeCursorMove the cursor to the next sibling of its current node.- Overrides:
gotoNextSiblingin classTreeCursor- Returns:
- true if the cursor successfully moved, and false if there was no next sibling node
-
gotoParent
public boolean gotoParent()
Description copied from class:TreeCursorMove the cursor to the parent of its current node.- Overrides:
gotoParentin classTreeCursor- 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(@NotNull @NotNull Consumer<Node> callback)Description copied from class:TreeCursorIteratively traverse over the parse tree, applying a callback to the nodes before they are visited.- Overrides:
preorderTraversalin classTreeCursor- Parameters:
callback- The callback consumer which will execute upon visiting a node
-
getCurrentNode
public Node getCurrentNode()
- Overrides:
getCurrentNodein classTreeCursor- Returns:
- The tree cursor's current node
-
getCurrentTreeCursorNode
public TreeCursorNode getCurrentTreeCursorNode()
- Overrides:
getCurrentTreeCursorNodein classTreeCursor- Returns:
- The tree cursor's current node
-
isNull
public final boolean isNull()
-
-