PageRenderTime 2ms CodeModel.GetById 121ms app.highlight 21ms RepoModel.GetById 60ms app.codeStats 0ms

/src/test/resources/com/puppycrawl/tools/checkstyle/coding/InputFallThrough.java

https://github.com/marschall/checkstyle
Java | 409 lines | 360 code | 18 blank | 31 comment | 34 complexity | ffb3ab672ea2faf0ce894cd345c537bb MD5 | raw file
  1package com.puppycrawl.tools.checkstyle.coding;
  2
  3public class InputFallThrough
  4{
  5    void method(int i, int j, boolean cond) {
  6        while (true) {
  7            switch (i) {
  8            case 0: // no problem
  9            case 1:
 10                i++;
 11                break;
 12            case 2:
 13                i++;
 14            case 3: //fall through!!!
 15                i++;
 16                break;
 17            case 4:
 18                return;
 19            case 5:
 20                throw new RuntimeException("");
 21            case 6:
 22                continue;
 23            case 7: {
 24                break;
 25            }
 26            case 8: {
 27                return;
 28            }
 29            case 9: {
 30                throw new RuntimeException("");
 31            }
 32            case 10: {
 33                continue;
 34            }
 35            case 11: {
 36                i++;
 37            }
 38            case 12: //fall through!!!
 39                if (false)
 40                    break;
 41                else
 42                    break;
 43            case 13:
 44                if (true) {
 45                    return;
 46                }
 47            case 14:
 48                if (true) {
 49                    return;
 50                } else {
 51                    //do nothing
 52                }
 53            case 15: //fall through!!!
 54                do {
 55                    System.out.println("something");
 56                    return;
 57                } while(true);
 58            case 16:
 59                for (int j1 = 0; j1 < 10; j1++) {
 60                    System.err.println("something");
 61                    return;
 62                }
 63            case 17:
 64                while (true)
 65                    throw new RuntimeException("");
 66            case 18:
 67                while(cond) {
 68                    break;
 69                }
 70            case 19: //fall through!!!
 71                try {
 72                    i++;
 73                    break;
 74                } catch (RuntimeException e) {
 75                    break;
 76                } catch (Error e) {
 77                    return;
 78                }
 79            case 20:
 80                try {
 81                    i++;
 82                    break;
 83                } catch (RuntimeException e) {
 84                } catch (Error e) {
 85                    return;
 86                }
 87            case 21: //fall through!!!
 88                try {
 89                    i++;
 90                } catch (RuntimeException e) {
 91                    i--;
 92                } finally {
 93                    break;
 94                }
 95            case 22:
 96                try {
 97                    i++;
 98                    break;
 99                } catch (RuntimeException e) {
100                    i--;
101                    break;
102                } finally {
103                    i++;
104                }
105            case 23: //fall through!!!
106                switch (j) {
107                case 1:
108                    continue;
109                case 2:
110                    return;
111                default:
112                    return;
113                }
114            case 24:
115                switch (j) {
116                case 1:
117                    continue;
118                case 2:
119                    break;
120                default:
121                    return;
122                }
123            default: //fall through!!!
124                // this is the last label
125                i++;
126            }
127        }
128    }
129    
130    
131    
132    /* Like above, but all fall throughs with relief comment */
133    void methodFallThru(int i, int j, boolean cond) {
134      while (true) {
135          switch (i) {
136          case -1: // FALLTHRU
137              
138          case 0: // no problem
139          case 1:
140              i++;
141              break;
142          case 2:
143              i++;
144              // fallthru
145          case 3: 
146              i++;
147              break;
148          case 4:
149              return;
150          case 5:
151              throw new RuntimeException("");
152          case 6:
153              continue;
154          case 7: {
155              break;
156          }
157          case 8: {
158              return;
159          }
160          case 9: {
161              throw new RuntimeException("");
162          }
163          case 10: {
164              continue;
165          }
166          case 11: {
167              i++;
168          }
169          // fallthru
170          case 12: 
171              if (false)
172                  break;
173              else
174                  break;
175          case 13:
176              if (true) {
177                  return;
178              }
179          case 14:
180              if (true) {
181                  return;
182              } else {
183                  //do nothing
184              }
185              // fallthru
186          case 15:
187              do {
188                  System.out.println("something");
189                  return;
190              } while(true);
191          case 16:
192              for (int j1 = 0; j1 < 10; j1++) {
193                  System.err.println("something");
194                  return;
195              }
196          case 17:
197              while (cond)
198                  throw new RuntimeException("");
199          case 18:
200              while(cond) {
201                  break;
202              }
203              // fallthru
204          case 19:
205              try {
206                  i++;
207                  break;
208              } catch (RuntimeException e) {
209                  break;
210              } catch (Error e) {
211                  return;
212              }
213          case 20:
214              try {
215                  i++;
216                  break;
217              } catch (RuntimeException e) {
218              } catch (Error e) {
219                  return;
220              }
221              // fallthru
222          case 21:
223              try {
224                  i++;
225              } catch (RuntimeException e) {
226                  i--;
227              } finally {
228                  break;
229              }
230          case 22:
231              try {
232                  i++;
233                  break;
234              } catch (RuntimeException e) {
235                  i--;
236                  break;
237              } finally {
238                  i++;
239              }
240              /* fallthru */
241          case 23:
242              switch (j) {
243              case 1:
244                  continue;
245              case 2:
246                  return;
247              default:
248                  return;
249              }        
250          case 24:
251              i++;
252          /* fallthru */ case 25: 
253              i++;
254              break;
255
256          case 26:
257              switch (j) {
258              case 1:
259                  continue;
260              case 2:
261                  break;
262              default:
263                  return;
264              } 
265              // fallthru
266          default:
267              // this is the last label
268              i++;
269          // fallthru
270         }
271      }
272   }
273    
274   /* Test relief comment. */
275   void methodFallThruCC(int i, int j, boolean cond) {
276      while (true) {
277          switch (i){
278          case 0:
279              i++; // fallthru
280
281          case 1:
282              i++;
283          // fallthru
284          case 2: {
285              i++;
286          }
287          // fallthru
288          case 3:
289              i++;
290          /* fallthru */case 4:
291                break;
292          case 5:
293              i++;
294          // fallthru
295          }
296      }
297   }
298    
299   /* Like above, but C-style comments. */
300   void methodFallThruC(int i, int j, boolean cond) {
301      while (true) {
302          switch (i){
303          case 0:
304              i++; /* fallthru */
305
306          case 1:
307              i++;
308          /* fallthru */
309          case 2:
310              i++;
311          /* fallthru */case 3:
312                break;
313          case 4:
314              i++;
315          /* fallthru */
316          }
317      }
318   }
319
320   /* Like above, but C-style comments with no spaces. */
321   void methodFallThruC2(int i, int j, boolean cond) {
322      while (true) {
323          switch (i){
324          case 0:
325              i++; /*fallthru*/
326
327          case 1:
328              i++;
329          /*fallthru*/
330          case 2:
331              i++;
332          /*fallthru*/case 3:
333                break;
334          case 4:
335              i++;
336          /*fallthru*/
337          }
338      }
339   }
340    
341   /* C-style comments with other default fallthru-comment. */
342   void methodFallThruCOtherWords(int i, int j, boolean cond) {
343      while (true) {
344          switch (i){
345          case 0:
346              i++; /* falls through */
347
348          case 1:
349              i++;
350          /* falls through */
351          case 2:
352              i++;
353          /* falls through */case 3:
354                break;
355          case 4:
356              i++;
357          /* falls through */
358          }
359      }
360   }
361    
362   /* C-style comments with custom fallthru-comment. */
363   void methodFallThruCCustomWords(int i, int j, boolean cond) {
364      while (true) {
365          switch (i){
366          case 0:
367              i++; /* Continue with next case */
368
369          case 1:
370              i++;
371          /* Continue with next case */
372          case 2:
373              i++;
374          /* Continue with next case */case 3:
375                break;
376          case 4:
377              i++;
378          /* Continue with next case */
379          }
380      }
381   }
382   
383   void methodFallThruLastCaseGroup(int i, int j, boolean cond) {
384       while (true) {
385           switch (i){
386           case 0:
387               i++; // fallthru
388           }
389           switch (i){
390           case 0:
391               i++; 
392               // fallthru
393           }
394           switch (i){
395           case 0:
396               i++; 
397           /* fallthru */ }
398       }
399    }
400
401    void method1472228(int i) {
402        switch(i) {
403        case 2:
404            // do nothing
405            break;
406        default:
407        }
408    }
409}