Package software.amazon.smithy.syntax
Class TreeCursor
- java.lang.Object
-
- software.amazon.smithy.syntax.TreeCursor
-
- All Implemented Interfaces:
FromSourceLocation
public final class TreeCursor extends java.lang.Object implements FromSourceLocation
Externally traverses aTokenTreeto provide access to parents and siblings.- See Also:
TokenTree.zipper()
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)TreeCursorfindAt(int line, int column)Find the innermost tree that contains the given coordinates.java.util.List<TreeCursor>findChildrenByType(TreeType... types)Recursively find every node in the tree that has the givenTreeType.java.util.List<TreeCursor>getChildren()Get all children of the tree as a list of cursors.java.util.List<TreeCursor>getChildrenByType(TreeType... types)Get direct children from the current tree of a specific type.TreeCursorgetFirstChild()Get the first child of the wrapped tree.TreeCursorgetFirstChild(TreeType type)Get the first child of the wrapped tree with the given type.TreeCursorgetLastChild()Get the last child of the wrapped tree.TreeCursorgetLastChild(TreeType type)Get the last child of the wrapped tree with the given type.TreeCursorgetNextSibling()Get the next sibling of this tree, if present.TreeCursorgetParent()Get the parent cursor, or null if not present.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.TreeCursorgetPreviousSibling()Get the previous sibling of this tree, if present.TreeCursorgetRoot()Get the root of the tree, returning itself if the tree has no parent.SourceLocationgetSourceLocation()Gets the source location of a value.TokenTreegetTree()Get the wrappedTokenTree.inthashCode()static TreeCursorof(TokenTree tree)Create a TreeCursor from the given TokenTree, treating it as the root of the tree.java.util.List<TreeCursor>remainingSiblings()
-
-
-
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.
-
getSourceLocation
public SourceLocation getSourceLocation()
Description copied from interface:FromSourceLocationGets the source location of a value.- Specified by:
getSourceLocationin interfaceFromSourceLocation- Returns:
- Returns the source location of the value.
-
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 givenTreeType.- 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.
-
remainingSiblings
public java.util.List<TreeCursor> remainingSiblings()
- Returns:
- All siblings after this cursor, in order.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-