View Javadoc
1   /*
2   EmptyBlock
3   option = TEXT
4   tokens = LITERAL_DEFAULT
5   
6   
7   */
8   
9   package com.puppycrawl.tools.checkstyle.checks.blocks.emptyblock;
10  
11  public class InputEmptyBlockDefault {
12      void method1(int a) {
13          switch (a) {}
14          switch (a) {default: ; }
15          switch (a) {default: {}}    // violation 'Empty default block'
16          switch (a) {
17              default:
18          }
19          switch (a) {
20              default:
21              {}  // violation 'Empty default block'
22          }
23          switch (a) {
24              default:
25              {   // ok as the block contains a comment
26              }
27          }
28      }
29  
30      void method2(int a) {
31          switch (a) {
32              case 1:a++;
33              case 2:a++;
34              default:
35                  switch (a) {
36                      default: {  // ok as the block contains a comment
37  
38                      }
39                  }
40          }
41      }
42  
43      void method3(int a, int b) {
44          switch (a) {
45              case 1: break;
46              default: {} method2(a);     // violation 'Empty default block'
47          }
48  
49          switch (b) {
50              case 2: break;
51              default: method2(b); {}
52          }
53  
54          switch (a+b) {case 1: break; default: {} ; }    // violation 'Empty default block'
55      }
56  
57      void method4(int a, int b) {
58          switch (a) {
59              case 1:
60              default: {}      // violation 'Empty default block'
61          }
62  
63          switch (b) {
64              case 1:
65              default:
66          }
67  
68          switch (a+b) {
69              default:
70              case 1: { }
71          }
72  
73          switch (a-b) {
74              case 1:
75              default: {      // ok as the block contains a comment
76  
77              } ;
78              case 2: { }
79          }
80      }
81  
82      void method5(int a, int b) {
83          switch (a) {
84              case 1:
85              case 2:
86              case 3:
87              default:
88              {
89              }   // violation above 'Empty default block'
90          }
91  
92          switch (b) {
93              default:
94              case 1:
95              case 2: { } method2(b);
96              case 3:
97          }
98      }
99  }