Created UnusedFormalParamterRule
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@504 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -0,0 +1,45 @@
|
||||
package net.sourceforge.pmd.rules;
|
||||
|
||||
import net.sourceforge.pmd.AbstractRule;
|
||||
import net.sourceforge.pmd.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.ast.SimpleNode;
|
||||
import net.sourceforge.pmd.ast.ASTInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.ast.ASTName;
|
||||
import java.util.*;
|
||||
import net.sourceforge.pmd.ast.ASTBlock;
|
||||
|
||||
|
||||
public class UnusedFormalParameterRule extends AbstractRule {
|
||||
private List paramNames = null;
|
||||
|
||||
/**
|
||||
Skip interfaces
|
||||
*/
|
||||
public Object visit(ASTInterfaceDeclaration node, Object data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
public Object visit(ASTMethodDeclaration node, Object data) {
|
||||
if (node.isPrivate()) {
|
||||
SimpleNode md = (SimpleNode)node.jjtGetChild(1);
|
||||
SimpleNode formalParams = (SimpleNode)md.jjtGetChild(0);
|
||||
int paramCount = formalParams.jjtGetNumChildren();
|
||||
if (paramCount == 0) return data; //bail out if now paramters
|
||||
paramNames = new ArrayList();
|
||||
for (int i=0; i<paramCount; i++) {
|
||||
ASTName paramName = (ASTName)formalParams.jjtGetChild(i).jjtGetChild(0).jjtGetChild(0);
|
||||
paramNames.add(paramName);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public Object visit(ASTBlock node, Object data) {
|
||||
if (paramNames != null) {
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
@ -5,6 +5,18 @@
|
||||
These are new ones for the next release
|
||||
</description>
|
||||
|
||||
<rule name="UnusedFormalParameter"
|
||||
message="Avoid unused formal paramters such as ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.UnusedFormalParameterRule">
|
||||
<description>
|
||||
Complete this description
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
11
pmd/test-data/UnusedFormalParam1.java
Normal file
11
pmd/test-data/UnusedFormalParam1.java
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
class UnusedFormalParam1 {
|
||||
private void testMethod(String param1) {
|
||||
|
||||
}
|
||||
|
||||
private void t2(){
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user