View Javadoc
1   package com.google.checkstyle.test.chapter4formatting.rule412nonemptyblocks;
2   
3   class InputRightCurlyOther {
4     /**
5      * summary.
6      *
7      * @see test method *
8      */
9     int foo() throws InterruptedException {
10      int x = 1;
11      int a = 2;
12      while (true) {
13        try {
14          if (x > 0) {
15            break;
16          } else if (x < 0) {
17  
18            ;
19          } // violation ''}' at column 9 should be on the same line as the next part of .*'
20          else {
21            break;
22          }
23          switch (a) {
24            case 0:
25              break;
26            default:
27              break;
28          }
29        } // violation ''}' at column 7 should be on the same line as the next part of .*'
30        catch (Exception e) {
31          break;
32        }
33      }
34  
35      synchronized (this) {
36        do {
37          x = 2;
38        } while (x == 2);
39      }
40  
41      this.wait(666); // Bizarre, but legal
42  
43      for (int k = 0; k < 1; k++) {
44        String innerBlockVariable = "";
45      }
46  
47      if (System.currentTimeMillis() > 1000) {
48        return 1;
49      } else {
50        return 2;
51      }
52    }
53  
54    static {
55      int x = 1;
56    }
57  
58    public enum GreetingsEnum {
59      HELLO,
60      GOODBYE
61    }
62  
63    void method2() {
64      boolean flag = true;
65      if (flag) {
66        System.identityHashCode("heh");
67        // 2 violations 3 lines below:
68        //  ''}' at column 21 should have line break before.'
69        //  ''method def' child has incorrect indentation level 6, expected level should be 4.'
70        flag = !flag; } System
71        .identityHashCode("Xe-xe");
72  
73      if (flag) {
74        System.identityHashCode("some foo");
75      }
76    }
77  }
78  
79  /**
80   * Test input for closing brace if that brace terminates a statement or the body of a constructor.
81   */
82  class FooCtorAlone {
83    // violation above 'Top-level class FooCtorAlone has to reside in its own source file.'
84    int test;
85  
86    public FooCtorAlone() {
87      test = 1;
88    } } // violation ''}' at column 3 should be alone on a line.'
89  
90  /** Test input for closing brace if that brace terminates a statement or the body of a method. */
91  class FooMethodAlone {
92    // violation above 'Top-level class FooMethodAlone has to reside in its own source file.'
93    public void fooMethod() {
94      int i = 1;
95    } } // violation ''}' at column 3 should be alone on a line.'
96  
97  /**
98   * Test input for closing brace if that brace terminates a statement or the body of a named class.
99   */
100 class FooInnerAlone {
101   // violation above 'Top-level class FooInnerAlone has to reside in its own source file.'
102   class InnerFoo {
103     public void fooInnerMethod() {}
104   }
105 }
106 
107 // violation below 'Top-level class EnumContainerAlone has to reside in its own source file.'
108 class EnumContainerAlone {
109   private enum Suit {
110     CLUBS,
111     HEARTS,
112     SPADES,
113     DIAMONDS
114   }
115 }
116 
117 // violation below 'Top-level class WithArraysAlone has to reside in its own source file.'
118 class WithArraysAlone {
119   String[] ss = {""};
120   String[] empty = {};
121   String[] s1 = {
122     "foo", "foo",
123   };
124   String[] s2 = {
125     "foo", "foo",
126   };
127   String[] s3 = {
128     "foo", "foo",
129   };
130   String[] s4 = {"foo", "foo"};
131 }
132 
133 // violation below 'Top-level class Interface has to reside in its own source file.'
134 class Interface {
135   public @interface TestAnnotation {}
136 
137   public @interface TestAnnotation1 {
138     String someValue();
139   }
140 
141   public @interface TestAnnotation2 {
142     String someValue();
143   }
144 
145   public @interface TestAnnotation3 {
146     String someValue();
147   }
148 
149   public @interface TestAnnotation4 {
150     String someValue();
151   }
152 }
153 
154 // violation below 'Top-level class TestEnum has to reside in its own source file.'
155 enum TestEnum {}
156 
157 // violation below 'Top-level class TestEnum1 has to reside in its own source file.'
158 enum TestEnum1 {
159   SOME_VALUE;
160 }
161 
162 // violation below 'Top-level class TestEnum2 has to reside in its own source file.'
163 enum TestEnum2 {
164   SOME_VALUE;
165 }
166 
167 // violation below 'Top-level class TestEnum3 has to reside in its own source file.'
168 enum TestEnum3 {
169   SOME_VALUE;
170 }
171 
172 // violation below 'Top-level class TestEnum4 has to reside in its own source file.'
173 enum TestEnum4 {
174   SOME_VALUE;
175 }