public abstract class AbstractNode extends Object implements Node
| Modifier and Type | Field and Description |
|---|---|
protected int |
beginColumn |
protected int |
beginLine |
protected Node[] |
children |
protected int |
endColumn |
protected int |
endLine |
protected int |
id |
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(Node parentNode) |
List |
findChildNodesWithXPath(String xpathString)
Returns all the nodes matching the xpath expression.
|
<T> List<T> |
findChildrenOfType(Class<T> targetType)
Traverses the children to find all the instances of type childType.
|
<T> List<T> |
findDescendantsOfType(Class<T> targetType)
Traverses down the tree to find all the descendant instances of type descendantType.
|
<T> void |
findDescendantsOfType(Class<T> targetType,
List<T> results,
boolean crossBoundaries)
Traverses down the tree to find all the descendant instances of type descendantType.
|
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(Class<T> childType)
Traverses the children to find the first instance of type childType.
|
<T> T |
getFirstDescendantOfType(Class<T> descendantType)
Traverses down the tree to find the first descendant instance of type descendantType.
|
<T> T |
getFirstParentOfType(Class<T> parentType)
Traverses up the tree to find the first parent instance of type parentType
|
String |
getImage() |
Node |
getNthParent(int n)
Returns the n-th parent or null if there are not
n ancestors |
<T> List<T> |
getParentsOfType(Class<T> parentType)
Traverses up the tree to find all of the parent instances of type parentType
|
Object |
getUserData()
Get the user data associated with this node.
|
boolean |
hasDecendantOfAnyType(Class<?>... types) |
boolean |
hasDescendantMatchingXPath(String xpathString)
Checks whether at least one descendant matches the xpath expression.
|
<T> boolean |
hasDescendantOfType(Class<T> type)
Finds if this node contains a descendant of the given type.
|
boolean |
hasImageEqualTo(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 |
jjtGetId() |
int |
jjtGetNumChildren()
Return the number of children the node has.
|
Node |
jjtGetParent() |
void |
jjtOpen()
This method is called after the node has been made the current
node.
|
void |
jjtSetParent(Node parent)
This pair of methods are used to inform the node of its
parent.
|
void |
setDataFlowNode(DataFlowNode dataFlowNode) |
void |
setImage(String image) |
void |
setUserData(Object userData)
Set the user data associated with this node.
|
void |
testingOnly__setBeginColumn(int i) |
void |
testingOnly__setBeginLine(int i) |
void |
testingOnly__setEndColumn(int i) |
void |
testingOnly__setEndLine(int i) |
abstract 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 id
protected int beginLine
protected int endLine
protected int beginColumn
protected int endColumn
public AbstractNode(int id)
public AbstractNode(int id,
int theBeginLine,
int theEndLine,
int theBeginColumn,
int theEndColumn)
public boolean isSingleLine()
public void jjtOpen()
Nodepublic void jjtClose()
Nodepublic void jjtSetParent(Node parent)
NodejjtSetParent in interface Nodepublic Node jjtGetParent()
jjtGetParent in interface Nodepublic void jjtAddChild(Node child, int index)
NodejjtAddChild in interface Nodepublic Node jjtGetChild(int index)
NodejjtGetChild in interface Nodeindex - the child index. Must be nonnegative and less than
Node.jjtGetNumChildren().public int jjtGetNumChildren()
NodejjtGetNumChildren in interface Nodepublic abstract String toString()
public boolean hasImageEqualTo(String image)
hasImageEqualTo in interface Nodepublic int getBeginLine()
getBeginLine in interface Nodepublic void testingOnly__setBeginLine(int i)
public int getBeginColumn()
getBeginColumn in interface Nodepublic void testingOnly__setBeginColumn(int i)
public int getEndLine()
getEndLine in interface Nodepublic void testingOnly__setEndLine(int i)
public int getEndColumn()
getEndColumn in interface Nodepublic void testingOnly__setEndColumn(int i)
public DataFlowNode getDataFlowNode()
getDataFlowNode in interface Nodepublic void setDataFlowNode(DataFlowNode dataFlowNode)
setDataFlowNode in interface Nodepublic Node getNthParent(int n)
n ancestorsgetNthParent in interface Noden - how many ancestors to iterate over.IllegalArgumentException - if n is not positive.public <T> T getFirstParentOfType(Class<T> parentType)
getFirstParentOfType in interface NodeparentType - class which you want to find.public <T> List<T> getParentsOfType(Class<T> parentType)
getParentsOfType in interface NodeparentType - classes which you want to find.public <T> List<T> findDescendantsOfType(Class<T> targetType)
findDescendantsOfType in interface NodetargetType - class which you want to find.public <T> void findDescendantsOfType(Class<T> targetType, List<T> results, boolean crossBoundaries)
findDescendantsOfType in interface NodetargetType - class which you want to find.results - list to store the matching descendantscrossBoundaries - if false, recursion stops for nodes for which Node.isFindBoundary() is truepublic <T> List<T> findChildrenOfType(Class<T> targetType)
findChildrenOfType in interface NodetargetType - class which you want to find.if traversal of the entire tree is needed.public boolean isFindBoundary()
isFindBoundary in interface Nodepublic Document getAsDocument()
NodegetAsDocument in interface Nodeprotected void appendElement(Node parentNode)
public <T> T getFirstDescendantOfType(Class<T> descendantType)
getFirstDescendantOfType in interface NodedescendantType - class which you want to find.null if none found.public <T> T getFirstChildOfType(Class<T> childType)
getFirstChildOfType in interface NodechildType - class which you want to find.null if none found.if traversal of the entire tree is needed.public final <T> boolean hasDescendantOfType(Class<T> type)
hasDescendantOfType in interface Nodetype - the node type to searchtrue if there is at least one descendant of the given typepublic final boolean hasDecendantOfAnyType(Class<?>... types)
types - public List findChildNodesWithXPath(String xpathString) throws org.jaxen.JaxenException
findChildNodesWithXPath in interface NodexpathString - the expression to checkorg.jaxen.JaxenExceptionpublic boolean hasDescendantMatchingXPath(String xpathString)
hasDescendantMatchingXPath in interface NodexpathString - the expression to checkpublic Object getUserData()
Node.setUserData(Object).getUserData in interface Nodepublic void setUserData(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.
setUserData in interface NodeuserData - The data to set on this node.Copyright © 2002-2014 InfoEther. All Rights Reserved.