KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > InputNestedBlocks


1 ////////////////////////////////////////////////////////////////////////////////
2
// Test case file for checkstyle.
3
// Created: 2001
4
////////////////////////////////////////////////////////////////////////////////
5
package com.puppycrawl.tools.checkstyle;
6
7 /**
8  * Test case for finding nested blocks.
9  * @author lkuehne
10  **/

11 class InputNestedBlocks
12 {
13     static
14     { // OK
15
}
16
17     public void method()
18     {
19         int x = 0;
20
21         // if (condition that is not important anymore)
22
{ // nested block, should be marked
23
int z = 1;
24             int y = z;
25         }
26
27         if (x == 1)
28         { // OK
29
x = 2;
30         }
31
32         // case statements are a bit complicated,
33
// they do not have its own variable scope by default.
34
// Hence it may be OK in some development teams to allow
35
// nested blocks if they are the complete case body.
36
switch (x)
37         {
38             case 0:
39                 // OK
40
x = 3;
41                 break;
42             case 1:
43                 // Not OK, SLIST is not complete case body
44
{
45                     x = 1;
46                 }
47                 break;
48             case 2:
49                 // OK if allowInSwitchCase is true, SLIST is complete case body
50
{
51                     x = 1;
52                     break;
53                 }
54             case 3: // test fallthrough
55
default:
56                 // Not OK, SLIST is not complete case body
57
System.out.println("Hello");
58                 {
59                     x = 2;
60                 }
61         }
62     }
63 }
64
Popular Tags