refactoring
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@457 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -13,15 +13,13 @@ import net.sourceforge.pmd.ast.ASTBlock;
|
|||||||
import net.sourceforge.pmd.ast.ASTForStatement;
|
import net.sourceforge.pmd.ast.ASTForStatement;
|
||||||
|
|
||||||
public class ForLoopsMustUseBracesRule extends AbstractRule {
|
public class ForLoopsMustUseBracesRule extends AbstractRule {
|
||||||
private int lineNumberOfLastViolation;
|
|
||||||
|
|
||||||
public Object visit(ASTForStatement node, Object data) {
|
public Object visit(ASTForStatement node, Object data) {
|
||||||
RuleContext ctx = (RuleContext)data;
|
RuleContext ctx = (RuleContext)data;
|
||||||
SimpleNode loopBody = (SimpleNode)node.jjtGetChild(3);
|
SimpleNode loopBody = (SimpleNode)node.jjtGetChild(3);
|
||||||
|
|
||||||
if (!hasBlockAsFirstChild(loopBody) && (node.getBeginLine() != this.lineNumberOfLastViolation)) {
|
if (!hasBlockAsFirstChild(loopBody)) {
|
||||||
ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine()));
|
ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine()));
|
||||||
lineNumberOfLastViolation = node.getBeginLine();
|
|
||||||
}
|
}
|
||||||
return super.visit(node,data);
|
return super.visit(node,data);
|
||||||
}
|
}
|
||||||
|
@ -13,15 +13,13 @@ import net.sourceforge.pmd.ast.ASTBlock;
|
|||||||
import net.sourceforge.pmd.ast.ASTWhileStatement;
|
import net.sourceforge.pmd.ast.ASTWhileStatement;
|
||||||
|
|
||||||
public class WhileLoopsMustUseBracesRule extends AbstractRule {
|
public class WhileLoopsMustUseBracesRule extends AbstractRule {
|
||||||
private int lineNumberOfLastViolation;
|
|
||||||
|
|
||||||
public Object visit(ASTWhileStatement node, Object data) {
|
public Object visit(ASTWhileStatement node, Object data) {
|
||||||
RuleContext ctx = (RuleContext)data;
|
RuleContext ctx = (RuleContext)data;
|
||||||
SimpleNode firstStmt = (SimpleNode)node.jjtGetChild(1);
|
SimpleNode firstStmt = (SimpleNode)node.jjtGetChild(1);
|
||||||
|
|
||||||
if (!hasBlockAsFirstChild(firstStmt) && (node.getBeginLine() != this.lineNumberOfLastViolation)) {
|
if (!hasBlockAsFirstChild(firstStmt)) {
|
||||||
ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine()));
|
ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine()));
|
||||||
lineNumberOfLastViolation = node.getBeginLine();
|
|
||||||
}
|
}
|
||||||
return super.visit(node,data);
|
return super.visit(node,data);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user