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