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