From fcb69f49670d5f4569222e0cab929761e6c5c10e Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Thu, 11 Dec 2008 00:49:35 +0000 Subject: [PATCH] Fixed bug 1955852 - false positives for UnusedPrivateMethod & UnusedLocalVariable git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@6745 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 2 +- .../unusedcode/xml/UnusedLocalVariable.xml | 2 +- .../unusedcode/xml/UnusedPrivateMethod.xml | 2 +- .../pmd/lang/java/symboltable/NameFinder.java | 18 ++++++++++++------ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 827a718756..20926fe096 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -409,11 +409,11 @@ Fixed bug 1556594 - Wonky detection of NullAssignment Fixed bug 1481051 - false + UnusedNullCheckInEquals (and other false positives too) Fixed bug 1943204 - Ant task: path should be relative to Ant basedir Fixed patch 2075906 - Add toString() to the rule UnnecessaryWrapperObjectCreation -Fixed bug 2338341 - ArrayIndexOutOfBoundsException in cpd on rails project Fixed bug 2315623 - @SuppressWarnings("PMD.UseSingleton") has no effect Fixed bug 2230809 - False +: ClassWithOnlyPrivateConstructorsShouldBeFinal Fixed bug 2338341 - ArrayIndexOutOfBoundsException in CPD (on Ruby) Fixed bug 2315599 - False +: UseSingleton with class containing constructor +Fixed bug 1955852 - false positives for UnusedPrivateMethod & UnusedLocalVariable ruleset.dtd and ruleset_xml_schema.xsd added to jar file in rulesets directory bin and java14/bin scripts: diff --git a/pmd/regress/test/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedLocalVariable.xml b/pmd/regress/test/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedLocalVariable.xml index e95f1a1937..cf279052bb 100644 --- a/pmd/regress/test/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedLocalVariable.xml +++ b/pmd/regress/test/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedLocalVariable.xml @@ -307,7 +307,7 @@ public class Foo { ]]> - + diff --git a/pmd/regress/test/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedPrivateMethod.xml b/pmd/regress/test/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedPrivateMethod.xml index 7ce1061e1a..550dd9c2b1 100644 --- a/pmd/regress/test/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedPrivateMethod.xml +++ b/pmd/regress/test/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedPrivateMethod.xml @@ -342,7 +342,7 @@ public class Foo { ]]> - + diff --git a/pmd/src/net/sourceforge/pmd/lang/java/symboltable/NameFinder.java b/pmd/src/net/sourceforge/pmd/lang/java/symboltable/NameFinder.java index 97df6a7e1b..a2aafc0fc9 100644 --- a/pmd/src/net/sourceforge/pmd/lang/java/symboltable/NameFinder.java +++ b/pmd/src/net/sourceforge/pmd/lang/java/symboltable/NameFinder.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.StringTokenizer; import net.sourceforge.pmd.lang.java.ast.ASTArguments; +import net.sourceforge.pmd.lang.java.ast.ASTMemberSelector; import net.sourceforge.pmd.lang.java.ast.ASTName; import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression; import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix; @@ -44,12 +45,16 @@ public class NameFinder { add(new NameOccurrence(grandchild, st.nextToken())); } } - if (node instanceof ASTPrimarySuffix && ((ASTPrimarySuffix) node).isArguments()) { - NameOccurrence occurrence = names.get(names.size() - 1); - occurrence.setIsMethodOrConstructorInvocation(); - ASTArguments args = (ASTArguments) ((ASTPrimarySuffix) node).jjtGetChild(0); - occurrence.setArgumentCount(args.getArgumentCount()); - + if (node instanceof ASTPrimarySuffix) { + ASTPrimarySuffix suffix = (ASTPrimarySuffix) node; + if (suffix.isArguments()) { + NameOccurrence occurrence = names.get(names.size() - 1); + occurrence.setIsMethodOrConstructorInvocation(); + ASTArguments args = (ASTArguments) ((ASTPrimarySuffix) node).jjtGetChild(0); + occurrence.setArgumentCount(args.getArgumentCount()); + } else if (suffix.jjtGetNumChildren() == 1 && suffix.jjtGetChild(0) instanceof ASTMemberSelector) { + add(new NameOccurrence((JavaNode)suffix.jjtGetChild(0), suffix.jjtGetChild(0).getImage())); + } } } @@ -62,6 +67,7 @@ public class NameFinder { } + @Override public String toString() { StringBuffer result = new StringBuffer(); for (NameOccurrence occ: names) {