1 /*xml
2 <module name="Checker">
3 <module name="TreeWalker">
4 <module name="NeedBraces">
5 <property name="allowEmptyLoopBody" value="true"/>
6 <property name="tokens" value="LITERAL_WHILE, LITERAL_FOR"/>
7 </module>
8 </module>
9 </module>
10 */
11
12 package com.puppycrawl.tools.checkstyle.checks.blocks.needbraces;
13
14 // xdoc section -- start
15 class Example5 {
16 String obj = new String();
17 String value = new String();
18 int counter = 1;
19 int count = 0;
20 int num = 12;
21 String o = "O";
22 public boolean Example5() {
23 if (obj.equals(num)) return true;
24 // ok above, because IF is not a target of validation
25 if (true) {
26 count = 2;
27 } else
28 // ok above, because ELSE is not a target of validation
29 return false;
30 for (int i = 0; i < 5; i++) {
31 ++count;}
32 do // ok, because DO is not a target of validation
33 ++count;
34 while (false);
35 for (int j = 0; j < 10; j++);
36 // ok above, because FOR is not a target of validation
37 for(int i = 0; i < 10; value.charAt(12));
38 // ok above, because FOR is not a target of validation
39 while (counter < 10)
40 // violation above, ''while' construct must use '{}'s.'
41 ++count;
42 while (value.charAt(12) < 5);
43 // ok above, because WHILE is not a target of validation
44 switch (num) {
45 case 1: counter++; break;
46 // ok above, because break in case blocks is not counted to allow compact view
47 }
48 return true;
49 }
50 }
51
52
53
54 // xdoc section -- end