01: ////////////////////////////////////////////////////////////////////////////////
02: // Test case file for checkstyle.
03: // Created: 2001
04: ////////////////////////////////////////////////////////////////////////////////
05: package com.puppycrawl.tools.checkstyle;
06:
07: /**
08: * Test case for finding nested blocks.
09: * @author lkuehne
10: **/
11: class InputNestedBlocks {
12: static { // OK
13: }
14:
15: public void method() {
16: int x = 0;
17:
18: // if (condition that is not important anymore)
19: { // nested block, should be marked
20: int z = 1;
21: int y = z;
22: }
23:
24: if (x == 1) { // OK
25: x = 2;
26: }
27:
28: // case statements are a bit complicated,
29: // they do not have its own variable scope by default.
30: // Hence it may be OK in some development teams to allow
31: // nested blocks if they are the complete case body.
32: switch (x) {
33: case 0:
34: // OK
35: x = 3;
36: break;
37: case 1:
38: // Not OK, SLIST is not complete case body
39: {
40: x = 1;
41: }
42: break;
43: case 2:
44: // OK if allowInSwitchCase is true, SLIST is complete case body
45: {
46: x = 1;
47: break;
48: }
49: case 3: // test fallthrough
50: default:
51: // Not OK, SLIST is not complete case body
52: System.out.println("Hello");
53: {
54: x = 2;
55: }
56: }
57: }
58: }
|