From 4a25c7423f4fa74568b502adfe7a46c194cb8199 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Tue, 14 Jun 2005 11:52:49 +0000 Subject: [PATCH] Minor refactoring git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@3579 51baf565-9d33-0410-a72c-fc3788e3496d --- .../pmd/symboltable/AcceptanceTest.java | 27 +++++++++++++++++++ pmd/src/net/sourceforge/pmd/dfa/DaaRule.java | 15 +++-------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/pmd/regress/test/net/sourceforge/pmd/symboltable/AcceptanceTest.java b/pmd/regress/test/net/sourceforge/pmd/symboltable/AcceptanceTest.java index d92cd44e3a..8b078eb11e 100644 --- a/pmd/regress/test/net/sourceforge/pmd/symboltable/AcceptanceTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/symboltable/AcceptanceTest.java @@ -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 + diff --git a/pmd/src/net/sourceforge/pmd/dfa/DaaRule.java b/pmd/src/net/sourceforge/pmd/dfa/DaaRule.java index 3da537ad95..73190084ed 100644 --- a/pmd/src/net/sourceforge/pmd/dfa/DaaRule.java +++ b/pmd/src/net/sourceforge/pmd/dfa/DaaRule.java @@ -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")); } }