View Javadoc
1   /*
2   RightCurly
3   option = ALONE
4   tokens = CLASS_DEF, METHOD_DEF, CTOR_DEF, ANNOTATION_DEF, ENUM_DEF, INTERFACE_DEF
5   
6   
7   */
8   
9   package com.puppycrawl.tools.checkstyle.checks.blocks.rightcurly;
10  
11  class InputRightCurlyLeftTestNewLine
12  {
13      /** @see test method **/
14      int foo() throws InterruptedException
15      {
16          int x = 1;
17          int a = 2;
18          while (true)
19          {
20              try
21              {
22                  if (x > 0)
23                  {
24                      break;
25                  }
26                  else if (x < 0) {
27                      ;
28                  }
29                  else
30                  {
31                      break;
32                  }
33                  switch (a)
34                  {
35                  case 0:
36                      break;
37                  default:
38                      break;
39                  }
40              }
41              catch (Exception e)
42              {
43                  break;
44              }
45              finally
46              {
47                  break;
48              }
49          }
50  
51          synchronized (this)
52          {
53              do
54              {
55                  x = 2;
56              } while (x == 2);
57          }
58  
59          this.wait(666
60                   ); // Bizarre, but legal
61  
62          for (int k = 0; k < 1; k++)
63          {
64              String innerBlockVariable = "";
65          }
66  
67          // test input for bug reported by Joe Comuzzi
68          if (System.currentTimeMillis() > 1000)
69              return 1;
70          else
71              return 2;
72      }
73  
74      // Test static initialiser
75      static
76      {
77          int x = 1; // should not require any javadoc
78      }
79  
80  
81  
82      public enum GreetingsEnum
83      {
84          HELLO,
85          GOODBYE
86      }; // violation ''}' at column 5 should be alone on a line'
87  
88      void method2()
89      {
90          boolean flag = true;
91          if (flag) {
92              System.identityHashCode("heh");
93              flag = !flag; } String.CASE_INSENSITIVE_ORDER.
94                equals("Xe-xe");
95          // it is ok to have rcurly on the same line as previous
96          // statement if lcurly on the same line.
97          if (flag) { String.CASE_INSENSITIVE_ORDER.equals("it is ok."); }
98      }
99  }
100 
101 /**
102  * Test input for closing brace if that brace terminates
103  * a statement or the body of a constructor.
104  */
105 class FooCtorTestNewLine
106 {
107         int i;
108         public void FooCtor()
109     {
110                 i = 1;
111     }} // 2 violations
112 
113 /**
114 * Test input for closing brace if that brace terminates
115 * a statement or the body of a method.
116 */
117 class FooMethodTestNewLine
118 {
119         public void fooMethod()
120     {
121                 int i = 1;
122     }} // 2 violations
123 
124 /**
125 * Test input for closing brace if that brace terminates
126 * a statement or the body of a named class.
127 */
128 class FooInnerTestNewLine
129 {
130         class InnerFoo
131     {
132                 public void fooInnerMethod ()
133         {
134 
135                 }
136     }} // 2 violations
137 
138 /**
139  * False positive
140  *
141  */
142 class Absent_CustomFieldSerializer3TestNewLine {
143 
144     public static void serialize() {} // violation ''}' at column 37 should be alone on a line'
145 }
146 
147 class Absent_CustomFieldSerializer4TestNewLine
148 {
149   void Absent_CustomFieldSerializer4() {} // violation ''}' at column 41 should be alone on a line'
150 }
151 
152 class EmptyClass2TestNewLine {} // violation ''}' at column 31 should be alone on a line'
153 
154 interface EmptyInterface3TestNewLine {} // violation ''}' at column 39 should be alone on a line'
155 
156 class ClassWithStaticInitializersTestNewLine
157 {
158     static {
159     }
160     static
161     {}
162 
163     static class Inner
164     {
165         static {
166             int i = 1;
167         }
168     }
169 
170     public void emptyBlocks() {
171         try {
172             // comment
173         } catch (RuntimeException e) {
174             new Object();
175         } catch (Exception e) {
176             // comment
177         } catch (Throwable e) {
178         } finally {
179             // comment
180         }
181 
182         do {
183         } while (true);
184     }
185 
186     public void codeAfterLastRightCurly() {
187         while (new Object().equals(new Object())) {
188         };
189         for (int i = 0; i < 1; i++) { new Object(); };
190     }
191 
192     static final java.util.concurrent.ThreadFactory threadFactory
193             = new java.util.concurrent.ThreadFactory() {
194         @Override
195         public Thread newThread(final Runnable r) {
196             return new Thread(r);
197         }}; // violation ''}' at column 9 should be alone on a line'
198 
199     interface Interface1
200     {
201         int i = 1;
202         public void meth1(); } // violation ''}' at column 30 should be alone on a line'
203 
204     interface Interface2
205     { int i = 1; public void meth1(); } // violation ''}' at column 39 should be alone on a line'
206 
207     interface Interface3 {
208         void display();
209         interface Interface4 {
210             void myMethod();
211         }} // 2 violations
212 }