Added Jeff Anderson's node finding utilities
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2286 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -96,6 +96,41 @@ public class SimpleNode implements Node {
|
||||
return endColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses up the tree to find the first parent instance of type parentType
|
||||
* @param parentType class which you want to find.
|
||||
* @return Node of type parentType. Returns null if none found.
|
||||
*/
|
||||
public Node getFirstParentOfType(Class parentType) {
|
||||
Node parentNode = jjtGetParent();
|
||||
|
||||
while (parentNode != null && parentNode.getClass() != parentType) {
|
||||
parentNode = parentNode.jjtGetParent();
|
||||
}
|
||||
|
||||
return parentNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses up the tree to find all of the parent instances of type parentType
|
||||
* @param parentType classes which you want to find.
|
||||
* @return List of parentType instances found.
|
||||
*/
|
||||
public List getParentsOfType(Class parentType) {
|
||||
List parents = new ArrayList();
|
||||
Node parentNode = jjtGetParent();
|
||||
|
||||
while (parentNode != null) {
|
||||
if (parentNode.getClass() == parentType) {
|
||||
parents.add(parentNode);
|
||||
}
|
||||
|
||||
parentNode = parentNode.jjtGetParent();
|
||||
}
|
||||
|
||||
return parents;
|
||||
}
|
||||
|
||||
public List findChildrenOfType(Class targetType) {
|
||||
List list = new ArrayList();
|
||||
findChildrenOfType(targetType, list);
|
||||
|
@ -38,6 +38,7 @@
|
||||
</subsection>
|
||||
<subsection name="Contributors">
|
||||
<ul>
|
||||
<li>Jeff Anderson - some node finding utility code</li>
|
||||
<li>Boris Gruschko - regression test suites, nifty AST/XPath viewer</li>
|
||||
<li>Jeff Epstein - put together the TextPad integration </li>
|
||||
<li>Trevor Harmon - rewrote XSLT script</li>
|
||||
|
Reference in New Issue
Block a user