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:
Tom Copeland
2003-09-30 14:04:09 +00:00
parent d87f4761b8
commit 6466419b1a
2 changed files with 36 additions and 0 deletions

View File

@ -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);

View File

@ -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>