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