View Javadoc
1   /*xml
2   <module name="Checker">
3     <module name="TreeWalker">
4       <module name="RightCurly">
5         <property name="option" value="alone_or_singleline"/>
6         <property name="tokens" value="LITERAL_SWITCH, LITERAL_CASE"/>
7       </module>
8     </module>
9   </module>
10  */
11  
12  package com.puppycrawl.tools.checkstyle.checks.blocks.rightcurly;
13  
14  // xdoc section -- start
15  class Example5 {
16  
17    public void method0() {
18      int mode = 0;
19      int x;
20      switch (mode) {
21        case 1:
22          int y = 1;
23          break;
24        case 2: {x = 1;}   // ok, RightCurly is in single line
25        case 3: int z = 0; {break;} // ok, the braces is not a first child of case
26        default:
27          x = 0;
28      }
29    }
30  
31    public static void method7() {
32      int mode = 0;
33      switch (mode) {
34        case 1:
35          int x = 5;
36      } // ok, RightCurly is on the same line as LeftCurly
37    }
38  
39    public void method() {
40      int mode = 0;
41      int x;
42      switch (mode) {
43        case 1:
44          x = 1; }
45      // violation above, 'should be alone on a line.'
46    }
47  }
48  // xdoc section -- end