View Javadoc
1   package com.google.checkstyle.test.chapter4formatting.rule412nonemptyblocks;
2   
3   /** some javadoc. */
4   public class InputRightCurlySwitchCasesBlocks {
5   
6     /** some javadoc. */
7     public static void test0() {
8       int mode = 0;
9       switch (mode) {
10        case 1:
11          {
12            int x = 1;
13            break;
14          }
15        case 2:
16          {
17            int x = 0;
18            break;
19          }
20        default:
21          {
22            int x = 0;
23          }
24      }
25    }
26  
27    /** some javadoc. */
28    public static void test() {
29      int mode = 0;
30      switch (mode) {
31        case 1:
32          {
33            int x = 1;
34            break;
35          } default:
36          int x = 0;
37          // 2 violations 2 lines above:
38          //  ''}' at column 9 should be alone on a line.'
39          //  ''case' child has incorrect indentation level 8, expected level should be 6.'
40      }
41    }
42  
43    /** some javadoc. */
44    public static void test1() {
45      int k = 0;
46      switch (k) {
47        case 1:
48          {
49          int x = 1; } // violation ''}' at column 20 should be alone on a line.'
50          break;
51        case 2:
52          int x = 2;
53          break;
54        default:
55      }
56    }
57  
58    /** some javadoc. */
59    public static void test2() {
60      int mode = 0;
61      switch (mode) {
62        case 1:
63          int x = 1;
64          break;
65        case 2:
66          {
67            break;
68          }
69        default:
70          {
71            break;
72          }
73      }
74    }
75  
76    /** some javadoc. */
77    public static void test3() {
78      int k = 0;
79      switch (k) {
80        case 1:
81          {
82            int x = 1;
83            break;
84          }
85        default:
86          {
87            int x = 2; } // false-negative until #14782
88      }
89    }
90  
91    /** some javadoc. */
92    public static void test4() {
93      int mode = 0;
94      switch (mode) {
95        case 1: { // violation ''{' at column 15 should be on a new line.'
96            int x = 1; // violation '.* incorrect indentation level 10, expected level should be 8.'
97            break; // violation '.* incorrect indentation level 10, expected level should be 8.'
98            // 2 violations 3 lines below:
99            //  ''block rcurly' has incorrect indentation level 8, expected level should be 6.'
100           //  ''}' at column 9 should be alone on a line.'
101         } default:
102           { // violation '.* incorrect indentation level 10, expected level should be 8.'
103                   int x = 0; // violation '.* incorrect indentation .*, expected .* 8, 10.'
104           } // violation '.* incorrect indentation level 10, expected level should be 8.'
105     }
106   }
107 
108   /** some javadoc. */
109   public static void test5() {
110     int k = 0;
111     switch (k) {
112       case 1: { // violation ''{' at column 15 should be on a new line.'
113         int x = 1; } // violation ''}' at column 20 should be alone on a line.'
114         break;
115       default: { // violation ''{' at column 16 should be on a new line.'
116   int a = 2; // violation '.* incorrect indentation level 2, expected level should be 8.'
117       }
118     }
119   }
120 
121   /** some javadoc. */
122   public static void test6() {
123     int mode = 0;
124     switch (mode) {
125       case 1:
126         int x = 1;
127         break;
128       case 2: { // violation ''{' at column 15 should be on a new line.'
129           break; // violation '.* incorrect indentation level 10, expected level should be 8.'
130         } // violation '.* incorrect indentation level 8, expected level should be 6.'
131       default:
132     }
133   }
134 
135   /** some javadoc. */
136   public static void test7() {
137     int k = 0;
138     switch (k) {
139       case 1:
140         {
141             int x = 1; // violation '.* incorrect indentation .* 12, expected .* following: 8, 10.'
142             break; // violation '.* incorrect indentation .* 12, expected .* following: 8, 10.'
143         }
144       default: { // violation ''{' at column 16 should be on a new line.'
145         int x = 2; } // false-negative until #14782
146     }
147   }
148 }