View Javadoc
1   /*xml
2   <module name="Checker">
3     <module name="TreeWalker">
4       <module name="RightCurly"/>
5     </module>
6   </module>
7   */
8   
9   package com.puppycrawl.tools.checkstyle.checks.blocks.rightcurly;
10  
11  // xdoc section -- start
12  public class Example1 {
13  
14    public void test() {
15  
16      boolean foo = false;
17      if (foo) {
18        bar();
19      } // violation, 'should be on the same line'
20      // as the next part of a multi-block statement (one that directly
21      // contains multiple blocks: if/else-if/else, do/while or try/catch/finally).
22      else {
23        bar();
24      }
25  
26      if (foo) {
27        bar();
28      } else {
29        bar();
30      }
31  
32      if (foo) { bar(); } int i = 0;
33      // violation above, 'should be alone on a line.'
34  
35      if (foo) { bar(); }
36      i = 0;
37  
38      try {
39        bar();
40      } // violation, 'should be on the same line'
41      // as the next part of a multi-block statement (one that directly
42      // contains multiple blocks: if/else-if/else, do/while or try/catch/finally).
43      catch (Exception e) {
44        bar();
45      }
46  
47      try {
48        bar();
49      } catch (Exception e) {
50        bar();
51      }
52  
53    }
54  
55    private void bar() {
56    }
57  
58    public void testSingleLine() { bar(); } // OK, because singleline is allowed
59  }
60  // xdoc section -- end