Minor refactoring
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@3579 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -7,14 +7,19 @@ import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.ast.ASTBlock;
|
||||
import net.sourceforge.pmd.ast.ASTCatchStatement;
|
||||
import net.sourceforge.pmd.ast.ASTInitializer;
|
||||
import net.sourceforge.pmd.ast.ASTEqualityExpression;
|
||||
import net.sourceforge.pmd.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.symboltable.Scope;
|
||||
import net.sourceforge.pmd.symboltable.VariableNameDeclaration;
|
||||
import net.sourceforge.pmd.symboltable.LocalScope;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class AcceptanceTest extends STBBaseTst {
|
||||
|
||||
/*
|
||||
public void testClashingSymbols() {
|
||||
parseCode(TEST1);
|
||||
}
|
||||
@ -38,6 +43,28 @@ public class AcceptanceTest extends STBBaseTst {
|
||||
assertEquals("e", v.getImage());
|
||||
assertEquals(1, ((List)vars.get(v)).size());
|
||||
}
|
||||
*/
|
||||
|
||||
public void testEq() {
|
||||
parseCode(TEST_EQ);
|
||||
ASTEqualityExpression e = (ASTEqualityExpression)(acu.findChildrenOfType(ASTEqualityExpression.class)).get(0);
|
||||
ASTMethodDeclaration method = (ASTMethodDeclaration)e.getFirstParentOfType(ASTMethodDeclaration.class);
|
||||
Scope s = method.getScope();
|
||||
Map m = s.getVariableDeclarations();
|
||||
for (Iterator i = m.keySet().iterator(); i.hasNext();) {
|
||||
VariableNameDeclaration vnd = (VariableNameDeclaration)i.next();
|
||||
// vnd.
|
||||
}
|
||||
System.out.println(m.size());
|
||||
|
||||
}
|
||||
|
||||
private static final String TEST_EQ =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" boolean foo(String a, String b) { " + PMD.EOL +
|
||||
" return a == b; " + PMD.EOL +
|
||||
" } " + PMD.EOL +
|
||||
"}" + PMD.EOL;
|
||||
|
||||
private static final String TEST1 =
|
||||
"import java.io.*;" + PMD.EOL +
|
||||
|
@ -58,22 +58,13 @@ public class DaaRule extends AbstractRule implements Executable {
|
||||
if (o != null) {
|
||||
List array = (List) o;
|
||||
int last = ((Integer) array.get(0)).intValue();
|
||||
//int current = va.getAccessType();
|
||||
// TODO - at some point investigate and possibly reintroduce this line2 thing
|
||||
//int line2 = ((Integer) array.get(1)).intValue();
|
||||
|
||||
// DD
|
||||
//if ( last == current && current == VariableAccess.DEFINITION) {
|
||||
if (va.accessTypeMatches(last) && va.isDefinition()) {
|
||||
|
||||
if (va.accessTypeMatches(last) && va.isDefinition()) { // DD
|
||||
this.rc.getReport().addRuleViolation(createRuleViolation(rc, inode.getSimpleNode(), va.getVariableName(), "DD"));
|
||||
}
|
||||
// UR
|
||||
else if (last == VariableAccess.UNDEFINITION && va.isReference()) {
|
||||
} else if (last == VariableAccess.UNDEFINITION && va.isReference()) { // UR
|
||||
this.rc.getReport().addRuleViolation(createRuleViolation(rc, inode.getSimpleNode(), va.getVariableName(), "UR"));
|
||||
}
|
||||
// DU
|
||||
else if (last == VariableAccess.DEFINITION && va.isUndefinition()) {
|
||||
} else if (last == VariableAccess.DEFINITION && va.isUndefinition()) { // DU
|
||||
this.rc.getReport().addRuleViolation(createRuleViolation(rc, inode.getSimpleNode(), va.getVariableName(), "DU"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user