forked from phoedos/pmd
Added new rule
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@90 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -30,8 +30,8 @@
|
||||
<target name="pmd">
|
||||
<taskdef name="pmd" classname="net.sourceforge.pmd.PMDTask"/>
|
||||
<pmd reportFile="c:\pmd.xml" verbose="false" rulesettype="general" format="xml">
|
||||
<fileset dir="c:\data\pmd\pmd\src">
|
||||
<!--<fileset dir="c:\j2sdk1.4.0\src">-->
|
||||
<!--<fileset dir="c:\data\pmd\pmd\src">-->
|
||||
<fileset dir="c:\j2sdk1.4.0\src">
|
||||
<include name="**/*.java"/>
|
||||
</fileset>
|
||||
</pmd>
|
||||
|
@ -1,7 +1,11 @@
|
||||
??? - 0.2:
|
||||
Added IfElseStmtsMustUseBracesRule
|
||||
Added new rules:
|
||||
+IfElseStmtsMustUseBracesRule
|
||||
+EmptyWhileStmtRule
|
||||
Modified command line interface to accept a rule set
|
||||
Fixed bug in EmptyCatchBlockRule
|
||||
Fixed type in UnnecessaryConversionTemporaryRule
|
||||
|
||||
|
||||
June 25 2002 - 0.1:
|
||||
Initial release
|
||||
|
@ -1,6 +1,6 @@
|
||||
update the xdocs to reflect any new release changes
|
||||
update the xdocs:
|
||||
+command line ui now takes a filename, format, rule set
|
||||
update the changelog.txt
|
||||
update the readme.txt (when we get one)
|
||||
|
||||
ant dist
|
||||
rename jar to pmd-0.2.jar
|
||||
|
@ -138,6 +138,12 @@ public class FunctionalTest extends TestCase{
|
||||
assertEquals(new EmptyIfStmtRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
|
||||
}
|
||||
|
||||
public void testEmptyWhileStmtRule() {
|
||||
Report report = process("EmptyWhileStmtRule.java");
|
||||
assertEquals(1, report.countViolationsInCurrentFile());
|
||||
assertEquals(new EmptyWhileStmtRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
|
||||
}
|
||||
|
||||
public void testUnusedPrivateInstanceVar1() {
|
||||
Report report = process("UnusedPrivateInstanceVar1.java");
|
||||
assertEquals(1, report.countViolationsInCurrentFile());
|
||||
|
@ -56,6 +56,7 @@ public class RuleFactory {
|
||||
List list = new ArrayList();
|
||||
list.add(new EmptyCatchBlockRule());
|
||||
list.add(new EmptyIfStmtRule());
|
||||
list.add(new EmptyWhileStmtRule());
|
||||
list.add(new UnnecessaryConversionTemporaryRule());
|
||||
list.add(new UnusedLocalVariableRule());
|
||||
list.add(new UnusedPrivateInstanceVariableRule());
|
||||
|
@ -12,7 +12,7 @@ import net.sourceforge.pmd.ast.ASTIfStatement;
|
||||
import net.sourceforge.pmd.*;
|
||||
|
||||
public class EmptyIfStmtRule extends AbstractRule implements Rule {
|
||||
public String getDescription() {return "Avoid empty IF statements";}
|
||||
public String getDescription() {return "Avoid empty 'if' statements";}
|
||||
|
||||
public Object visit(ASTBlock node, Object data){
|
||||
if ((node.jjtGetParent().jjtGetParent() instanceof ASTIfStatement) && node.jjtGetNumChildren()==0) {
|
||||
|
45
pmd/src/net/sourceforge/pmd/rules/EmptyWhileStmtRule.java
Normal file
45
pmd/src/net/sourceforge/pmd/rules/EmptyWhileStmtRule.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* User: tom
|
||||
* Date: Jun 27, 2002
|
||||
* Time: 11:40:07 AM
|
||||
*/
|
||||
package net.sourceforge.pmd.rules;
|
||||
|
||||
import net.sourceforge.pmd.AbstractRule;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.ast.*;
|
||||
|
||||
public class EmptyWhileStmtRule extends AbstractRule implements Rule{
|
||||
public String getDescription() {return "Avoid empty 'while' statements";}
|
||||
|
||||
/**
|
||||
* We're looking for anything other than
|
||||
* WhileStmt
|
||||
* Expression
|
||||
* Statement
|
||||
* Block
|
||||
* BlockStmt
|
||||
*/
|
||||
public Object visit(ASTWhileStatement node, Object data){
|
||||
ASTStatement stmt = (ASTStatement)node.jjtGetChild(1);
|
||||
|
||||
// can this happen? an Statement without a child?
|
||||
if (stmt.jjtGetNumChildren() == 0) {
|
||||
return super.visit(node, data);
|
||||
}
|
||||
|
||||
// an Statement whose child is not a Block... this might be caught be another braces type rule
|
||||
if (!(stmt.jjtGetChild(0) instanceof ASTBlock)) {
|
||||
return super.visit(node, data);
|
||||
}
|
||||
|
||||
ASTBlock block = (ASTBlock)stmt.jjtGetChild(0);
|
||||
// this block must have 1 child, and that child must be a BlockStatement
|
||||
if (block.jjtGetNumChildren() == 0 || (!(block.jjtGetChild(0) instanceof ASTBlockStatement))) {
|
||||
(((RuleContext)data).getReport()).addRuleViolation(new RuleViolation(this, node.getBeginLine()));
|
||||
}
|
||||
return super.visit(node, data);
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ public class UnnecessaryConversionTemporaryRule extends AbstractRule implements
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return "Avoid unnecessay temporaries when converting primitives to Strings";
|
||||
return "Avoid unnecessary temporaries when converting primitives to Strings";
|
||||
}
|
||||
|
||||
public Object visit(ASTPrimaryExpression node, Object data) {
|
||||
|
10
pmd/test-data/EmptyWhileStmtRule.java
Normal file
10
pmd/test-data/EmptyWhileStmtRule.java
Normal file
@ -0,0 +1,10 @@
|
||||
public class EmptyWhileStmtRule {
|
||||
public EmptyWhileStmtRule() {
|
||||
while (true == true) {
|
||||
}
|
||||
while (true == true) {
|
||||
String x = "";
|
||||
x = "hi";
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user