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