forked from phoedos/pmd
refactoring
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@458 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
17
pmd/src/net/sourceforge/pmd/rules/BracesRule.java
Normal file
17
pmd/src/net/sourceforge/pmd/rules/BracesRule.java
Normal 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));
|
||||
}
|
||||
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user