1   package com.puppycrawl.tools.checkstyle.checks.blocks.needbraces;
2   
3   public class InputNeedBracesSingleLineStatements
4   {
5       private static class SomeClass {
6           boolean flag = true;
7           private static boolean test(boolean k) {
8               return k;
9           }
10      }
11  
12      private int foo() {
13          if (SomeClass.test(true) == true) return 4; //No warning if 'mAllowSingleLineIf' is true
14          return 0;
15      }
16  
17      private int foo1() {
18          if (SomeClass.test(true)) return 4; int k = 3; //No warning if 'mAllowSingleLineIf' is true
19          return 0;
20      }
21  
22      private int foo2() {
23          if (SomeClass.test(true) == true) //Warning, not single-line if-statement
24              return 4;
25          return 0;
26      }
27  
28      private int foo3() {
29          if (SomeClass.test(true) == true) if (true) return 4; //Warning, complex block
30          return 0;
31      }
32  
33      private void foo(Object o) {
34          if (o != null) this.notify();
35      }
36  
37      private void foo2(Object o) {
38          if (o != null)
39              this.notify();
40      }
41  
42      private void loopTest(Object o) {
43          while (o != null) {
44              this.notify();
45          }
46          while (o != null)
47              this.notify();
48          while (o != null) this.notify();
49          do {
50              this.notify();
51          } while (o != null);
52          do this.notify(); while (o != null);
53          do
54              this.notify();
55          while (o != null);
56          for (;;)
57              break;
58          for (;;) break;
59          for (int i = 0; i < 10; i++) {
60               this.notify();
61          }
62          for (int i = 0; i < 10; i++)
63               this.notify();
64          for (int i = 0; ; ) this.notify();
65      }
66  
67      private int getSmth(int num)
68      {
69          int counter = 0;
70          switch (num) {
71              case 1: counter++; break;
72              case 2:
73                  counter += 2;
74                  break;
75              case 3:
76                  counter += 3;
77                  break;
78              case 6: counter += 10; break;
79              default: counter = 100; break;
80          }
81          return counter;
82      }
83  
84      private void testElse(int k) {
85          if (k == 4) System.identityHashCode("yes");
86          else System.identityHashCode("no");
87          for (;;);
88      }
89  
90      private int testMissingWarnings() {
91          if (true)
92              throw new RuntimeException();
93          if (true) {
94              return 1;
95          } else
96              return 2;
97      }
98  
99      void enhancedForLoop(int[] array) {
100         for (int value: array) return;
101     }
102 
103     int[] sourceLocators;
104 
105     private class StateInfo {
106         public boolean isInitial() {
107             for (int locator: sourceLocators) if (locator != 0) return false;
108             return true;
109         }
110     }
111 
112     private void forEachLoop() {
113         for (String s: new String[]{""}) break;
114         for (String s: new String[]{""})
115             break;
116         for (;;)
117         ;
118     }
119 }