refactoring

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@458 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-07-20 16:24:58 +00:00
parent be1ef15543
commit bb7c548ba5
4 changed files with 21 additions and 14 deletions

View File

@ -0,0 +1,17 @@
/*
* User: tom
* Date: Jul 20, 2002
* Time: 9:28:10 AM
*/
package net.sourceforge.pmd.rules;
import net.sourceforge.pmd.AbstractRule;
import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.ast.ASTBlock;
public abstract class BracesRule extends AbstractRule {
protected boolean hasBlockAsFirstChild(SimpleNode node) {
return (node.jjtGetNumChildren() != 0 && (node.jjtGetChild(0) instanceof ASTBlock));
}
}

View File

@ -12,7 +12,7 @@ import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.ast.ASTBlock;
import net.sourceforge.pmd.ast.ASTForStatement;
public class ForLoopsMustUseBracesRule extends AbstractRule {
public class ForLoopsMustUseBracesRule extends BracesRule {
public Object visit(ASTForStatement node, Object data) {
RuleContext ctx = (RuleContext)data;
@ -24,7 +24,4 @@ public class ForLoopsMustUseBracesRule extends AbstractRule {
return super.visit(node,data);
}
private boolean hasBlockAsFirstChild(SimpleNode node) {
return (node.jjtGetNumChildren() != 0 && (node.jjtGetChild(0) instanceof ASTBlock));
}
}

View File

@ -10,7 +10,7 @@ import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.ast.ASTBlock;
import net.sourceforge.pmd.*;
public class IfElseStmtsMustUseBracesRule extends AbstractRule {
public class IfElseStmtsMustUseBracesRule extends BracesRule {
private int lineNumberOfLastViolation;
@ -29,10 +29,7 @@ public class IfElseStmtsMustUseBracesRule extends AbstractRule {
ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine()));
lineNumberOfLastViolation = node.getBeginLine();
}
return super.visit(node,data);
}
private boolean hasBlockAsFirstChild(SimpleNode node) {
return (node.jjtGetNumChildren() != 0 && (node.jjtGetChild(0) instanceof ASTBlock));
}
}

View File

@ -12,7 +12,7 @@ import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.ast.ASTBlock;
import net.sourceforge.pmd.ast.ASTWhileStatement;
public class WhileLoopsMustUseBracesRule extends AbstractRule {
public class WhileLoopsMustUseBracesRule extends BracesRule {
public Object visit(ASTWhileStatement node, Object data) {
RuleContext ctx = (RuleContext)data;
@ -24,8 +24,4 @@ public class WhileLoopsMustUseBracesRule extends AbstractRule {
return super.visit(node,data);
}
private boolean hasBlockAsFirstChild(SimpleNode node) {
return (node.jjtGetNumChildren() != 0 && (node.jjtGetChild(0) instanceof ASTBlock));
}
}