1 package com.google.checkstyle.test.chapter4formatting.rule413emptyblocks;
2
3 class InputEmptyBlocksAndCatchBlocks {
4 static {
5 }
6
7 static {}
8
9 static { }
10
11 public void fooMethod() {
12 InputEmptyBlocksAndCatchBlocks r = new InputEmptyBlocksAndCatchBlocks();
13 int a = 1;
14 if (a == 1) { }
15
16 char[] s = {'1', '2'};
17 int index = 2;
18 if (doSideEffect() == 1) { }
19
20 Io in = new Io();
21 while ((r = in.read()) != null) {}
22 for (; index < s.length && s[index] != 'x'; index++) {}
23 if (a == 1) {
24 } else {
25 System.identityHashCode("a");
26 }
27 do {} while (a == 1);
28 switch (a) {
29 }
30
31 int[] z = {};
32 }
33
34 public int doSideEffect() {
35 return 1;
36 }
37
38 public void emptyMethod() {}
39
40 void foo() throws Exception {
41 int a = 90;
42
43 if (a == 1) {
44 } else {}
45
46 if (a == 1) {
47 } else { }
48
49
50 try (MyResource r = new MyResource()) { }
51
52 try (MyResource r = new MyResource()) {}
53 try (MyResource r = new MyResource()) {} catch (Exception expected) {}
54
55 try (MyResource r = new MyResource()) {} catch (Exception expected) { }
56
57 try (MyResource r = new MyResource()) {
58
59 } catch (Exception expected) {}
60 try (MyResource r = new MyResource()) {
61
62 } catch (Exception expected) { }
63
64 try (MyResource r = new MyResource()) {;}
65
66
67
68
69 }
70
71
72 public class MyResource implements AutoCloseable {
73
74 @Override
75 public void close() throws Exception {
76 System.out.println("Closed MyResource");
77 }
78 }
79 }
80
81
82 class Io {
83 public InputEmptyBlocksAndCatchBlocks read() {
84 return new InputEmptyBlocksAndCatchBlocks();
85 }
86 }
87
88
89 class Empty {}
90
91
92 interface EmptyImplement {}
93
94
95 class WithInner {
96 static {
97 }
98
99 public void emptyMethod() {}
100
101 public int doSideEffect() {
102 return 1;
103 }
104
105 class Inner {
106 private void withEmpty() {
107 InputEmptyBlocksAndCatchBlocks r = new InputEmptyBlocksAndCatchBlocks();
108 int a = 1;
109 if (a == 1) { }
110
111 char[] s = {'1', '2'};
112 int index = 2;
113 if (doSideEffect() == 1) { }
114
115 Io in = new Io();
116 while ((r = in.read()) != null) {}
117 for (; index < s.length && s[index] != 'x'; index++) {}
118 if (a == 1) {
119 } else {
120 System.identityHashCode("a");
121 }
122 do {} while (a == 1);
123 switch (a) {
124 }
125
126 int[] z = {};
127 }
128 }
129 }
130
131
132 class WithAnon {
133 interface AnonWithEmpty {
134 public void fooEmpty();
135 }
136
137 void method() {
138 AnonWithEmpty foo =
139 new AnonWithEmpty() {
140
141 public void emptyMethod() {}
142
143 public void fooEmpty() {
144 InputEmptyBlocksAndCatchBlocks r = new InputEmptyBlocksAndCatchBlocks();
145 int a = 1;
146 if (a == 1) { }
147
148 char[] s = {'1', '2'};
149 int index = 2;
150 if (doSideEffect() == 1) { }
151
152 Io in = new Io();
153 while ((r = in.read()) != null) {}
154 for (; index < s.length && s[index] != 'x'; index++) {}
155 if (a == 1) {
156 } else {
157 System.identityHashCode("a");
158 }
159 do {} while (a == 1);
160 switch (a) {
161 }
162
163 int[] z = {};
164 }
165
166 public int doSideEffect() {
167 return 1;
168 }
169 };
170 }
171 }
172
173
174 class NewClass {
175
176 void foo() {
177 int a = 1;
178
179 if (a == 1) {
180 System.identityHashCode("a");
181 } else {
182 }
183
184 if (a == 1) {
185 System.identityHashCode("a");
186 } else {
187
188 }
189
190 if (a == 1) {
191
192 } else {
193 System.identityHashCode("a");
194 }
195
196 if (a == 1) {
197 System.identityHashCode("a");
198 } else if (a != 1) {
199
200 } else {
201
202 }
203
204 if (a == 1) {
205
206 } else if (a != 1) {
207 System.identityHashCode("a");
208 } else {
209
210 }
211
212 if (a == 1) {
213
214 } else if (a != 1) {
215
216 } else {
217 System.identityHashCode("a");
218 }
219
220 if (a == 1) {
221
222 } else if (a != 1) {
223
224 } else {
225
226 }
227
228 if (a == 1) {
229
230 } else if (a != 1) {
231 } else {
232 }
233
234 if (a == 1) {
235 } else if (a != 1) {
236
237 } else {
238 }
239
240 if (a == 1) {
241 } else if (a != 1) {
242 } else {
243
244 }
245 }
246
247 class NewInner {
248
249 void foo() {
250 int a = 1;
251
252 if (a == 1) {
253 System.identityHashCode("a");
254 } else {
255 }
256
257 if (a == 1) {
258 System.identityHashCode("a");
259 } else {
260
261 }
262
263 if (a == 1) {
264
265 } else {
266 System.identityHashCode("a");
267 }
268
269 if (a == 1) {
270 System.identityHashCode("a");
271 } else if (a != 1) {
272
273 } else {
274
275 }
276
277 if (a == 1) {
278
279 } else if (a != 1) {
280 System.identityHashCode("a");
281 } else {
282
283 }
284
285 if (a == 1) {
286
287 } else if (a != 1) {
288
289 } else {
290 System.identityHashCode("a");
291 }
292
293 if (a == 1) {
294
295 } else if (a != 1) {
296
297 } else {
298
299 }
300
301 if (a == 1) {
302
303 } else if (a != 1) {
304 } else {
305 }
306
307 if (a == 1) {
308 } else if (a != 1) {
309
310 } else {
311 }
312
313 if (a == 1) {
314 } else if (a != 1) {
315 } else {
316
317 }
318 }
319
320 NewInner anon =
321 new NewInner() {
322
323 void foo() {
324 int a = 1;
325
326 if (a == 1) {
327 System.identityHashCode("a");
328 } else {
329 }
330
331 if (a == 1) {
332 System.identityHashCode("a");
333 } else {
334
335 }
336
337 if (a == 1) {
338
339 } else {
340 System.identityHashCode("a");
341 }
342
343 if (a == 1) {
344 System.identityHashCode("a");
345 } else if (a != 1) {
346
347 } else {
348
349 }
350
351 if (a == 1) {
352
353 } else if (a != 1) {
354 System.identityHashCode("a");
355 } else {
356
357 }
358
359 if (a == 1) {
360
361 } else if (a != 1) {
362
363 } else {
364 System.identityHashCode("a");
365 }
366
367 if (a == 1) {
368
369 } else if (a != 1) {
370
371 } else {
372
373 }
374
375 if (a == 1) {
376
377 } else if (a != 1) {
378 } else {
379 }
380
381 if (a == 1) {
382 } else if (a != 1) {
383
384 } else {
385 }
386
387 if (a == 1) {
388 } else if (a != 1) {
389 } else {
390
391 }
392 }
393 };
394 }
395 }
396
397
398 class Example {
399
400 void doNothing() {}
401
402 void doNothingElse() {}
403 }
404
405
406 class TestingEmptyBlockCatch {
407 boolean flag;
408
409 void doSm() {}
410
411 void foo() {
412 try {
413 if (!flag) {
414 doSm();
415 }
416 } catch (Exception e) {
417
418 } finally {
419
420 }
421 }
422
423 void foo2() {
424 try {
425 if (!flag) {
426 doSm();
427 }
428
429 } catch (Exception e) {
430 } finally {
431 }
432 }
433
434 class Inner {
435 boolean flag;
436
437 void doSm() {}
438
439 void foo() {
440 try {
441 if (!flag) {
442 doSm();
443 }
444 } catch (Exception e) {
445
446 } finally {
447
448 }
449 }
450
451 void foo2() {
452 try {
453 if (!flag) {
454 doSm();
455 }
456
457 } catch (Exception e) {
458 } finally {
459 }
460 }
461 }
462
463 Inner anon =
464 new Inner() {
465 boolean flag;
466
467 void doSm() {}
468
469 void foo() {
470 try {
471 if (!flag) {
472 doSm();
473 }
474 } catch (Exception e) {
475
476 } finally {
477
478 }
479 }
480
481 void foo2() {
482 try {
483 if (!flag) {
484 doSm();
485 }
486
487 } catch (Exception e) {
488 } finally {
489 }
490 }
491 };
492 }