View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // Test case file for checkstyle.
3   // Created: 2001
4   ///////////////////////////////////////////////////////////////////////////////////////////////
5   package com.google.checkstyle.test.chapter4formatting.rule413emptyblocks;
6   
7   import java.io.*;
8   import java.awt.Dimension;
9   import java.awt.Color;
10  
11  class InputEmptyBlockBasic
12  {
13      static {} //ok
14  
15      public void fooMethod()
16      {
17          InputEmptyBlockBasic r = new InputEmptyBlockBasic();
18          int a = 1;
19          if (a == 1) {} // warn
20          char[] s = {'1', '2'};
21          int index = 2;
22          if (doSideEffect() == 1) {} // warn
23          IO in = new IO();
24          while ((r = in.read()) != null) {} // ok
25          for (; index < s.length && s[index] != 'x'; index++) {} // ok
26          if (a == 1) {} else {System.identityHashCode("a");}  // warn
27          do {} while(a == 1); //ok
28          switch (a) {} //warn
29          int[] z = {}; // ok
30      }
31  
32      public int doSideEffect()
33      {
34          return 1;
35      }
36  
37      public void emptyMethod() {}
38  }
39  
40  class IO
41  {
42      public InputEmptyBlockBasic read()
43      {
44          return new InputEmptyBlockBasic();
45      }
46  }
47  class Empty {} //ok
48  
49  interface EmptyImplement {} //ok
50  
51  class WithInner
52  {
53      static {} //ok
54  
55      public void emptyMethod() {}
56  
57      public int doSideEffect()
58      {
59          return 1;
60      }
61  
62      class Inner
63      {
64          private void withEmpty()
65          {
66              InputEmptyBlockBasic r = new InputEmptyBlockBasic();
67              int a = 1;
68              if (a == 1) {} // warn
69              char[] s = {'1', '2'};
70              int index = 2;
71              if (doSideEffect() == 1) {} //warn
72              IO in = new IO();
73              while ((r = in.read()) != null) {} // ok
74              for (; index < s.length && s[index] != 'x'; index++) {} // ok
75              if (a == 1) {} else {System.identityHashCode("a");} // warn
76              do {} while(a == 1); //ok
77              switch (a) {} //warn
78              int[] z = {}; // ok
79          }
80      }
81  }
82  
83  class WithAnon
84  {
85      interface AnonWithEmpty {
86          public void fooEmpty();
87      }
88  
89      void method()
90      {
91          AnonWithEmpty foo = new AnonWithEmpty() {
92  
93              public void emptyMethod() {}
94  
95              public void fooEmpty() {
96                  InputEmptyBlockBasic r = new InputEmptyBlockBasic();
97                  int a = 1;
98                  if (a == 1) {} //warn
99                  char[] s = {'1', '2'};
100                 int index = 2;
101                 if (doSideEffect() == 1) {} //warn
102                 IO in = new IO();
103                 while ((r = in.read()) != null) {} // ok
104                 for (; index < s.length && s[index] != 'x'; index++) {} // ok
105                 if (a == 1) {} else {System.identityHashCode("a");} // warn
106                 do {} while(a == 1); //ok
107                 switch (a) {} //warn
108                 int[] z = {}; // ok
109             }
110 
111             public int doSideEffect()
112             {
113                 return 1;
114             }
115         };
116     }
117 }
118 
119 class NewClass {
120 
121     void foo() {
122         int a = 1;
123 
124         if (a == 1) {
125             System.identityHashCode("a");
126         } else {} // warn
127 
128         if (a == 1) {
129             System.identityHashCode("a");
130         } else {/*ignore*/} // OK
131 
132         if (a == 1) {
133             /*ignore*/
134         } else {
135             System.identityHashCode("a");
136         } // ok
137 
138         if (a == 1) {
139             System.identityHashCode("a");
140         } else if (a != 1) {
141             /*ignore*/
142         } else {
143             /*ignore*/
144         }
145 
146         if (a == 1) {
147             /*ignore*/
148         } else if (a != 1) {
149             System.identityHashCode("a");
150         } else {
151             /*ignore*/
152         }
153 
154         if (a == 1) {
155             /*ignore*/
156         } else if (a != 1) {
157             /*ignore*/
158         } else {
159             System.identityHashCode("a");
160         }
161 
162         if (a == 1) {
163             /*ignore*/
164         } else if (a != 1) {
165             /*ignore*/
166         } else {
167             /*ignore*/
168         }
169 
170         if (a == 1) {
171             /*ignore*/
172         } else if (a != 1) {} //warn
173         else {} //warn
174 
175         if (a == 1) {} //warn
176         else if (a != 1) {
177             /*ignore*/
178         }
179         else {} //warn
180 
181         if (a == 1) {} //warn
182         else if (a != 1) {} //warn
183         else {
184             /*ignore*/
185         }
186     }
187 
188     class NewInner {
189 
190         void foo() {
191             int a = 1;
192 
193             if (a == 1) {
194                 System.identityHashCode("a");
195             } else {} // warn
196 
197             if (a == 1) {
198                 System.identityHashCode("a");
199             } else {/*ignore*/} // OK
200 
201             if (a == 1) {
202                 /*ignore*/
203             } else {
204                 System.identityHashCode("a");
205             } // ok
206 
207             if (a == 1) {
208                 System.identityHashCode("a");
209             } else if (a != 1) {
210                 /*ignore*/
211             } else {
212                 /*ignore*/
213             }
214 
215             if (a == 1) {
216                 /*ignore*/
217             } else if (a != 1) {
218                 System.identityHashCode("a");
219             } else {
220                 /*ignore*/
221             }
222 
223             if (a == 1) {
224                 /*ignore*/
225             } else if (a != 1) {
226                 /*ignore*/
227             } else {
228                 System.identityHashCode("a");
229             }
230 
231             if (a == 1) {
232                 /*ignore*/
233             } else if (a != 1) {
234                 /*ignore*/
235             } else {
236                 /*ignore*/
237             }
238 
239             if (a == 1) {
240                 /*ignore*/
241             } else if (a != 1) {} //warn
242             else {} //warn
243 
244             if (a == 1) {} //warn
245             else if (a != 1) {
246                 /*ignore*/
247             }
248             else {} //warn
249 
250             if (a == 1) {} //warn
251             else if (a != 1) {} //warn
252             else {
253                 /*ignore*/
254             }
255         }
256 
257         NewInner anon = new NewInner() {
258 
259             void foo() {
260                 int a = 1;
261 
262                 if (a == 1) {
263                     System.identityHashCode("a");
264                 } else {} // warn
265 
266                 if (a == 1) {
267                     System.identityHashCode("a");
268                 } else {/*ignore*/} // OK
269 
270                 if (a == 1) {
271                     /*ignore*/
272                 } else {
273                     System.identityHashCode("a");
274                 } // ok
275 
276                 if (a == 1) {
277                     System.identityHashCode("a");
278                 } else if (a != 1) {
279                     /*ignore*/
280                 } else {
281                     /*ignore*/
282                 }
283 
284                 if (a == 1) {
285                     /*ignore*/
286                 } else if (a != 1) {
287                     System.identityHashCode("a");
288                 } else {
289                     /*ignore*/
290                 }
291 
292                 if (a == 1) {
293                     /*ignore*/
294                 } else if (a != 1) {
295                     /*ignore*/
296                 } else {
297                     System.identityHashCode("a");
298                 }
299 
300                 if (a == 1) {
301                     /*ignore*/
302                 } else if (a != 1) {
303                     /*ignore*/
304                 } else {
305                     /*ignore*/
306                 }
307 
308                 if (a == 1) {
309                     /*ignore*/
310                 } else if (a != 1) {} //warn
311                 else {} //warn
312 
313                 if (a == 1) {} //warn
314                 else if (a != 1) {
315                     /*ignore*/
316                 }
317                 else {} //warn
318 
319                 if (a == 1) {} //warn
320                 else if (a != 1) {} //warn
321                 else {
322                     /*ignore*/
323                 }
324             }
325         };
326     }
327 }
328 
329 class Example {
330 
331     void doNothing() {} // ok
332 
333     void doNothingElse() { // ok
334 
335     }
336 }