Package com.sonar.sslr.api
Class AstNode
java.lang.Object
com.sonar.sslr.api.AstNode
the parser is in charge to construct an abstract syntax tree (AST) which is a tree representation of the abstract syntactic structure of
source code. Each node of the tree is an AstNode and each node denotes a construct occurring in the source code which starts at a given
Token.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidfindChildren(AstNodeType... nodeTypes) Deprecated.findDirectChildren(AstNodeType... nodeTypes) Deprecated.in 1.17, usegetChildren(AstNodeType...)insteadfindFirstChild(AstNodeType... nodeTypes) Deprecated.in 1.17, usegetFirstDescendant(AstNodeType...)insteadfindFirstDirectChild(AstNodeType... nodeTypes) Deprecated.in 1.17, usegetFirstChild(AstNodeType...)insteadfindFirstParent(AstNodeType nodeType) Deprecated.in 1.17, usegetFirstAncestor(AstNodeType)insteadgetChild(int index) Deprecated.in 1.19.2, usegetFirstChild(AstNodeType...)insteadGet the list of children.getChildren(AstNodeType... nodeTypes) Returns children of specified types.getDescendants(AstNodeType... nodeTypes) Returns descendants of specified types.getFirstAncestor(AstNodeType nodeType) getFirstAncestor(AstNodeType... nodeTypes) Returns the first child of this node.getFirstChild(AstNodeType... nodeTypes) Returns first child of one of specified types.getFirstDescendant(AstNodeType... nodeTypes) Returns first descendant of one of specified types.intReturns the last child of this node.getLastChild(AstNodeType... nodeTypes) Returns last child of one of specified types.getName()Get the next sibling AstNode in the tree and if this node doesn't exist try to get the next AST Node of the parent.Get the next sibling AstNode if exists in the tree.intGet the parent of this node in the tree.Get the previous sibling AstNode in the tree and if this node doesn't exist try to get the next AST Node of the parent.Get the previous sibling AstNode if exists in the tree.intgetToken()Get the Token associated to this AstNodeintGet the Token's line associated to this AstNodeGet the Token's original value associated to this AstNodeReturn all tokens contained in this tree node.Get the Token's value associated to this AstNodegetType()booleanhasAncestor(AstNodeType nodeType) booleanhasAncestor(AstNodeType... nodeTypes) booleanbooleanhasChildren(AstNodeType... nodeTypes) Deprecated.in 1.17, usehasDescendant(AstNodeType...)instead.booleanhasDescendant(AstNodeType... nodeTypes) booleanhasDirectChildren(AstNodeType... nodeTypes) booleanhasParent(AstNodeType... nodeTypes) booleanhasParents(AstNodeType nodeType) Deprecated.in 1.17, usehasAncestor(AstNodeType)insteadbooleanFor internal use only.booleanhasToken()booleanis(AstNodeType... types) booleanbooleanisNot(AstNodeType... types) Deprecated.in 1.17, usegetNextAstNode()insteadDeprecated.in 1.17, usegetNextSibling()insteadDeprecated.in 1.17, usegetPreviousAstNode()insteadDeprecated.in 1.17, usegetPreviousSibling()select()Deprecated.in 1.22voidsetFromIndex(int fromIndex) voidsetToIndex(int toIndex) toString()
-
Field Details
-
type
-
-
Constructor Details
-
AstNode
-
AstNode
-
-
Method Details
-
getParent
Get the parent of this node in the tree. -
addChild
-
hasChildren
public boolean hasChildren()- Returns:
- true if this AstNode has some children.
-
getChildren
Get the list of children.- Returns:
- list of children
-
getNumberOfChildren
public int getNumberOfChildren() -
getChild
Deprecated.in 1.19.2, usegetFirstChild(AstNodeType...)instead -
nextAstNode
Deprecated.in 1.17, usegetNextAstNode()instead -
getNextAstNode
Get the next sibling AstNode in the tree and if this node doesn't exist try to get the next AST Node of the parent.- Since:
- 1.17
-
previousAstNode
Deprecated.in 1.17, usegetPreviousAstNode()instead -
getPreviousAstNode
Get the previous sibling AstNode in the tree and if this node doesn't exist try to get the next AST Node of the parent.- Since:
- 1.17
-
nextSibling
Deprecated.in 1.17, usegetNextSibling()instead -
getNextSibling
Get the next sibling AstNode if exists in the tree.- Returns:
- next sibling, or null if not exists
- Since:
- 1.17
-
previousSibling
Deprecated.in 1.17, usegetPreviousSibling() -
getPreviousSibling
Get the previous sibling AstNode if exists in the tree.- Returns:
- previous sibling, or null if not exists
- Since:
- 1.17
-
getTokenValue
Get the Token's value associated to this AstNode- Returns:
- token's value
-
getTokenOriginalValue
Get the Token's original value associated to this AstNode- Returns:
- token's original value
-
getToken
Get the Token associated to this AstNode -
getTokenLine
public int getTokenLine()Get the Token's line associated to this AstNode- Returns:
- token's line
-
hasToken
public boolean hasToken() -
getName
-
getFromIndex
public int getFromIndex() -
setFromIndex
public void setFromIndex(int fromIndex) -
getToIndex
public int getToIndex() -
hasToBeSkippedFromAst
public boolean hasToBeSkippedFromAst()For internal use only. -
setToIndex
public void setToIndex(int toIndex) -
is
-
isNot
-
findFirstDirectChild
Deprecated.in 1.17, usegetFirstChild(AstNodeType...)instead -
getFirstChild
Returns first child of one of specified types.In the following case,
getFirstChild("B")would return "B2":A1 |__ C1 | |__ B1 |__ B2 |__ B3
- Returns:
- first child of one of specified types, or null if not found
- Since:
- 1.17
-
findFirstChild
Deprecated.in 1.17, usegetFirstDescendant(AstNodeType...)instead -
getFirstDescendant
Returns first descendant of one of specified types.In the following case,
getFirstDescendant("B")would return "B1":A1 |__ C1 | |__ B1 |__ B2 |__ B3
- Returns:
- first descendant of one of specified types, or null if not found
- Since:
- 1.17
-
getFirstChild
Returns the first child of this node.- Returns:
- the first child, or null if there is no child
-
findDirectChildren
Deprecated.in 1.17, usegetChildren(AstNodeType...)instead -
getChildren
Returns children of specified types. In the following case,getChildren("B")would return "B2" and "B3":A1 |__ C1 | |__ B1 |__ B2 |__ B3
- Returns:
- children of specified types, never null
- Since:
- 1.17
-
findChildren
Deprecated.in 1.17, usegetDescendants(AstNodeType...)instead, but don't forget that those methods behave differently due to bug SSLR-249 -
getDescendants
Returns descendants of specified types. Be careful, this method searches among all descendants whatever is their depth, so favorgetChildren(AstNodeType...)when possible.In the following case,
getDescendants("B", "C")would return "C1", "B1", "B2" and "B3":A1 |__ C1 | |__ B1 |__ B2 |__ D1 |__ B3
- Returns:
- descendants of specified types, never null
- Since:
- 1.17
-
getLastChild
Returns the last child of this node.- Returns:
- the last child, or null if there is no child
-
getLastChild
Returns last child of one of specified types.In the following case,
getLastChild("B")would return "B3":A1 |__ C1 | |__ B1 |__ B2 |__ B3 |__ B4- Returns:
- last child of one of specified types, or null if not found
- Since:
- 1.20
-
hasDirectChildren
- Returns:
- true if this node has some children with the requested node types
-
hasChildren
Deprecated.in 1.17, usehasDescendant(AstNodeType...)instead. Be careful the name of this method is misleading as the check is done on descendant nodes and not only on child nodes. -
hasDescendant
- Returns:
- true if this node has a descendant of one of specified types
- Since:
- 1.17
-
hasParents
Deprecated.in 1.17, usehasAncestor(AstNodeType)instead -
hasParent
- Since:
- 1.19.2
-
hasAncestor
- Returns:
- true if this node has an ancestor of the specified type
- Since:
- 1.17
-
hasAncestor
- Returns:
- true if this node has an ancestor of one of specified types
- Since:
- 1.19.2
-
findFirstParent
Deprecated.in 1.17, usegetFirstAncestor(AstNodeType)instead -
getFirstAncestor
- Returns:
- first ancestor of the specified type, or null if not found
- Since:
- 1.17
-
getFirstAncestor
- Returns:
- first ancestor of one of specified types, or null if not found
- Since:
- 1.19.2
-
isCopyBookOrGeneratedNode
public boolean isCopyBookOrGeneratedNode() -
getType
-
getTokens
Return all tokens contained in this tree node. Those tokens can be directly or indirectly attached to this node. -
toString
-
getLastToken
-
select
Deprecated.in 1.22- Since:
- 1.18
-
getDescendants(AstNodeType...)instead, but don't forget that those methods behave differently due to bug SSLR-249