Package software.amazon.smithy.syntax
Class TreeCursor
java.lang.Object
software.amazon.smithy.syntax.TreeCursor
- All Implemented Interfaces:
FromSourceLocation
Externally traverses a
TokenTree
to provide access to parents and siblings.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionboolean
findAt
(int line, int column) Find the innermost tree that contains the given coordinates.findChildrenByType
(TreeType... types) Recursively find every node in the tree that has the givenTreeType
.Get all children of the tree as a list of cursors.getChildrenByType
(TreeType... types) Get direct children from the current tree of a specific type.Get the first child of the wrapped tree.getFirstChild
(TreeType type) Get the first child of the wrapped tree with the given type.Get the last child of the wrapped tree.getLastChild
(TreeType type) Get the last child of the wrapped tree with the given type.Get the next sibling of this tree, if present.Get the parent cursor, or null if not present.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.Get the previous sibling of this tree, if present.getRoot()
Get the root of the tree, returning itself if the tree has no parent.Gets the source location of a value.getTree()
Get the wrappedTokenTree
.int
hashCode()
static TreeCursor
Create a TreeCursor from the given TokenTree, treating it as the root of the tree.
-
Method Details
-
of
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.
-
getSourceLocation
Description copied from interface:FromSourceLocation
Gets the source location of a value.- Specified by:
getSourceLocation
in interfaceFromSourceLocation
- Returns:
- Returns the source location of the value.
-
getTree
Get the wrappedTokenTree
.- Returns:
- Return the token tree.
-
getParent
Get the parent cursor, or null if not present.- Returns:
- Nullable parent cursor.
-
getRoot
Get the root of the tree, returning itself if the tree has no parent.- Returns:
- Non-nullable root tree.
-
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
Get the previous sibling of this tree, if present.- Returns:
- Return the nullable previous sibling.
-
getNextSibling
Get the next sibling of this tree, if present.- Returns:
- Return the nullable next sibling.
-
getChildren
Get all children of the tree as a list of cursors.- Returns:
- Return the cursors to each child.
-
getChildrenByType
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
Get the first child of the wrapped tree.- Returns:
- Return the first child, or null if the tree has no children.
-
getFirstChild
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
Get the last child of the wrapped tree.- Returns:
- Return the last child, or null if the tree has no children.
-
getLastChild
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
Recursively find every node in the tree that has the givenTreeType
.- Parameters:
types
- Types of children to return.- Returns:
- Returns the matching tree cursors.
-
findAt
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
-
hashCode
public int hashCode()
-