diff --git a/pmd/src/net/sourceforge/pmd/rules/design/UseSingletonRule.java b/pmd/src/net/sourceforge/pmd/rules/design/UseSingletonRule.java new file mode 100644 index 0000000000..96a50a32ff --- /dev/null +++ b/pmd/src/net/sourceforge/pmd/rules/design/UseSingletonRule.java @@ -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; + } +}