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