Class TreeCursor

    • Method Detail

      • of

        public static TreeCursor of​(TokenTree tree)
        Create a TreeCursor from the given TokenTree, treating it as the root of the tree.
        Parameters:
        tree - Tree to create a cursor from.
        Returns:
        Returns the created cursor.
      • getTree

        public TokenTree getTree()
        Get the wrapped TokenTree.
        Returns:
        Return the token tree.
      • getParent

        public TreeCursor getParent()
        Get the parent cursor, or null if not present.
        Returns:
        Nullable parent cursor.
      • getRoot

        public TreeCursor getRoot()
        Get the root of the tree, returning itself if the tree has no parent.
        Returns:
        Non-nullable root tree.
      • getPathToCursor

        public java.util.List<TreeCursor> getPathToCursor()
        Get a list of tree cursors that lead up to the current tree, starting from the root as the first element, and including the current tree as the last element.
        Returns:
        Returns the path to the current tree from the root.
      • getPreviousSibling

        public TreeCursor getPreviousSibling()
        Get the previous sibling of this tree, if present.
        Returns:
        Return the nullable previous sibling.
      • getNextSibling

        public TreeCursor getNextSibling()
        Get the next sibling of this tree, if present.
        Returns:
        Return the nullable next sibling.
      • getChildren

        public java.util.List<TreeCursor> getChildren()
        Get all children of the tree as a list of cursors.
        Returns:
        Return the cursors to each child.
      • getChildrenByType

        public java.util.List<TreeCursor> getChildrenByType​(TreeType... types)
        Get direct children from the current tree of a specific type.
        Parameters:
        types - Types of children to get.
        Returns:
        Returns the collected children, or an empty list.
      • getFirstChild

        public TreeCursor getFirstChild()
        Get the first child of the wrapped tree.
        Returns:
        Return the first child, or null if the tree has no children.
      • getFirstChild

        public TreeCursor getFirstChild​(TreeType type)
        Get the first child of the wrapped tree with the given type.
        Parameters:
        type - Child type to get.
        Returns:
        Return the first child, or null if a matching child is not found.
      • getLastChild

        public TreeCursor getLastChild()
        Get the last child of the wrapped tree.
        Returns:
        Return the last child, or null if the tree has no children.
      • getLastChild

        public TreeCursor getLastChild​(TreeType type)
        Get the last child of the wrapped tree with the given type.
        Parameters:
        type - Child type to get.
        Returns:
        Return the last child, or null if a matching child is not found.
      • findChildrenByType

        public java.util.List<TreeCursor> findChildrenByType​(TreeType... types)
        Recursively find every node in the tree that has the given TreeType.
        Parameters:
        types - Types of children to return.
        Returns:
        Returns the matching tree cursors.
      • findAt

        public TreeCursor findAt​(int line,
                                 int column)
        Find the innermost tree that contains the given coordinates.
        Parameters:
        line - Line to find.
        column - Column to find.
        Returns:
        Returns the innermost tree that contains the coordinates.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object