forked from phoedos/pmd
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:
@ -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
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user