Added another version of findChildrenOfType
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1463 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -131,10 +131,7 @@ public class SimpleNodeTest
|
||||
public void testFindChildrenOfType() {
|
||||
ASTBlock block = new ASTBlock(2);
|
||||
block.jjtAddChild(new ASTReturnStatement(1), 0);
|
||||
|
||||
List nodes = new ArrayList();
|
||||
block.findChildrenOfType(ASTReturnStatement.class, nodes);
|
||||
assertEquals(1, nodes.size());
|
||||
assertEquals(1, block.findChildrenOfType(ASTReturnStatement.class).size());
|
||||
}
|
||||
|
||||
public void testFindChildrenOfTypeMultiple() {
|
||||
|
@ -4,6 +4,7 @@ package net.sourceforge.pmd.ast;
|
||||
import net.sourceforge.pmd.symboltable.Scope;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SimpleNode implements Node {
|
||||
protected Node parent;
|
||||
@ -100,6 +101,12 @@ public class SimpleNode implements Node {
|
||||
return endColumn;
|
||||
}
|
||||
|
||||
public List findChildrenOfType(Class targetType) {
|
||||
List list = new ArrayList();
|
||||
findChildrenOfType(targetType, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public void findChildrenOfType(Class targetType, List results) {
|
||||
findChildrenOfType(this, targetType, results, true);
|
||||
}
|
||||
|
@ -24,9 +24,7 @@ public class AssignmentInOperandRule extends AbstractRule implements Rule {
|
||||
}
|
||||
|
||||
private void checkForAssignmentInConditionalExpression(SimpleNode node, Object data) {
|
||||
List kids = new ArrayList();
|
||||
SimpleNode ifExpression = (SimpleNode)node.jjtGetChild(0);
|
||||
ifExpression.findChildrenOfType(ASTAssignmentOperator.class, kids);
|
||||
List kids = ((SimpleNode)node.jjtGetChild(0)).findChildrenOfType(ASTAssignmentOperator.class);
|
||||
if (!kids.isEmpty()) {
|
||||
RuleContext ctx = (RuleContext)data;
|
||||
ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine()));
|
||||
|
@ -14,9 +14,7 @@ import java.util.List;
|
||||
public class AtLeastOneConstructorRule extends AbstractRule implements Rule {
|
||||
|
||||
public Object visit(ASTClassDeclaration node, Object data) {
|
||||
List constructors = new ArrayList();
|
||||
node.findChildrenOfType(ASTConstructorDeclaration.class, constructors);
|
||||
if (constructors.isEmpty()) {
|
||||
if (node.findChildrenOfType(ASTConstructorDeclaration.class).isEmpty()) {
|
||||
RuleContext ctx = (RuleContext)data;
|
||||
ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine()));
|
||||
}
|
||||
|
Reference in New Issue
Block a user