Checks for all static methods, and recommends Singleton use if

it finds it.


git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@125 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
David Dixon-Peugh
2002-06-28 17:28:26 +00:00
parent 6e00699626
commit b89d46f4c6

View File

@ -0,0 +1,39 @@
package net.sourceforge.pmd.rules.design;
import net.sourceforge.pmd.AbstractRule;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.ast.ASTCompilationUnit;
import net.sourceforge.pmd.ast.ASTMethodDeclaration;
public class UseSingletonRule
extends AbstractRule
{
public boolean isOK = false;
public UseSingletonRule() { }
public String getDescription() {
return "All methods are static. Consider using Singleton instead.";
}
public Object visit( ASTMethodDeclaration decl, Object data ) {
if (isOK) return data;
if (!decl.isStatic()) {
isOK = true;
return data;
}
return data;
}
public Object visit( ASTCompilationUnit cu, Object data ) {
Object RC = super.visit( cu, data );
if (!isOK)
(((RuleContext) data).getReport()).
addRuleViolation( new RuleViolation( this, cu.getBeginLine() ));
return data;
}
}