View Javadoc
1   /*
2   FallThrough
3   checkLastCaseGroup = (default)false
4   reliefPattern = (default)falls?[ -]?thr(u|ough)
5   
6   
7   */
8   
9   package com.puppycrawl.tools.checkstyle.checks.coding.fallthrough;
10  
11  public class InputFallThroughLabeledBreak {
12  
13      int method(int a, int b) {
14          top: switch (a) {
15              case 1:
16                  switch (b) {
17                      case 10:
18                          break top; // ok as terminates outer 'top' switch
19                      default:
20                          return 11;
21                  }
22              case 2:
23                  return 2;
24          }
25          outer: outer2: switch (a) {
26              case 1:
27                  inner1: inner2: switch (b) {
28                      case 10:
29                          break outer; // ok as terminates outer 'outer' switch
30                      default:
31                          return 11;
32                  }
33              case 2:
34                  inner: for (int i = 0;i < 3;i++) {
35                      // ok below as terminates outer 'outer2' switch
36                      break outer2;
37                  }
38              case 3:
39                  return 2;
40          }
41  
42          loop_outer: for(int c = 0; c < 2; c++) {
43              outer:switch (a) {
44                  case 1:
45                      inner:inner2:switch (b) {
46                          case 10:
47                              break inner;
48                          default:
49                              return 11;
50                      }
51                  case 2: // violation 'Fall through from previous branch of the switch statement.'
52                      inner: inner2: for (int i = 0; i < 3; i++) {
53                          break inner2;
54                      }
55                  case 3: // violation 'Fall through from previous branch of the switch statement.'
56                      return 1;
57                  case 4:
58                      switch (b) {
59                          case 10:
60                              break outer; // ok as terminates outer 'outer' switch
61                          default:
62                              return 11;
63                      }
64                  case 5:
65                      inner:{ switch (a) {
66                          case 1: break inner;
67                          }
68                      }
69                  case 6: // violation 'Fall through from previous branch of the switch statement.'
70                      inner:
71                      while (true) {
72                          break outer;
73                      }
74                  case 7:
75                      inner: while (true) {
76                          break inner;
77                      }
78                  case 8:  // violation 'Fall through from previous branch of the switch statement.'
79                      inner:
80                      while (true) {
81                          continue loop_outer;
82                      }
83                  case 9:
84                      loop_inner:
85                      while (true) {
86                          continue loop_inner;
87                      }
88                  case 10:  // violation 'Fall through from previous branch of the switch statement.'
89                      inner1:
90                      {
91                          switch (a) {
92                              case 1:
93                                  // ok below as terminates outer 'outer' switch
94                                  break outer;
95  
96                          }
97                      }
98                  case 11:
99                      return 1;
100             }
101         }
102         return -1;
103     }
104 }