minor refactoring

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1088 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-10-08 20:43:15 +00:00
parent f2a329239c
commit bc5056fcd8
3 changed files with 32 additions and 31 deletions

View File

@ -11,6 +11,9 @@ public class ASTResultType extends SimpleNode {
super(p, id);
}
public boolean isVoid() {
return jjtGetNumChildren() == 0;
}
/** Accept the visitor. **/
public Object jjtAccept(JavaParserVisitor visitor, Object data) {

View File

@ -41,28 +41,26 @@ public class LooseCouplingRule extends AbstractRule {
}
public Object visit(ASTResultType node, Object data) {
checkType(node, data);
return data;
if (node.isVoid()) {
return data;
}
return checkType(node, data);
}
public Object visit(ASTFieldDeclaration node, Object data) {
checkType(node, data);
return data;
return checkType(node, data);
}
public Object visit(ASTFormalParameter node, Object data) {
checkType(node, data);
return data;
return checkType(node, data);
}
private void checkType(SimpleNode node, Object data) {
if (node.jjtGetNumChildren() ==0) {
return;
}
SimpleNode returnTypeNameNode = (SimpleNode)node.jjtGetChild(0).jjtGetChild(0);
if (implClassNames.contains(returnTypeNameNode.getImage())) {
private Object checkType(SimpleNode node, Object data) {
SimpleNode name = (SimpleNode)node.jjtGetChild(0).jjtGetChild(0);
if (implClassNames.contains(name.getImage())) {
RuleContext ctx = (RuleContext)data;
ctx.getReport().addRuleViolation(createRuleViolation(ctx, returnTypeNameNode.getBeginLine(), MessageFormat.format(getMessage(), new Object[] {returnTypeNameNode.getImage()})));
ctx.getReport().addRuleViolation(createRuleViolation(ctx, name.getBeginLine(), MessageFormat.format(getMessage(), new Object[] {name.getImage()})));
}
return data;
}
}

View File

@ -9,30 +9,30 @@ import net.sourceforge.pmd.ast.ASTMethodDeclaration;
public class UseSingletonRule
extends AbstractRule
{
private boolean isOK = false;
private int methodCount = 0;
private boolean isOK;
private int methodCount;
public Object visit( ASTMethodDeclaration decl, Object data ) {
methodCount ++;
if (isOK) return data;
if (!decl.isStatic()) {
isOK = true;
return data;
}
return data;
methodCount ++;
if (isOK) return data;
if (!decl.isStatic()) {
isOK = true;
return data;
}
return data;
}
public Object visit( ASTCompilationUnit cu, Object data ) {
methodCount = 0;
isOK=false;
Object RC = cu.childrenAccept( this, data );
methodCount = 0;
isOK=false;
Object RC = cu.childrenAccept( this, data );
if ((!isOK) && (methodCount > 0)) {
RuleContext ctx = (RuleContext)data;
ctx.getReport().addRuleViolation(createRuleViolation(ctx, cu.getBeginLine() ));
}
if ((!isOK) && (methodCount > 0)) {
RuleContext ctx = (RuleContext)data;
ctx.getReport().addRuleViolation(createRuleViolation(ctx, cu.getBeginLine() ));
}
return RC;
return RC;
}
}