From e300a2630b93cceca50d4d9f654aa72a06bae5b4 Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Thu, 11 Dec 2008 00:48:43 +0000 Subject: [PATCH] Fixed bug 1955852 - false positives for UnusedPrivateMethod & UnusedLocalVariable git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6744 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 2 +- .../unusedcode/xml/UnusedLocalVariable.xml | 2 +- .../unusedcode/xml/UnusedPrivateMethod.xml | 2 +- .../sourceforge/pmd/symboltable/NameFinder.java | 17 +++++++++++------ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index c03ac93617..51d450333b 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,11 +1,11 @@ ???? - 4.2.5: Enhanced logging in the ClassTypeResolver to provide more detailed messaging. -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 October 12, 2008 - 4.2.4: diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/unusedcode/xml/UnusedLocalVariable.xml b/pmd/regress/test/net/sourceforge/pmd/rules/unusedcode/xml/UnusedLocalVariable.xml index 1ac874fd37..6b8d5d446e 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/unusedcode/xml/UnusedLocalVariable.xml +++ b/pmd/regress/test/net/sourceforge/pmd/rules/unusedcode/xml/UnusedLocalVariable.xml @@ -306,7 +306,7 @@ public class Foo { } ]]> - + 0 diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/unusedcode/xml/UnusedPrivateMethod.xml b/pmd/regress/test/net/sourceforge/pmd/rules/unusedcode/xml/UnusedPrivateMethod.xml index d8ee1e32ed..c9cbf4dbcb 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/unusedcode/xml/UnusedPrivateMethod.xml +++ b/pmd/regress/test/net/sourceforge/pmd/rules/unusedcode/xml/UnusedPrivateMethod.xml @@ -341,7 +341,7 @@ public class Foo { } ]]> - + 0 diff --git a/pmd/src/net/sourceforge/pmd/symboltable/NameFinder.java b/pmd/src/net/sourceforge/pmd/symboltable/NameFinder.java index fe84f510f7..65c069eacd 100644 --- a/pmd/src/net/sourceforge/pmd/symboltable/NameFinder.java +++ b/pmd/src/net/sourceforge/pmd/symboltable/NameFinder.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.symboltable; import net.sourceforge.pmd.ast.ASTArguments; +import net.sourceforge.pmd.ast.ASTMemberSelector; import net.sourceforge.pmd.ast.ASTName; import net.sourceforge.pmd.ast.ASTPrimaryExpression; import net.sourceforge.pmd.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.getLast(); - 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.getLast(); + 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((SimpleNode)suffix.jjtGetChild(0), ((SimpleNode)suffix.jjtGetChild(0)).getImage())); + } } }