View Javadoc
1   package com.google.checkstyle.test.chapter4formatting.rule4861blockcommentstyle;
2   
3   /** some javadoc. */
4   public class InputCommentsIndentationInSwitchBlock {
5   
6     private static void fooSwitch() {
7       switch ("") {
8         case "0": // some comment
9         case "1":
10          // my comment
11          foo1();
12          break;
13        case "2":
14          // my comment
15          // comment
16          foo1();
17          // comment
18          break;
19        case "3":
20        /* // odd indentation comment
21           *  */
22          // violation 2 lines above '.* indentation should be the same level as line 23.'
23          foo1();
24          /* com */
25          break;
26        case "5":
27          // violation 2 lines below '.* indentation should be the same level as line 30.'
28          foo1();
29             // odd indentation comment
30          break;
31        case "6":
32          int k = 7;
33          // fall through
34        case "7":
35          // violation 2 lines below '.* indentation should be the same level as line 38.'
36          if (true) { /* foo */ }
37             // odd indentation comment
38          break;
39        case "8":
40          break;
41        case "9":
42          foo1();
43          // fall through
44        case "10": {
45          if (true) { /* foo */ }
46        }
47        // fall through
48        case "11": {
49        }
50        // fall through
51        case "28": {
52        }
53        // fall through
54        case "12": {
55    // odd indentation comment
56          // violation above '.* indentation should be the same level as line 57.'
57          int i;
58        }
59        break;
60        case "13": {
61          // some comment in empty case block
62        }
63        break;
64        case "14": {
65      // odd indentation comment
66          // violation above '.* indentation should be the same level as line 67.'
67        }
68        break;
69        case "15": {
70          // violation 2 lines below '.* indentation should be the same level as line 71.'
71          foo1();
72                // odd indentation comment
73        }
74        break;
75        case "16": {
76          int a;
77        }
78        // fall through
79        case "17": {
80          int a;
81        }
82        // violation below '.* indentation should be the same level as line 84.'
83    // odd indentation comment
84        break;
85        case "18": {
86          System.lineSeparator();
87        } // trailing comment
88        break;
89        case "19":
90          // comment
91        case "20":
92          // comment
93        case "21":
94        default:
95          // comment
96          break;
97      }
98    }
99  
100   private static void foo1() {
101     if (true) {
102       switch (1) {
103         case 0:
104 
105         case 1:
106           // violation below '.* indentation should be the same level as line 108.'
107               // odd indentation comment
108           int b = 10;
109           break;
110         default:
111           // comment
112       }
113     }
114   }
115 
116   /** some javadoc. */
117   public void fooDotInCaseBlock() {
118     int i = 0;
119     String s = "";
120 
121     switch (i) {
122       case -2:
123         // what
124         i++;
125         break;
126       case 0:
127         // what
128         s.indexOf("ignore");
129         break;
130       case -1:
131         // what
132         // violation 2 lines below '.* indentation should be the same .* as line 135.'
133         s.indexOf("no way");
134        // odd indentation comment
135         break;
136       case 1:
137       case 2:
138         i--;
139         break;
140       case 3: {
141       }
142       // fall through
143       default:
144     }
145 
146     String breaks =
147             ""
148                     // violation below '.* indentation should be the same level as line 150.'
149                         // odd indentation comment
150                     + "</table>"
151                     // middle
152                     + ""
153             // end
154             ;
155   }
156 
157   /** some javadoc. */
158   public void foo2() {
159     int a = 1;
160     switch (a) {
161       case 1:
162       default:
163   // odd indentation comment
164     }
165     // violation 2 lines above'.* indentation should be the same level as line 164.'
166   }
167 
168   /** some javadoc. */
169   public void foo3() {
170     int a = 1;
171     switch (a) {
172       case 1:
173       default:
174 
175         // comment
176     }
177   }
178 
179   /** some javadoc. */
180   public void foo4() {
181     int a = 1;
182     switch (a) {
183       case 1:
184         // violation 2 lines below '.* indentation should be the same .* as line 187.'
185         int b;
186           // odd indentation comment
187         break;
188       default:
189     }
190   }
191 
192   /** some javadoc. */
193   public void foo5() {
194     int a = 1;
195     switch (a) {
196       case 1:
197         int b;
198         // comment
199         break;
200       default:
201     }
202   }
203 
204   /** some javadoc. */
205   public void foo6() {
206     int a = 1;
207     switch (a) {
208       case 1:
209         int b;
210         // comment
211         break;
212       default:
213     }
214   }
215 
216   /** some javadoc. */
217   public void foo7() {
218     int a = 2;
219     String s = "";
220     switch (a) {
221       // comment
222       // comment
223       // comment
224       case 1:
225       case 2:
226         // comment
227         // comment
228         foo1();
229         // comment
230         break;
231       case 3:
232         // comment
233         // comment
234         // comment
235         // violation 2 lines below'.* indentation should be the same .* as line 236, 238.'
236       case 4:
237   // odd indentation comment
238       case 5:
239         // violation 4 lines below 'indentation should be the same level as line 246.'
240         // violation 4 lines below 'indentation should be the same level as line 246.'
241         // violation 4 lines below 'indentation should be the same level as line 246.'
242         s.toString().toString().toString();
243               // odd indentation comment
244            // odd indentation comment
245          // odd indentation comment
246         break;
247       default:
248     }
249   }
250 
251   /** some javadoc. */
252   public void foo8() {
253     int a = 2;
254     String s = "";
255     switch (a) {
256       // comment
257       // comment
258       // comment
259       case 1:
260       case 2:
261         // comment
262         // comment
263         foo1();
264         // comment
265         break;
266       case 3:
267         // comment
268         // comment
269         s.toString().toString().toString();
270         // comment
271         // violation 3 lines below '.* indentation should be the same level as line 273, 275.'
272         break;
273       case 4:
274   // odd indentation comment
275       default:
276     }
277   }
278 
279   /** some javadoc. */
280   public void foo9() {
281     int a = 5;
282     switch (a) {
283       case 1:
284       case 2:
285         // comment
286       default:
287     }
288   }
289 
290   /** some javadoc. */
291   public void foo10() {
292     int a = 5;
293     switch (a) {
294       case 1:
295       default:
296         // comment
297     }
298   }
299 
300   /** some javadoc. */
301   public void foo11() {
302     int a = 5;
303     switch (a) {
304       case 1:
305       case 2:
306         // comment
307       default:
308     }
309   }
310 
311   /** some javadoc. */
312   public void foo12() {
313     int a = 5;
314     switch (a) {
315       // comment
316       case 1:
317       default:
318     }
319   }
320 }