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:
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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()));
|
||||
|
7
pmd/test-data/ForLoopsNeedBraces3.java
Normal file
7
pmd/test-data/ForLoopsNeedBraces3.java
Normal file
@ -0,0 +1,7 @@
|
||||
public class ForLoopsNeedBraces3 {
|
||||
public void foo() {
|
||||
for (int i=0; i<42;)
|
||||
foo();
|
||||
|
||||
}
|
||||
}
|
7
pmd/test-data/ForLoopsNeedBraces4.java
Normal file
7
pmd/test-data/ForLoopsNeedBraces4.java
Normal file
@ -0,0 +1,7 @@
|
||||
public class ForLoopsNeedBraces4 {
|
||||
public void foo() {
|
||||
for (int i=0;;)
|
||||
foo();
|
||||
|
||||
}
|
||||
}
|
7
pmd/test-data/ForLoopsNeedBraces5.java
Normal file
7
pmd/test-data/ForLoopsNeedBraces5.java
Normal file
@ -0,0 +1,7 @@
|
||||
public class ForLoopsNeedBraces5 {
|
||||
public void foo() {
|
||||
for (;;)
|
||||
foo();
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user