Class TreeCursor

  • All Implemented Interfaces:
    AutoCloseable
    Direct Known Subclasses:
    OffsetTreeCursor

    public class TreeCursor
    extends Object
    A tree cursor is a stateful object that allows you to walk a syntax tree with maximum efficiency. It allows you to walk a syntax tree more efficiently than is possible using the Node traversal functions. It is always on a certain syntax node, and can be moved imperatively to different nodes.
    Since:
    1.0.0
    Author:
    Tommy MacWilliam, Ozren Dabić
    • Method Detail

      • close

        public void close()
        Delete the tree cursor, freeing all the memory that it used.
        Specified by:
        close in interface AutoCloseable
      • 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, 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​(@NotNull
                                      @NotNull 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
        Throws:
        NullPointerException - if callback is null
      • isNull

        public final boolean isNull()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object