fixed bug # 588083

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@544 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-07-29 15:21:41 +00:00
parent 1d34b9b803
commit 6e7abaa671
5 changed files with 37 additions and 1 deletions

View File

@ -23,4 +23,19 @@ public class ForLoopsMustUseBracesRuleTest extends RuleTst {
Report report = process("ForLoopsNeedBraces2.java", new ForLoopsMustUseBracesRule());
assertTrue(report.isEmpty());
}
public void test3() throws Throwable {
Report report = process("ForLoopsNeedBraces3.java", new ForLoopsMustUseBracesRule());
assertEquals(1, report.size());
}
public void test4() throws Throwable {
Report report = process("ForLoopsNeedBraces4.java", new ForLoopsMustUseBracesRule());
assertEquals(1, report.size());
}
public void test5() throws Throwable {
Report report = process("ForLoopsNeedBraces5.java", new ForLoopsMustUseBracesRule());
assertEquals(1, report.size());
}
}

View File

@ -16,7 +16,7 @@ public class ForLoopsMustUseBracesRule extends BracesRule {
public Object visit(ASTForStatement node, Object data) {
RuleContext ctx = (RuleContext)data;
SimpleNode loopBody = (SimpleNode)node.jjtGetChild(3);
SimpleNode loopBody = (SimpleNode)node.jjtGetChild(node.jjtGetNumChildren()-1);
if (!hasBlockAsFirstChild(loopBody)) {
ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine()));

View File

@ -0,0 +1,7 @@
public class ForLoopsNeedBraces3 {
public void foo() {
for (int i=0; i<42;)
foo();
}
}

View File

@ -0,0 +1,7 @@
public class ForLoopsNeedBraces4 {
public void foo() {
for (int i=0;;)
foo();
}
}

View File

@ -0,0 +1,7 @@
public class ForLoopsNeedBraces5 {
public void foo() {
for (;;)
foo();
}
}