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