forked from phoedos/pmd
fixing 581853
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@356 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -391,7 +391,14 @@ void ClassBody() :
|
||||
void NestedClassDeclaration() :
|
||||
{}
|
||||
{
|
||||
( "static" | "abstract" | "final" | "public" | "protected" | "private" | "strictfp")*
|
||||
("static" { ((AccessNode) jjtThis).setStatic( true ); }
|
||||
| "abstract" { ((AccessNode) jjtThis).setAbstract( true ); }
|
||||
| "final" { ((AccessNode) jjtThis).setFinal( true ); }
|
||||
| "public" { ((AccessNode) jjtThis).setPublic( true ); }
|
||||
| "protected" { ((AccessNode) jjtThis).setProtected( true ); }
|
||||
| "private" { ((AccessNode) jjtThis).setPrivate( true ); }
|
||||
| "strictfp" { ((AccessNode) jjtThis).setStrict( true ); }
|
||||
)*
|
||||
UnmodifiedClassDeclaration()
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,8 @@
|
||||
<!--<pmd reportFile="c:\pmd.html" rulesetfiles="rulesets/basic.xml" format="html">-->
|
||||
<pmd reportFile="c:\jdk14.html" rulesetfiles="rulesets/new_for_0_5.xml" format="html">
|
||||
<!--<fileset dir="c:\data\pmd\pmd\src">-->
|
||||
<fileset dir="c:\j2sdk1.4.0\src\com\sun\corba">
|
||||
<!--<fileset dir="c:\j2sdk1.4.0\src\com\sun\corba">-->
|
||||
<fileset dir="c:\j2sdk1.4.0\src\">
|
||||
<include name="**/*.java"/>
|
||||
</fileset>
|
||||
</pmd>
|
||||
|
@ -4,6 +4,7 @@ Changed sorting of RuleViolations to group Files together.
|
||||
Changed XML Renderer to improved format.
|
||||
Created DVSL Stylesheet for the new format.
|
||||
Fixed bug 580093 - OverrideBothEqualsAndHashcodeRule reports a more correct line number.
|
||||
Fixed bug 581853 - UnusedLocalVariableRule now handles anonymous inner classes correctly.
|
||||
|
||||
July 10 2002 - 0.4:
|
||||
Added new rules: OverrideBothEqualsAndHashcodeRule, EmptyTryBlock, EmptyFinallyBlock
|
||||
|
@ -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% xml rulesets\new_for_0_5.xml
|
||||
java %MAIN% %TEST_FILE% xml rulesets\unusedcode.xml
|
||||
|
@ -75,10 +75,7 @@ public class UnusedLocalVariableTest extends RuleTst {
|
||||
|
||||
public void testUnusedLocal9() throws Throwable {
|
||||
Report report = process("Unused9.java", rule);
|
||||
assertEquals(2, report.size());
|
||||
Iterator i = report.iterator();
|
||||
assertEquals(rule, ((RuleViolation)i.next()).getRule());
|
||||
assertEquals(rule, ((RuleViolation)i.next()).getRule());
|
||||
assertTrue(report.isEmpty());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -5,7 +5,7 @@
|
||||
These are new ones for 0.5
|
||||
</description>
|
||||
|
||||
<rule name="UnnecessaryCast"
|
||||
<rule name="UnnecessaryCast"
|
||||
message="Avoid unnecessary casts"
|
||||
class="net.sourceforge.pmd.rules.UnnecessaryCastRule">
|
||||
<description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
package net.sourceforge.pmd.ast;
|
||||
|
||||
public class ASTClassBodyDeclaration extends SimpleNode {
|
||||
public class ASTClassBodyDeclaration extends AccessNode {
|
||||
public ASTClassBodyDeclaration(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
package net.sourceforge.pmd.ast;
|
||||
|
||||
public class ASTNestedClassDeclaration extends SimpleNode {
|
||||
public class ASTNestedClassDeclaration extends AccessNode {
|
||||
public ASTNestedClassDeclaration(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -32,7 +32,7 @@ public class UnnecessaryCastRule extends AbstractRule {
|
||||
try {
|
||||
if (inCastCtx) {
|
||||
TypeSet t = new TypeSet();
|
||||
//System.out.println(t.findClass(node.getImage()));
|
||||
System.out.println(t.findClass(node.getImage()));
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
return super.visit(node, data);
|
||||
@ -42,7 +42,7 @@ public class UnnecessaryCastRule extends AbstractRule {
|
||||
try {
|
||||
if (inCastCtx) {
|
||||
TypeSet t = new TypeSet();
|
||||
//System.out.println(t.findClass(node.getImage()));
|
||||
System.out.println(t.findClass(node.getImage()));
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
return super.visit(node, data);
|
||||
|
@ -14,14 +14,7 @@ import net.sourceforge.pmd.*;
|
||||
|
||||
public class UnusedLocalVariableRule extends AbstractRule implements Rule{
|
||||
|
||||
private Stack tableGroups = new Stack();
|
||||
|
||||
public Object createGroup(SimpleNode node, Object data) {
|
||||
tableGroups.push(new Namespace());
|
||||
Object report = super.visit(node, data);
|
||||
tableGroups.pop();
|
||||
return report;
|
||||
}
|
||||
private Stack nameSpaces;
|
||||
|
||||
/**
|
||||
* Skip interfaces because they don't have local variables.
|
||||
@ -31,10 +24,13 @@ public class UnusedLocalVariableRule extends AbstractRule implements Rule{
|
||||
}
|
||||
|
||||
/**
|
||||
* A new ClassBody triggers a new namespace
|
||||
* For the purpose of local variables, only an ASTCompilation unit creates a new namespace
|
||||
*/
|
||||
public Object visit(ASTClassBody node, Object data) {
|
||||
return createGroup(node, data);
|
||||
public Object visit(ASTCompilationUnit node, Object data) {
|
||||
nameSpaces = new Stack();
|
||||
createNamespace(node, data);
|
||||
nameSpaces.clear();
|
||||
return data;
|
||||
}
|
||||
|
||||
// these AST types trigger creation of a new symbol table scope
|
||||
@ -52,7 +48,7 @@ public class UnusedLocalVariableRule extends AbstractRule implements Rule{
|
||||
if (!(node.jjtGetParent().jjtGetParent() instanceof ASTLocalVariableDeclaration)) {
|
||||
return super.visit(node, data);
|
||||
}
|
||||
Namespace group = (Namespace)tableGroups.peek();
|
||||
Namespace group = (Namespace)nameSpaces.peek();
|
||||
group.peek().add(new Symbol(node.getImage(), node.getBeginLine()));
|
||||
return super.visit(node, data);
|
||||
}
|
||||
@ -61,7 +57,7 @@ public class UnusedLocalVariableRule extends AbstractRule implements Rule{
|
||||
//System.out.println("ASTName.getImage() = " + node.getImage() + "; " + node.getBeginLine());
|
||||
if (node.jjtGetParent() instanceof ASTPrimaryPrefix) {
|
||||
String img = (node.getImage().indexOf('.') == -1) ? node.getImage() : node.getImage().substring(0, node.getImage().indexOf('.'));
|
||||
Namespace group = (Namespace)tableGroups.peek();
|
||||
Namespace group = (Namespace)nameSpaces.peek();
|
||||
group.peek().recordPossibleUsageOf(new Symbol(img, node.getBeginLine()));
|
||||
}
|
||||
return super.visit(node, data);
|
||||
@ -77,7 +73,7 @@ public class UnusedLocalVariableRule extends AbstractRule implements Rule{
|
||||
|
||||
private Object addTable(SimpleNode node, Object data) {
|
||||
RuleContext ctx = (RuleContext)data;
|
||||
Namespace group = (Namespace)tableGroups.peek();
|
||||
Namespace group = (Namespace)nameSpaces.peek();
|
||||
group.addTable();
|
||||
super.visit(node, ctx);
|
||||
reportUnusedLocals(ctx, group.peek());
|
||||
@ -85,4 +81,11 @@ public class UnusedLocalVariableRule extends AbstractRule implements Rule{
|
||||
return ctx;
|
||||
}
|
||||
|
||||
private Object createNamespace(SimpleNode node, Object data) {
|
||||
nameSpaces.push(new Namespace());
|
||||
Object report = super.visit(node, data);
|
||||
nameSpaces.pop();
|
||||
return report;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,6 @@ public class Unused1 {
|
||||
try {
|
||||
FileReader fr = new FileReader("/dev/null");
|
||||
// howdy
|
||||
} catch (Exception e) {e=null;}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
public class Unused9 {
|
||||
public void foo() {
|
||||
String x = "baf";
|
||||
bar(new Runnable() {
|
||||
public void run() {String x = "buz";}
|
||||
});
|
||||
}
|
||||
public void bar(Runnable r) {
|
||||
}
|
||||
public void foo() {
|
||||
final String x = "baf";
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
System.out.println(x);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user