Fixed bug in EmptyCatchBlockRule

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@87 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-06-27 13:49:11 +00:00
parent bdb6c077fa
commit 2dac4f08e8
4 changed files with 12 additions and 4 deletions

View File

@ -1,6 +1,7 @@
??? - 0.2:
Added IfElseStmtsMustUseBracesRule
Modified command line interface to accept a rule set
Fixed bug in EmptyCatchBlockRule
June 25 2002 - 0.1:
Initial release

View File

@ -2,4 +2,4 @@
set MAIN=net.sourceforge.pmd.PMD
set TEST_FILE=c:\\data\\pmd\\pmd\\test-data\\%1%.java
java %MAIN% %TEST_FILE% %2%
java %MAIN% %TEST_FILE% xml general

View File

@ -85,6 +85,11 @@ public class FunctionalTest extends TestCase{
assertEquals(new EmptyCatchBlockRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testEmptyCatchBlock2() {
Report report = process("EmptyCatchBlock2.java");
assertTrue(report.currentFileHasNoViolations());
}
public void testUnnecessaryTemporaries() {
Report report = process("UnnecessaryTemporary.java");
assertEquals(6, report.countViolationsInCurrentFile());

View File

@ -7,17 +7,19 @@ package net.sourceforge.pmd.rules;
import net.sourceforge.pmd.ast.ASTBlock;
import net.sourceforge.pmd.ast.ASTTryStatement;
import net.sourceforge.pmd.ast.ASTBlockStatement;
import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.*;
public class EmptyCatchBlockRule extends AbstractRule implements Rule {
public String getDescription() {return "Avoid empty catch blocks";}
public Object visit(ASTBlock node, Object data){
if ((node.jjtGetParent() instanceof ASTTryStatement) && node.jjtGetNumChildren()==0) {
public Object visit(ASTTryStatement node, Object data){
ASTBlock catchBlock = (ASTBlock)node.jjtGetChild(2);
if (catchBlock.jjtGetNumChildren() == 0) {
(((RuleContext)data).getReport()).addRuleViolation(new RuleViolation(this, node.getBeginLine()));
}
return super.visit(node, data);
}
}