View Javadoc
1   /*
2   DefaultComesLast
3   skipIfLastAndSharedWithCase = (default)false
4   
5   
6   */
7   
8   package com.puppycrawl.tools.checkstyle.checks.coding.defaultcomeslast;
9   
10  public class InputDefaultComesLast
11  {
12      void method(int i) {
13          // switch with last default
14          switch (i) {
15          case 1: break;
16          case 2: break;
17          default:
18              // do something :)
19          }
20  
21          // switch w/o default (not a problem)
22          switch (i) {
23          case 1: break;
24          case 2: break;
25          }
26  
27          // VIOLATION!!! default is not the last one.
28          switch (i) {
29          case 1:
30              break;
31          default: /**default is not last*/ // violation 'Default should be last label in the switch.'
32              break;
33          case 2:
34              break;
35          }
36  
37          switch (i) {
38          case 1: break; default: break; case 2: break; // violation 'Default should be last.'
39          }
40  
41          switch (i) {
42              case 1:
43              default: // violation 'Default should be last label in the switch.'
44                  break;
45              case 2:
46                  break;
47          }
48  
49          switch (i) {
50              case 1:
51              default: // violation 'Default should be last label in the switch.'
52              case 2:
53                  break;
54              case 3:
55                  break;
56          }
57  
58          switch (i) {
59              default: // violation 'Default should be last label in the switch.'
60              case 1:
61                  break;
62              case 2:
63                  break;
64          }
65  
66          switch (i) {
67              case 0: default: case 1: break; case 2: break; // violation 'Default should be last.'
68          }
69  
70          switch (i) {
71              default: case 1: break; case 2: break; // violation 'Default should be last.'
72          }
73  
74          switch (i) {
75              case 1: default: break; case 2: break; // violation 'Default should be last.'
76          }
77  
78          switch (i) {
79              case 1:
80              default: // violation 'Default should be last label in the switch.'
81                  break;
82              case 2:
83                  break;
84              case 3:
85                  break;
86          }
87  
88          switch (i) {
89              case 1:
90                  break;
91              default: // violation 'Default should be last label in the switch.'
92              case 2:
93                  break;
94              case 3:
95                  break;
96          }
97  
98          switch (i) {
99              case 1:
100                 break;
101             case 2:
102             default: // violation 'Default should be last label in the switch.'
103                 break;
104             case 3:
105                 break;
106         }
107 
108         switch (i) {
109             case 1:
110                 break;
111             case 2:
112             default: // violation 'Default should be last label in the switch.'
113             case 3:
114                 break;
115             case 4:
116                 break;
117         }
118 
119         switch (i) {
120             default: // violation 'Default should be last label in the switch.'
121                 break;
122             case 1:
123                 break;
124         }
125 
126         switch (i) {
127             case 1:
128                 break;
129             case 2:
130                 break;
131             default: // violation 'Default should be last label in the switch.'
132             case 5:
133             case 6:
134                 break;
135             case 7:
136                 break;
137         }
138     }
139 }
140 
141 @interface InputDefaultComesLastAnnotation
142 {
143     int blag() default 1;
144 }