Fixed bug 1380969 - UnusedPrivateMethod no longer flags private static methods that are only invoked in a static context from a field declaration.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4071 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2005-12-15 15:51:59 +00:00
parent 433bd30a14
commit 7475320929
4 changed files with 11 additions and 3 deletions

View File

@ -7,5 +7,5 @@ that contains this fix.
Thanks,
Tom
Using PMD? Get the book, "PMD Applied"! http://pmdapplied.com/
Support PMD, get the book: http://pmdapplied.com/

View File

@ -16,6 +16,7 @@ Fixed bug 1378358 - StringInstantiation no longer throws ClassCastExceptions on
Fixed bug 1371741 - UncommentedEmptyConstructor no longer flags constructors that consist of a this() or a super() invocation.
Fixed bug 1277373 - InefficientStringBuffering no longer flags concatenations that involve a static final String.
Fixed bug 1379701 - CompareObjectsWithEquals no longer flags comparisons of array elements.
Fixed bug 1380969 - UnusedPrivateMethod no longer flags private static methods that are only invoked in a static context from a field declaration.
Fixed a bug in UseStringBufferLength; it no longers fails with an exception on expressions like StringBuffer.toString.equals(x)
Partially fixed bug 1371753 - UnnecessaryLocalBeforeReturn message now reflects the fact that that rule flags all types
Modified renderers to support disabling printing of suppressed warnings. Introduced a new AbstractRenderer class that all Renderers can extends to get the current behavior - that is, suppressed violations are printed.

View File

@ -33,7 +33,8 @@ public class UnusedPrivateMethodRuleTest extends SimpleAggregatorTst {
new TestDescriptor(TEST11, "called from constructor", 0, rule),
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),
// FIXME new TestDescriptor(TEST14, "two methods, one private, one public, same name, same arg count, diff types", 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),
});
}
@ -153,6 +154,12 @@ public class UnusedPrivateMethodRuleTest extends SimpleAggregatorTst {
private static final String TEST14 =
"public class Foo {" + PMD.EOL +
" static boolean BUZ = Foo.bar(); " + PMD.EOL +
" private static boolean bar() { return true; }" + PMD.EOL +
"}";
private static final String TEST15 =
"public class Foo {" + PMD.EOL +
" public void baz() {" + PMD.EOL +
" foo(\"hi\");" + PMD.EOL +
" }" + PMD.EOL +

View File

@ -62,7 +62,7 @@ public class UnusedPrivateMethodRule extends AbstractRule {
}
ASTMethodDeclaration enclosingMethod = (ASTMethodDeclaration)occNode.getFirstParentOfType(ASTMethodDeclaration.class);
if (enclosingMethod != null && !mnd.getNode().jjtGetParent().equals(enclosingMethod)) {
if ((enclosingMethod == null) || (enclosingMethod != null && !mnd.getNode().jjtGetParent().equals(enclosingMethod))) {
callsFromOutsideMethod++;
}
}