View Javadoc
1   /*
2   RightCurly
3   option = ALONE
4   tokens = LITERAL_CASE
5   
6   */
7   package com.puppycrawl.tools.checkstyle.checks.blocks.rightcurly;
8   
9   public class InputRightCurlyCaseBlocksInSwitchStatementAlone {
10      public static void test0() {
11          int mode = 0;
12          switch (mode) {
13              case 1: {
14                  int x = 1;
15                  break;
16              }
17              case 2:
18              default:  {
19                  int x = 0;
20              }break;
21              case 3: {
22                  int x = 3;
23              }
24          }
25      }
26  
27      public static void test() {
28          int mode = 0;
29          switch (mode) {
30              case 1:{
31                  int x = 1;
32                  break;
33              } default :          // violation '}' at column 13 should be alone on a line'
34                  int x = 0;
35          }
36      }
37  
38      public static void test1() {
39          int k = 0;
40          switch (k) {
41              case 1:{
42                   int x = 1;
43                   break;
44              } case 2:        // violation '}' at column 13 should be alone on a line'
45                   int x = 2;
46                   break;
47          }
48      }
49  
50      public static void test2() {
51           int k = 0;
52           switch (k) {
53              case 1:{
54                   int x = 1;
55                   break;
56              }
57              case 2:
58                   int x = 2;
59                   break;
60           }
61      }
62  
63      public static void test3() {
64           int k = 0;
65           switch (k) {
66              case 1:{
67                   int x = 1;
68                   break;
69              }
70              case 2:{
71                      int x = 2;
72                      break;
73              } }      // violation '}' at column 13 should be alone on a line'
74      }
75  
76      public static void test4() {
77          int mode = 0;
78          switch (mode) { case 0: {int x = 1;} break; default : int x = 5; }
79          // violation above '}' at column 44 should be alone on a line'
80      }
81  
82      public static void test5() {
83          int mode = 0;
84          switch (mode) { case 0: }
85      }
86  
87      public static void test6() {
88          int mode = 0;
89          switch (mode) {
90              case 0: {int x = 1; break;}  // violation '}' at column 39 should be alone on a line'
91              default : break;
92          }
93      }
94  
95      public static void test7() {
96          int mode = 0;
97          switch (mode) {case 0:{int x = 1;} // violation '}' at column 42 should be alone on a line'
98              break; default : break; }
99      }
100 
101     public static void test8() {
102         int mode = 0;
103         int x = 0;
104         switch (mode) {
105             case 0:
106             case 1: x = 1; break;
107             case 2: {x = 1; break;} // violation '}' at column 35 should be alone on a line'
108             default : x = 5;
109         }
110     }
111 }