public class AstNode extends Object
Token
Modifier and Type | Field and Description |
---|---|
protected AstNodeType |
type |
Constructor and Description |
---|
AstNode(AstNodeType type,
String name,
Token token) |
AstNode(Token token) |
Modifier and Type | Method and Description |
---|---|
void |
addChild(AstNode child) |
List<AstNode> |
findChildren(AstNodeType... nodeTypes)
Deprecated.
in 1.17, use
getDescendants(AstNodeType...) instead, but don't forget that those methods behave differently due to bug SSLR-249 |
List<AstNode> |
findDirectChildren(AstNodeType... nodeTypes)
Deprecated.
in 1.17, use
getChildren(AstNodeType...) instead |
AstNode |
findFirstChild(AstNodeType... nodeTypes)
Deprecated.
in 1.17, use
getFirstDescendant(AstNodeType...) instead |
AstNode |
findFirstDirectChild(AstNodeType... nodeTypes)
Deprecated.
in 1.17, use
getFirstChild(AstNodeType...) instead |
AstNode |
findFirstParent(AstNodeType nodeType)
Deprecated.
in 1.17, use
getFirstAncestor(AstNodeType) instead |
AstNode |
getChild(int index)
Deprecated.
in 1.19.2, use
getFirstChild(AstNodeType...) instead |
List<AstNode> |
getChildren()
Get the list of children.
|
List<AstNode> |
getChildren(AstNodeType... nodeTypes)
Returns children of specified types.
|
List<AstNode> |
getDescendants(AstNodeType... nodeTypes)
Returns descendants of specified types.
|
AstNode |
getFirstAncestor(AstNodeType... nodeTypes) |
AstNode |
getFirstAncestor(AstNodeType nodeType) |
AstNode |
getFirstChild()
Returns the first child of this node.
|
AstNode |
getFirstChild(AstNodeType... nodeTypes)
Returns first child of one of specified types.
|
AstNode |
getFirstDescendant(AstNodeType... nodeTypes)
Returns first descendant of one of specified types.
|
int |
getFromIndex() |
AstNode |
getLastChild()
Returns the last child of this node.
|
AstNode |
getLastChild(AstNodeType... nodeTypes)
Returns last child of one of specified types.
|
Token |
getLastToken() |
String |
getName() |
AstNode |
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.
|
AstNode |
getNextSibling()
Get the next sibling AstNode if exists in the tree.
|
int |
getNumberOfChildren() |
AstNode |
getParent()
Get the parent of this node in the tree.
|
AstNode |
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.
|
AstNode |
getPreviousSibling()
Get the previous sibling AstNode if exists in the tree.
|
int |
getToIndex() |
Token |
getToken()
Get the Token associated to this AstNode
|
int |
getTokenLine()
Get the Token's line associated to this AstNode
|
String |
getTokenOriginalValue()
Get the Token's original value associated to this AstNode
|
List<Token> |
getTokens()
Return all tokens contained in this tree node.
|
String |
getTokenValue()
Get the Token's value associated to this AstNode
|
AstNodeType |
getType() |
boolean |
hasAncestor(AstNodeType... nodeTypes) |
boolean |
hasAncestor(AstNodeType nodeType) |
boolean |
hasChildren() |
boolean |
hasChildren(AstNodeType... nodeTypes)
Deprecated.
in 1.17, use
hasDescendant(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. |
boolean |
hasDescendant(AstNodeType... nodeTypes) |
boolean |
hasDirectChildren(AstNodeType... nodeTypes) |
boolean |
hasParent(AstNodeType... nodeTypes) |
boolean |
hasParents(AstNodeType nodeType)
Deprecated.
in 1.17, use
hasAncestor(AstNodeType) instead |
boolean |
hasToBeSkippedFromAst()
For internal use only.
|
boolean |
hasToken() |
boolean |
is(AstNodeType... types) |
boolean |
isCopyBookOrGeneratedNode() |
boolean |
isNot(AstNodeType... types) |
AstNode |
nextAstNode()
Deprecated.
in 1.17, use
getNextAstNode() instead |
AstNode |
nextSibling()
Deprecated.
in 1.17, use
getNextSibling() instead |
AstNode |
previousAstNode()
Deprecated.
in 1.17, use
getPreviousAstNode() instead |
AstNode |
previousSibling()
Deprecated.
in 1.17, use
getPreviousSibling() |
AstSelect |
select() |
void |
setFromIndex(int fromIndex) |
void |
setToIndex(int toIndex) |
String |
toString() |
protected AstNodeType type
public AstNode(Token token)
public AstNode(AstNodeType type, String name, @Nullable Token token)
public AstNode getParent()
public void addChild(AstNode child)
public boolean hasChildren()
public int getNumberOfChildren()
@Deprecated public AstNode getChild(int index)
getFirstChild(AstNodeType...)
instead@Deprecated public AstNode nextAstNode()
getNextAstNode()
insteadpublic AstNode getNextAstNode()
@Deprecated public AstNode previousAstNode()
getPreviousAstNode()
insteadpublic AstNode getPreviousAstNode()
@Deprecated public AstNode nextSibling()
getNextSibling()
insteadpublic AstNode getNextSibling()
@Deprecated public AstNode previousSibling()
getPreviousSibling()
public AstNode getPreviousSibling()
public String getTokenValue()
public String getTokenOriginalValue()
public Token getToken()
public int getTokenLine()
public boolean hasToken()
public String getName()
public int getFromIndex()
public void setFromIndex(int fromIndex)
public int getToIndex()
public boolean hasToBeSkippedFromAst()
public void setToIndex(int toIndex)
public boolean is(AstNodeType... types)
public boolean isNot(AstNodeType... types)
@Deprecated public AstNode findFirstDirectChild(AstNodeType... nodeTypes)
getFirstChild(AstNodeType...)
insteadpublic AstNode getFirstChild(AstNodeType... nodeTypes)
In the following case, getFirstChild("B")
would return "B2":
A1 |__ C1 | |__ B1 |__ B2 |__ B3
@Deprecated public AstNode findFirstChild(AstNodeType... nodeTypes)
getFirstDescendant(AstNodeType...)
insteadpublic AstNode getFirstDescendant(AstNodeType... nodeTypes)
In the following case, getFirstDescendant("B")
would return "B1":
A1 |__ C1 | |__ B1 |__ B2 |__ B3
public AstNode getFirstChild()
@Deprecated public List<AstNode> findDirectChildren(AstNodeType... nodeTypes)
getChildren(AstNodeType...)
insteadpublic List<AstNode> getChildren(AstNodeType... nodeTypes)
getChildren("B")
would return "B2" and "B3":
A1 |__ C1 | |__ B1 |__ B2 |__ B3
@Deprecated public List<AstNode> findChildren(AstNodeType... nodeTypes)
getDescendants(AstNodeType...)
instead, but don't forget that those methods behave differently due to bug SSLR-249public List<AstNode> getDescendants(AstNodeType... nodeTypes)
getChildren(AstNodeType...)
when possible.
In the following case, getDescendants("B", "C")
would return "C1", "B1", "B2" and "B3":
A1 |__ C1 | |__ B1 |__ B2 |__ D1 |__ B3
public AstNode getLastChild()
@Nullable public AstNode getLastChild(AstNodeType... nodeTypes)
In the following case, getLastChild("B")
would return "B3":
A1 |__ C1 | |__ B1 |__ B2 |__ B3 |__ B4
public boolean hasDirectChildren(AstNodeType... nodeTypes)
@Deprecated public boolean hasChildren(AstNodeType... nodeTypes)
hasDescendant(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.public boolean hasDescendant(AstNodeType... nodeTypes)
@Deprecated public boolean hasParents(AstNodeType nodeType)
hasAncestor(AstNodeType)
insteadpublic boolean hasParent(AstNodeType... nodeTypes)
public boolean hasAncestor(AstNodeType nodeType)
public boolean hasAncestor(AstNodeType... nodeTypes)
@Deprecated public AstNode findFirstParent(AstNodeType nodeType)
getFirstAncestor(AstNodeType)
insteadpublic AstNode getFirstAncestor(AstNodeType nodeType)
public AstNode getFirstAncestor(AstNodeType... nodeTypes)
public boolean isCopyBookOrGeneratedNode()
public AstNodeType getType()
public List<Token> getTokens()
public Token getLastToken()
@Beta public AstSelect select()
Copyright © 2009–2018 SonarSource. All rights reserved.