From 14f22ca0ded9047f00db3996c9a1e5870a6b58d7 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Fri, 7 Apr 2006 01:01:16 +0000 Subject: [PATCH] Fixed bug 1465574 - UnusedPrivateMethod no longer reports false positives when a private method is called from a method with a parameter of the same name. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4326 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + .../pmd/rules/UnusedPrivateMethodRuleTest.java | 11 ++++++++++- .../net/sourceforge/pmd/symboltable/MethodScope.java | 2 +- pmd/xdocs/credits.xml | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 66d61f487d..3f9e270ac4 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,4 +1,5 @@ ????, 2006 - 3.7: +Fixed bug 1465574 - UnusedPrivateMethod no longer reports false positives when a private method is called from a method with a parameter of the same name. Fixed major bug in CPD; it was not picking up files other than .java or .jsp. Added RuleViolation.getBeginColumn()/getEndColumn() Added an IRuleViolation interface and modified various code classes (include Renderer implementations and Report) to use it. diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/UnusedPrivateMethodRuleTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/UnusedPrivateMethodRuleTest.java index f1c4d572fb..4c7670d213 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/UnusedPrivateMethodRuleTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/UnusedPrivateMethodRuleTest.java @@ -34,7 +34,8 @@ public class UnusedPrivateMethodRuleTest extends SimpleAggregatorTst { new TestDescriptor(TEST12, "private method with same name but diff arg count than public method", 0, rule), new TestDescriptor(TEST13, "static private called from initializer", 0, rule), new TestDescriptor(TEST14, "static private invoked in static context - i.e., Foo.hi()", 0, rule), - // FIXME new TestDescriptor(TEST15, "two methods, one private, one public, same name, same arg count, diff types", 0, rule), + new TestDescriptor(TEST15, "private method with same name as param", 0, rule), + // FIXME new TestDescriptor(TEST16, "two methods, one private, one public, same name, same arg count, diff types", 0, rule), }); } @@ -159,6 +160,14 @@ public class UnusedPrivateMethodRuleTest extends SimpleAggregatorTst { "}"; private static final String TEST15 = + "public class Foo {" + PMD.EOL + + " void bar(boolean buz) { " + PMD.EOL + + " buz();" + PMD.EOL + + " }" + PMD.EOL + + " private void buz() {}" + PMD.EOL + + "}"; + + private static final String TEST16 = "public class Foo {" + PMD.EOL + " public void baz() {" + PMD.EOL + " foo(\"hi\");" + PMD.EOL + diff --git a/pmd/src/net/sourceforge/pmd/symboltable/MethodScope.java b/pmd/src/net/sourceforge/pmd/symboltable/MethodScope.java index fef587455e..366d27bd66 100644 --- a/pmd/src/net/sourceforge/pmd/symboltable/MethodScope.java +++ b/pmd/src/net/sourceforge/pmd/symboltable/MethodScope.java @@ -52,7 +52,7 @@ public class MethodScope extends AbstractScope { } public NameDeclaration findVariableHere(NameOccurrence occurrence) { - if (occurrence.isThisOrSuper()) { + if (occurrence.isThisOrSuper() || occurrence.isMethodOrConstructorInvocation()) { return null; } ImageFinderFunction finder = new ImageFinderFunction(occurrence.getImage()); diff --git a/pmd/xdocs/credits.xml b/pmd/xdocs/credits.xml index 03219e87f4..9cc37c75aa 100644 --- a/pmd/xdocs/credits.xml +++ b/pmd/xdocs/credits.xml @@ -48,6 +48,7 @@