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