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 SummaryAll 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- 
ofpublic 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.
 
 - 
getSourceLocationpublic SourceLocation getSourceLocation() Description copied from interface:FromSourceLocationGets the source location of a value.- Specified by:
- getSourceLocationin interface- FromSourceLocation
- Returns:
- Returns the source location of the value.
 
 - 
getParentpublic TreeCursor getParent() Get the parent cursor, or null if not present.- Returns:
- Nullable parent cursor.
 
 - 
getRootpublic TreeCursor getRoot() Get the root of the tree, returning itself if the tree has no parent.- Returns:
- Non-nullable root tree.
 
 - 
getPathToCursorpublic 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.
 
 - 
getPreviousSiblingpublic TreeCursor getPreviousSibling() Get the previous sibling of this tree, if present.- Returns:
- Return the nullable previous sibling.
 
 - 
getNextSiblingpublic TreeCursor getNextSibling() Get the next sibling of this tree, if present.- Returns:
- Return the nullable next sibling.
 
 - 
getChildrenpublic java.util.List<TreeCursor> getChildren() Get all children of the tree as a list of cursors.- Returns:
- Return the cursors to each child.
 
 - 
getChildrenByTypepublic 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.
 
 - 
getFirstChildpublic TreeCursor getFirstChild() Get the first child of the wrapped tree.- Returns:
- Return the first child, or null if the tree has no children.
 
 - 
getFirstChildpublic 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.
 
 - 
getLastChildpublic TreeCursor getLastChild() Get the last child of the wrapped tree.- Returns:
- Return the last child, or null if the tree has no children.
 
 - 
getLastChildpublic 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.
 
 - 
findChildrenByTypepublic 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.
 
 - 
findAtpublic 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.
 
 - 
remainingSiblingspublic java.util.List<TreeCursor> remainingSiblings() - Returns:
- All siblings after this cursor, in order.
 
 - 
equalspublic boolean equals(java.lang.Object o) - Overrides:
- equalsin class- java.lang.Object
 
 - 
hashCodepublic int hashCode() - Overrides:
- hashCodein class- java.lang.Object
 
 
- 
 
-