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