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