Modifier and Type | Field and 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 and Description |
---|
AbstractNode(int id) |
AbstractNode(int id,
int theBeginLine,
int theEndLine,
int theBeginColumn,
int theEndColumn) |
Modifier and Type | Method and 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.
|
<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.
|
<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 |
hasDecendantOfAnyType(java.lang.Class<?>... types) |
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() |
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()
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 |
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) |
abstract java.lang.String |
toString()
Subclasses should implement this method to return a name usable with
XPathRule for evaluating Element Names.
|
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 abstract java.lang.String toString()
toString
in class java.lang.Object
public boolean hasImageEqualTo(java.lang.String image)
hasImageEqualTo
in interface Node
public 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
ancestorsgetNthParent
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 findpublic <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> 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()
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 typepublic final boolean hasDecendantOfAnyType(java.lang.Class<?>... types)
types
- public 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 removedCopyright © 2002–2018 PMD. All rights reserved.