Modifier and Type | Field | Description |
---|---|---|
protected int |
beginColumn |
|
protected int |
beginLine |
|
protected int |
childIndex |
|
protected Node[] |
children |
|
protected int |
endColumn |
|
protected int |
endLine |
|
protected GenericToken |
firstToken |
|
protected int |
id |
|
protected GenericToken |
lastToken |
|
protected Node |
parent |
Constructor | Description |
---|---|
AbstractNode(int id) |
|
AbstractNode(int id,
int theBeginLine,
int theEndLine,
int theBeginColumn,
int theEndColumn) |
Modifier and Type | Method | Description |
---|---|---|
protected void |
appendElement(org.w3c.dom.Node parentNode) |
|
java.util.List<Node> |
findChildNodesWithXPath(java.lang.String xpathString) |
Returns all the nodes matching the xpath expression.
|
<T> java.util.List<T> |
findChildrenOfType(java.lang.Class<T> targetType) |
Traverses the children to find all the instances of type childType or
one of its subclasses.
|
<T> java.util.List<T> |
findDescendantsOfType(java.lang.Class<T> targetType) |
Traverses down the tree to find all the descendant instances of type
descendantType without crossing find boundaries.
|
<T> java.util.List<T> |
findDescendantsOfType(java.lang.Class<T> targetType,
boolean crossBoundaries) |
|
<T> void |
findDescendantsOfType(java.lang.Class<T> targetType,
java.util.List<T> results,
boolean crossBoundaries) |
Traverses down the tree to find all the descendant instances of type
descendantType.
|
org.w3c.dom.Document |
getAsDocument() |
Get a DOM Document which contains Elements and Attributes representative
of this Node and it's children.
|
int |
getBeginColumn() |
|
int |
getBeginLine() |
|
DataFlowNode |
getDataFlowNode() |
|
int |
getEndColumn() |
|
int |
getEndLine() |
|
<T> T |
getFirstChildOfType(java.lang.Class<T> childType) |
Traverses the children to find the first instance of type childType.
|
<T> T |
getFirstDescendantOfType(java.lang.Class<T> descendantType) |
Traverses down the tree to find the first descendant instance of type
descendantType without crossing find boundaries.
|
<T> T |
getFirstParentOfAnyType(java.lang.Class<? extends T>... parentTypes) |
Gets the first parent that's an instance of any of the given types.
|
<T> T |
getFirstParentOfType(java.lang.Class<T> parentType) |
Traverses up the tree to find the first parent instance of type
parentType or one of its subclasses.
|
java.lang.String |
getImage() |
Returns a string token, usually filled-in by the parser, which describes some textual
characteristic of this node.
|
Node |
getNthParent(int n) |
Returns the n-th parent or null if there are less than
n ancestors. |
<T> java.util.List<T> |
getParentsOfType(java.lang.Class<T> parentType) |
Traverses up the tree to find all of the parent instances of type
parentType or one of its subclasses.
|
java.lang.Object |
getUserData() |
Get the user data associated with this node.
|
java.lang.String |
getXPathNodeName() |
Gets the name of the node that is used to match it with XPath queries.
|
boolean |
hasDecendantOfAnyType(java.lang.Class<?>... types) |
Deprecated.
|
boolean |
hasDescendantMatchingXPath(java.lang.String xpathString) |
Checks whether at least one descendant matches the xpath expression.
|
boolean |
hasDescendantOfAnyType(java.lang.Class<?>... types) |
Returns true if this node has a descendant of any type among the provided types.
|
<T> boolean |
hasDescendantOfType(java.lang.Class<T> type) |
Finds if this node contains a descendant of the given type without crossing find boundaries.
|
boolean |
hasImageEqualTo(java.lang.String image) |
Returns true if this node's image is equal to the given string.
|
boolean |
isFindBoundary() |
Returns true if this node is considered a boundary by traversal methods.
|
boolean |
isSingleLine() |
|
void |
jjtAddChild(Node child,
int index) |
This method tells the node to add its argument to the node's list of
children.
|
void |
jjtClose() |
This method is called after all the child nodes have been added.
|
Node |
jjtGetChild(int index) |
This method returns a child node.
|
int |
jjtGetChildIndex() |
Gets the index of this node in the children of its parent.
|
GenericToken |
jjtGetFirstToken() |
|
int |
jjtGetId() |
|
GenericToken |
jjtGetLastToken() |
|
int |
jjtGetNumChildren() |
Returns the number of children the node has.
|
Node |
jjtGetParent() |
Returns the parent of this node.
|
void |
jjtOpen() |
This method is called after the node has been made the current node.
|
void |
jjtSetChildIndex(int index) |
Sets the index of this node from the perspective of its parent.
|
void |
jjtSetFirstToken(GenericToken token) |
|
void |
jjtSetLastToken(GenericToken token) |
|
void |
jjtSetParent(Node parent) |
Sets the parent of this node.
|
void |
remove() |
Remove the current node from its parent.
|
void |
removeChildAtIndex(int childIndex) |
This method tells the node to remove the child node at the given index from the node's list of
children, if any; if not, no changes are done.
|
void |
setDataFlowNode(DataFlowNode dataFlowNode) |
|
void |
setImage(java.lang.String image) |
|
void |
setUserData(java.lang.Object userData) |
Set the user data associated with this node.
|
void |
testingOnlySetBeginColumn(int i) |
|
void |
testingOnlySetBeginLine(int i) |
|
void |
testingOnlySetEndColumn(int i) |
|
void |
testingOnlySetEndLine(int i) |
|
java.lang.String |
toString() |
Deprecated.
The equivalence between toString and a node's name could be broken as soon as release 7.0.0.
|
protected Node parent
protected Node[] children
protected int childIndex
protected int id
protected int beginLine
protected int endLine
protected int beginColumn
protected int endColumn
protected GenericToken firstToken
protected GenericToken lastToken
public AbstractNode(int id)
public AbstractNode(int id, int theBeginLine, int theEndLine, int theBeginColumn, int theEndColumn)
public boolean isSingleLine()
public void jjtOpen()
Node
public void jjtClose()
Node
public void jjtSetParent(Node parent)
Node
jjtSetParent
in interface Node
parent
- The parentpublic Node jjtGetParent()
Node
jjtGetParent
in interface Node
public void jjtAddChild(Node child, int index)
Node
jjtAddChild
in interface Node
child
- The child to addindex
- The index to which the child will be addedpublic void jjtSetChildIndex(int index)
Node
jjtSetChildIndex
in interface Node
index
- the child indexpublic int jjtGetChildIndex()
Node
jjtGetChildIndex
in interface Node
public Node jjtGetChild(int index)
Node
jjtGetChild
in interface Node
index
- the child index. Must be nonnegative and less than
Node.jjtGetNumChildren()
.public int jjtGetNumChildren()
Node
jjtGetNumChildren
in interface Node
public java.lang.String getImage()
Node
null
.public boolean hasImageEqualTo(java.lang.String image)
Node
hasImageEqualTo
in interface Node
image
- The image to checkpublic int getBeginLine()
getBeginLine
in interface Node
public void testingOnlySetBeginLine(int i)
public int getBeginColumn()
getBeginColumn
in interface Node
public void testingOnlySetBeginColumn(int i)
public int getEndLine()
getEndLine
in interface Node
public void testingOnlySetEndLine(int i)
public int getEndColumn()
getEndColumn
in interface Node
public void testingOnlySetEndColumn(int i)
public DataFlowNode getDataFlowNode()
getDataFlowNode
in interface Node
public void setDataFlowNode(DataFlowNode dataFlowNode)
setDataFlowNode
in interface Node
public Node getNthParent(int n)
Node
n
ancestors.getNthParent
in interface Node
n
- how many ancestors to iterate over.public <T> T getFirstParentOfType(java.lang.Class<T> parentType)
Node
getFirstParentOfType
in interface Node
T
- The type you want to findparentType
- Class literal of the type you want to findpublic <T> java.util.List<T> getParentsOfType(java.lang.Class<T> parentType)
Node
getParentsOfType
in interface Node
T
- The type you want to findparentType
- Class literal of the type you want to find@SafeVarargs public final <T> T getFirstParentOfAnyType(java.lang.Class<? extends T>... parentTypes)
Node
getFirstParentOfAnyType
in interface Node
T
- Most specific common type of the parametersparentTypes
- Types to look forpublic <T> java.util.List<T> findDescendantsOfType(java.lang.Class<T> targetType)
Node
findDescendantsOfType
in interface Node
targetType
- class which you want to find.public <T> java.util.List<T> findDescendantsOfType(java.lang.Class<T> targetType, boolean crossBoundaries)
public <T> void findDescendantsOfType(java.lang.Class<T> targetType, java.util.List<T> results, boolean crossBoundaries)
Node
findDescendantsOfType
in interface Node
targetType
- class which you want to find.results
- list to store the matching descendantscrossBoundaries
- if false
, recursion stops for nodes for which
Node.isFindBoundary()
is true
public <T> java.util.List<T> findChildrenOfType(java.lang.Class<T> targetType)
Node
findChildrenOfType
in interface Node
targetType
- class which you want to find.if traversal of the entire tree is
needed.
public boolean isFindBoundary()
Node
Node.getFirstDescendantOfType(Class)
don't
look past such boundaries by default, which is usually the expected thing
to do. For example, in Java, lambdas and nested classes are considered
find boundaries.isFindBoundary
in interface Node
public org.w3c.dom.Document getAsDocument()
Node
getAsDocument
in interface Node
protected void appendElement(org.w3c.dom.Node parentNode)
public <T> T getFirstDescendantOfType(java.lang.Class<T> descendantType)
Node
getFirstDescendantOfType
in interface Node
descendantType
- class which you want to find.null
if none
found.public <T> T getFirstChildOfType(java.lang.Class<T> childType)
Node
getFirstChildOfType
in interface Node
childType
- class which you want to find.null
if none found.if traversal of the entire tree is
needed.
public final <T> boolean hasDescendantOfType(java.lang.Class<T> type)
Node
hasDescendantOfType
in interface Node
type
- the node type to searchtrue
if there is at least one descendant of the
given type@Deprecated public final boolean hasDecendantOfAnyType(java.lang.Class<?>... types)
types
- Types to testpublic final boolean hasDescendantOfAnyType(java.lang.Class<?>... types)
types
- Types to testpublic java.util.List<Node> findChildNodesWithXPath(java.lang.String xpathString) throws org.jaxen.JaxenException
Node
findChildNodesWithXPath
in interface Node
xpathString
- the expression to checkorg.jaxen.JaxenException
- if the xpath is incorrect or fails altogetherpublic boolean hasDescendantMatchingXPath(java.lang.String xpathString)
Node
hasDescendantMatchingXPath
in interface Node
xpathString
- the expression to checkpublic java.lang.Object getUserData()
Node
Node.setUserData(Object)
.getUserData
in interface Node
public void setUserData(java.lang.Object userData)
Node
PMD itself will never set user data onto a node. Nor should any Rule implementation, as the AST nodes are shared between concurrently executing Rules (i.e. it is not thread-safe).
This API is most useful for external applications looking to leverage PMD's robust support for AST structures, in which case application specific annotations on the AST nodes can be quite useful.
setUserData
in interface Node
userData
- The data to set on this node.public GenericToken jjtGetFirstToken()
public void jjtSetFirstToken(GenericToken token)
public GenericToken jjtGetLastToken()
public void jjtSetLastToken(GenericToken token)
public void remove()
Node
public void removeChildAtIndex(int childIndex)
Node
removeChildAtIndex
in interface Node
childIndex
- The index of the child to be removedpublic java.lang.String getXPathNodeName()
This default implementation adds compatibility with the previous
way to get the xpath node name, which used Object.toString()
.
Please override it. It may be removed in a future major version.
getXPathNodeName
in interface Node
@Deprecated public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2002–2018 PMD. All rights reserved.