public interface Node
Modifier and Type | Method and Description |
---|---|
java.util.List<? extends Node> |
findChildNodesWithXPath(java.lang.String xpathString)
Returns all the nodes matching the xpath expression.
|
<T> java.util.List<T> |
findChildrenOfType(java.lang.Class<T> childType)
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.
|
<T> void |
findDescendantsOfType(java.lang.Class<T> targetType,
java.util.List<T> results,
boolean crossFindBoundaries)
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.
|
<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() |
Node |
getNthParent(int n)
Returns the n-th parent or null if there are not
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.
|
boolean |
hasDescendantMatchingXPath(java.lang.String xpathString)
Checks whether at least one descendant matches the xpath expression.
|
<T> boolean |
hasDescendantOfType(java.lang.Class<T> type)
Finds if this node contains a descendant of the given type.
|
boolean |
hasImageEqualTo(java.lang.String image) |
boolean |
isFindBoundary() |
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.
|
int |
jjtGetId() |
int |
jjtGetNumChildren()
Return 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 |
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 jjtOpen()
void jjtClose()
void jjtSetParent(Node parent)
parent
- The parentNode jjtGetParent()
void jjtAddChild(Node child, int index)
child
- The child to addindex
- The index to which the child will be addedvoid jjtSetChildIndex(int index)
index
- the child indexint jjtGetChildIndex()
Node jjtGetChild(int index)
index
- the child index. Must be nonnegative and less than
jjtGetNumChildren()
.int jjtGetNumChildren()
int jjtGetId()
java.lang.String getImage()
void setImage(java.lang.String image)
boolean hasImageEqualTo(java.lang.String image)
int getBeginLine()
int getBeginColumn()
int getEndLine()
int getEndColumn()
DataFlowNode getDataFlowNode()
void setDataFlowNode(DataFlowNode dataFlowNode)
boolean isFindBoundary()
Node getNthParent(int n)
n
ancestorsn
- how many ancestors to iterate over.java.lang.IllegalArgumentException
- if n
is negative or zero.<T> T getFirstParentOfType(java.lang.Class<T> parentType)
T
- The type you want to findparentType
- Class literal of the type you want to find<T> java.util.List<T> getParentsOfType(java.lang.Class<T> parentType)
T
- The type you want to findparentType
- Class literal of the type you want to find<T> java.util.List<T> findChildrenOfType(java.lang.Class<T> childType)
childType
- class which you want to find.if traversal of the entire tree is
needed.
<T> java.util.List<T> findDescendantsOfType(java.lang.Class<T> targetType)
targetType
- class which you want to find.<T> void findDescendantsOfType(java.lang.Class<T> targetType, java.util.List<T> results, boolean crossFindBoundaries)
targetType
- class which you want to find.results
- list to store the matching descendantscrossFindBoundaries
- if false
, recursion stops for nodes for which
isFindBoundary()
is true
<T> T getFirstChildOfType(java.lang.Class<T> childType)
childType
- class which you want to find.null
if none found.if traversal of the entire tree is
needed.
<T> T getFirstDescendantOfType(java.lang.Class<T> descendantType)
descendantType
- class which you want to find.null
if none
found.<T> boolean hasDescendantOfType(java.lang.Class<T> type)
type
- the node type to searchtrue
if there is at least one descendant of the
given typejava.util.List<? extends Node> findChildNodesWithXPath(java.lang.String xpathString) throws org.jaxen.JaxenException
xpathString
- the expression to checkorg.jaxen.JaxenException
- if the xpath is incorrect or fails altogetherboolean hasDescendantMatchingXPath(java.lang.String xpathString)
xpathString
- the expression to checkorg.w3c.dom.Document getAsDocument()
java.lang.Object getUserData()
setUserData(Object)
.void setUserData(java.lang.Object userData)
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.
userData
- The data to set on this node.void remove()
void removeChildAtIndex(int childIndex)
childIndex
- The index of the child to be removedCopyright © 2002–2017 PMD. All rights reserved.