Fixed bug 1376756 - UselessOverridingMethod no longer throws an exception on overloaded methods.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4049 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -9,6 +9,7 @@ Fixed bug 1371980 - InefficientStringBuffering no longer flags StringBuffer meth
|
||||
Fixed bug 1373510 - UseAssertSameInsteadOfAssertTrue no longer has a typo in its message, and its message is more clear.
|
||||
Fixed bug 1375290 - @SuppressWarnings annotations are now implemented correctly; they accept one blank argument to suppress all warnings.
|
||||
Fixed bug 1376760 - InefficientStringBuffering no longer throws a NullPointerException when processing certain expressions.
|
||||
Fixed bug 1376756 - UselessOverridingMethod no longer throws an exception on overloaded methods.
|
||||
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.
|
||||
|
@ -113,10 +113,7 @@ public class UselessOverridingMethodTest extends SimpleAggregatorTst {
|
||||
|
||||
private static final String TEST13 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
"public void foo(String[] args) {" + PMD.EOL +
|
||||
" super.init( args, Application.NO_MODULES );" + PMD.EOL +
|
||||
"}" + PMD.EOL +
|
||||
"public void foo(String args) {" + PMD.EOL +
|
||||
"public void init(String[] args) {" + PMD.EOL +
|
||||
" super.init( args, Application.NO_MODULES );" + PMD.EOL +
|
||||
"}" + PMD.EOL +
|
||||
"}";
|
||||
|
@ -6,24 +6,28 @@
|
||||
These are new rules that are still in progress
|
||||
</description>
|
||||
|
||||
<rule name="UselessOverridingMethod"
|
||||
message="Overriding method merely calls super"
|
||||
class="net.sourceforge.pmd.rules.UselessOverridingMethod"
|
||||
externalInfoUrl="http://pmd.sourceforge.net/rules/basic.html#UselessOverridingMethod">
|
||||
<description>
|
||||
The overriding method merely calls the same method defined in a superclass
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example><![CDATA[
|
||||
public void foo(String bar) {
|
||||
super.foo(bar); //Why bother overriding?
|
||||
<rule name="AppendCharacterWithChar"
|
||||
message="Avoid appending characters as strings in StringBuffer.append"
|
||||
class="net.sourceforge.pmd.rules.strings.AppendCharacterWithChar">
|
||||
<description>
|
||||
Avoid concatenating characters as strings in StringBuffer.append
|
||||
</description>
|
||||
<priority>2</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
void bar() {
|
||||
StringBuffer sb=new StringBuffer();
|
||||
// Avoid this
|
||||
sb.append("a");
|
||||
|
||||
// use instead something like this
|
||||
StringBuffer sb=new StringBuffer();
|
||||
sb.append('a');
|
||||
}
|
||||
}
|
||||
]]></example>
|
||||
<example><![CDATA[
|
||||
public String foo() {
|
||||
return super.foo(); //Why bother overriding?
|
||||
}
|
||||
]]></example>
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<!--
|
||||
|
@ -93,11 +93,16 @@ public class UselessOverridingMethod extends AbstractRule {
|
||||
if (!(argumentPrimaryPrefixChild instanceof ASTName))
|
||||
return super.visit(node, data); //The arguments are not simply passed through
|
||||
|
||||
if (formalParameters.jjtGetNumChildren() < i+1) {
|
||||
return super.visit(node, data); // different number of args
|
||||
}
|
||||
|
||||
ASTName argumentName = (ASTName)argumentPrimaryPrefixChild;
|
||||
ASTFormalParameter formalParameter = (ASTFormalParameter)formalParameters.jjtGetChild(i);
|
||||
ASTVariableDeclaratorId variableId = (ASTVariableDeclaratorId)findFirstDegreeChildrenOfType(formalParameter, ASTVariableDeclaratorId.class).get(0);
|
||||
if (!argumentName.getImage().equals(variableId.getImage()))
|
||||
if (!argumentName.getImage().equals(variableId.getImage())) {
|
||||
return super.visit(node, data); //The arguments are not simply passed through
|
||||
}
|
||||
|
||||
}
|
||||
addViolation(data, node, getMessage()); //All arguments are passed through directly
|
||||
@ -107,11 +112,11 @@ public class UselessOverridingMethod extends AbstractRule {
|
||||
|
||||
public List findFirstDegreeChildrenOfType(SimpleNode n, Class targetType) {
|
||||
List l = new ArrayList();
|
||||
lclFindChildrenOfType(n, targetType, l, 0);
|
||||
lclFindChildrenOfType(n, targetType, l);
|
||||
return l;
|
||||
}
|
||||
|
||||
private void lclFindChildrenOfType(Node node, Class targetType, List results, int depth) {
|
||||
private void lclFindChildrenOfType(Node node, Class targetType, List results) {
|
||||
if (node.getClass().equals(targetType)) {
|
||||
results.add(node);
|
||||
}
|
||||
|
@ -45,7 +45,7 @@
|
||||
</subsection>
|
||||
<subsection name="Contributors">
|
||||
<ul>
|
||||
<li>Bruce Kelly - bug report 1376760 for InefficientStringBuffering</li>
|
||||
<li>Bruce Kelly - bug report 1376756 for UselessOverridingMethod, bug report 1376760 for InefficientStringBuffering</li>
|
||||
<li>Allan Caplan - wrote AppendCharacterWithChar, wrote IntegerInstantiation, wrote UseStringBufferLength, wrote AvoidEnumAsIdentifier, bug report 1313216 for designer flaw, patch 1306999 to enhance CloseResource to check for more types, suggested including suppressed rule violations in the report</li>
|
||||
<li>Wouter Zelle - Renderer improvement suggestions, wrote NonThreadSafeSingleton rule, wrote DefaultPackage rule, worked thru ASTMethodDeclaration.isSyntacticallyX design, reported docs bug 1292689 for UnnecessaryLocalBeforeReturn, reported leftover ExceptionTypeChecking source file, rewrote UselessOverridingMethod in Java, UselessOverridingMethod rule, ProperLogger rule, nifty code to allow variables in XPath rules, externalInfoUrl data for all rules in basic and unusedcode rulesets, some very nifty XSLT, improvements to UseCorrectExceptionLogging, designed and implemented the "externalInfoUrl" feature in the rule definitions, fixed a devious bug in RuleSetFactory, AvoidPrintStackTrace, initial implementation of SimplifyConditional</li>
|
||||
<li>Bhatia Saurabh - reported a bug in UseStringBufferLength</li>
|
||||
|
Reference in New Issue
Block a user