Cleaning up a few more loose ends

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@3546 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2005-06-09 02:01:24 +00:00
parent d2e32f7d3c
commit ed80d36429
5 changed files with 17 additions and 24 deletions

View File

@ -7,6 +7,7 @@ Fixed bug 1052356 - ImmutableField no longer triggers on fields which are assign
Fixed bug 1215854 - Package/class/method name are now filled in whenever possible, and the XML report includes all three.
Fixed bug which caused MissingSerialVersionUID to trigger on all interfaces that implemented other interfaces.
Added two new node types - ASTCatchStatement and ASTFinallyStatement.
Modified rule XML definition; it no longer includes a symboltable attribute.
Implemented RFE 1188604 - AvoidThrowingCertainExceptionTypes has been split into AvoidThrowingRawExceptionTypes and AvoidThrowingNullPointerException.
Implemented RFE 1188369 - UnnecessaryBooleanAssertion now checks for things like 'assertTrue(!foo)'. These should be changed to 'assertFalse(foo)' for clarity.
Implemented RFE 1199622 - UnusedFormalParameter now defaults to only checking private methods unless a 'checkall' property is set.

View File

@ -39,9 +39,9 @@ public class LoggerIsNotStaticFinalTest extends SimpleAggregatorTst {
private static final String TEST3 =
"public class Foo {" + PMD.EOL +
" static final String log;" + PMD.EOL +
" static final Logger log;" + PMD.EOL +
" static class c { " + PMD.EOL +
" static final String log;" + PMD.EOL +
" static final Logger log;" + PMD.EOL +
" } " + PMD.EOL +
"}";

View File

@ -30,6 +30,7 @@ import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.stat.DataPoint;
import net.sourceforge.pmd.stat.Metric;
import net.sourceforge.pmd.stat.StatisticalRule;
import net.sourceforge.pmd.symboltable.SourceFileScope;
import java.util.ArrayList;
@ -266,14 +267,15 @@ public class StatisticalRuleTest extends TestCase {
}
// Test Single Datapoint
/*
public void testSingleDatapoint() {
StatisticalRule IUT = new MockStatisticalRule();
DataPoint point = new DataPoint();
point.setScore(POINTS + 1.0);
SimpleNode s = new SimpleNode(1);
s.setScope(new SourceFileScope("foo"));
s.testingOnly__setBeginLine(POINTS + 1);
s.testingOnly__setBeginColumn(1);
point.setNode(s);
point.setMessage("SingleDataPoint");
@ -285,7 +287,6 @@ public class StatisticalRuleTest extends TestCase {
assertEquals("Expecting only one result.", 1, report.size());
}
*/
// Okay, we have three properties we need to
// test in Combination:

View File

@ -8,7 +8,6 @@ The Unused Code Ruleset contains a collection of rules that find unused code.
<rule name="UnusedPrivateField"
message="Avoid unused private fields such as ''{0}''"
class="net.sourceforge.pmd.rules.UnusedPrivateFieldRule">
<description>
Detects when a private field is declared and/or assigned a value, but not used.
@ -30,7 +29,6 @@ public class Something {
<rule name="UnusedLocalVariable"
message="Avoid unused local variables such as ''{0}''"
class="net.sourceforge.pmd.rules.UnusedLocalVariableRule">
<description>
Detects when a local variable is declared and/or assigned, but not used.
@ -67,7 +65,6 @@ public class Something {
<rule name="UnusedFormalParameter"
message="Avoid unused formal parameters such as ''{0}''"
class="net.sourceforge.pmd.rules.UnusedFormalParameterRule">
<description>
Avoid passing parameters to methods and then not using those parameters.

View File

@ -107,41 +107,27 @@ public abstract class AbstractRule extends JavaParserVisitorAdapter implements R
return getName().hashCode();
}
protected void visitAll(List acus, RuleContext ctx) {
for (Iterator i = acus.iterator(); i.hasNext();) {
ASTCompilationUnit node = (ASTCompilationUnit) i.next();
visit(node, ctx);
}
}
public void apply(List acus, RuleContext ctx) {
visitAll(acus, ctx);
}
public RuleViolation createRuleViolation(RuleContext ctx, SimpleNode node) {
String packageName = node.getScope().getEnclosingSourceFileScope().getPackageName() == null ? "" : node.getScope().getEnclosingSourceFileScope().getPackageName();
String className = findClassName(node);
String methodName = findMethodName(node);
RuleViolation v = new RuleViolation(this, ctx, packageName, className, methodName);
RuleViolation v = new RuleViolation(this, ctx, packageName, findClassName(node), findMethodName(node));
extractNodeInfo(v, node);
return v;
}
public RuleViolation createRuleViolation(RuleContext ctx, SimpleNode node, String specificDescription) {
String packageName = node.getScope().getEnclosingSourceFileScope().getPackageName() == null ? "" : node.getScope().getEnclosingSourceFileScope().getPackageName();
String className = findClassName(node);
String methodName = findMethodName(node);
RuleViolation rv = new RuleViolation(this, node.getBeginLine(), specificDescription, ctx, packageName, className, methodName);
RuleViolation rv = new RuleViolation(this, node.getBeginLine(), specificDescription, ctx, packageName, findClassName(node), findMethodName(node));
extractNodeInfo(rv, node);
return rv;
}
public RuleViolation createRuleViolation(RuleContext ctx, SimpleNode node, String variableName, String specificDescription) {
String packageName = node.getScope().getEnclosingSourceFileScope().getPackageName() == null ? "" : node.getScope().getEnclosingSourceFileScope().getPackageName();
String className = findClassName(node);
String methodName = findMethodName(node);
return new RuleViolation(this, node.getBeginLine(), node.getEndLine(), variableName, specificDescription, ctx, packageName, className, methodName);
return new RuleViolation(this, node.getBeginLine(), node.getEndLine(), variableName, specificDescription, ctx, packageName, findClassName(node), findMethodName(node));
}
private String findMethodName(SimpleNode node) {
@ -149,6 +135,7 @@ public abstract class AbstractRule extends JavaParserVisitorAdapter implements R
if (node.getFirstParentOfType(ASTMethodDeclaration.class) == null) {
return "";
} else {
// TODO hm, this should be a method on MethodScope
Scope s = node.getScope();
while (!(s instanceof MethodScope)) {
s = s.getParent();
@ -203,6 +190,13 @@ public abstract class AbstractRule extends JavaParserVisitorAdapter implements R
return this.usesDFA;
}
protected void visitAll(List acus, RuleContext ctx) {
for (Iterator i = acus.iterator(); i.hasNext();) {
ASTCompilationUnit node = (ASTCompilationUnit) i.next();
visit(node, ctx);
}
}
/**
* Adds a violation to the report.
*