forked from phoedos/pmd
Merge branch 'bug-1456'
This commit is contained in:
@@ -12,6 +12,7 @@ import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTFormalParameter;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMarkerAnnotation;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTName;
|
||||
@@ -42,7 +43,7 @@ public class UnusedFormalParameterRule extends AbstractJavaRule {
|
||||
if (!node.isPrivate() && !getProperty(CHECKALL_DESCRIPTOR)) {
|
||||
return data;
|
||||
}
|
||||
if (!node.isNative() && !node.isAbstract() && !isSerializationMethod(node)) {
|
||||
if (!node.isNative() && !node.isAbstract() && !isSerializationMethod(node) && !hasOverrideAnnotation(node)) {
|
||||
check(node, data);
|
||||
}
|
||||
return data;
|
||||
@@ -110,4 +111,19 @@ public class UnusedFormalParameterRule extends AbstractJavaRule {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasOverrideAnnotation(ASTMethodDeclaration node) {
|
||||
int childIndex = node.jjtGetChildIndex();
|
||||
for (int i = 0; i < childIndex; i++) {
|
||||
Node previousSibling = node.jjtGetParent().jjtGetChild(i);
|
||||
List<ASTMarkerAnnotation> annotations = previousSibling.findDescendantsOfType(ASTMarkerAnnotation.class);
|
||||
for (ASTMarkerAnnotation annotation : annotations) {
|
||||
ASTName name = annotation.getFirstChildOfType( ASTName.class );
|
||||
if (name != null && (name.hasImageEqualTo( "Override" ) || name.hasImageEqualTo( "java.lang.Override" ))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -277,6 +277,31 @@ public class Foo {
|
||||
public void readObject(ObjectInputStream stream) throws InvalidObjectException{
|
||||
throw new InvalidObjectException("Proxy required");
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1456 UnusedFormalParameter should ignore overriding methods</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<rule-property name="checkAll">true</rule-property>
|
||||
<code><![CDATA[
|
||||
abstract class Base{
|
||||
abstract public int badMethod(int arg1, String arg2);
|
||||
}
|
||||
|
||||
class Imp1 extends Base {
|
||||
@Override
|
||||
public int badMethod(int arg1, String arg2) {
|
||||
return arg2.length();
|
||||
}
|
||||
}
|
||||
|
||||
class Imp2 extends Base {
|
||||
@Override
|
||||
public int badMethod(int arg1, String arg2) {
|
||||
return arg2.length() + arg1;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@@ -72,6 +72,8 @@
|
||||
* [#1443](https://sourceforge.net/p/pmd/bugs/1443/): RedundantFieldInitializer: False positive for small floats
|
||||
* java-unnecessary/UselessQualifiedThis
|
||||
* [#1422](https://sourceforge.net/p/pmd/bugs/1422/): UselessQualifiedThis: False positive with Java 8 Function
|
||||
* java-unusedcode/UnusedFormalParameter:
|
||||
* [#1456](https://sourceforge.net/p/pmd/bugs/1456/): UnusedFormalParameter should ignore overriding methods
|
||||
* java-unusedcode/UnusedPrivateField
|
||||
* [#1428](https://sourceforge.net/p/pmd/bugs/1428/): False positive in UnusedPrivateField when local variable
|
||||
hides member variable
|
||||
|
Reference in New Issue
Block a user