View Javadoc
1   /*
2   RightCurly
3   option = ALONE
4   tokens = LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, \
5            LITERAL_FOR, LITERAL_WHILE, LITERAL_DO
6   
7   
8   */
9   
10  package com.puppycrawl.tools.checkstyle.checks.blocks.rightcurly;
11  
12  class InputRightCurlyLeftTestAlone
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                  }
27                  else if (x < 0) {
28                      ;
29                  }
30                  else
31                  {
32                      break;
33                  }
34                  switch (a)
35                  {
36                  case 0:
37                      break;
38                  default:
39                      break;
40                  }
41              }
42              catch (Exception e)
43              {
44                  break;
45              }
46              finally
47              {
48                  break;
49              }
50          }
51  
52          synchronized (this)
53          {
54              do
55              {
56                  x = 2;
57              } while (x == 2); // violation ''}' at column 13 should be alone on a line'
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      };
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 be alone on a line'
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.valueOf(""); } // violation ''}' at column 41 should be alone on a line'
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 FooCtorTestAlone
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 FooMethodTestAlone
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 FooInnerTestAlone
130 {
131         class InnerFoo
132     {
133                 public void fooInnerMethod ()
134         {
135 
136                 }
137     }}
138 
139 /**
140  * False positive
141  *
142  */
143 class Absent_CustomFieldSerializer3TestAlone {
144 
145     public static void serialize() {}
146 }
147 
148 class Absent_CustomFieldSerializer4TestAlone
149 {
150     public void Absent_CustomFieldSerializer4() {}
151 }
152 
153 class EmptyClass2TestAlone {}
154 
155 interface EmptyInterface3TestAlone {}
156 
157 class ClassWithStaticInitializersTestAlone
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) { // violation ''}' at column 9 should be alone on a line'
175             new Object();
176         } catch (Exception e) { // violation ''}' at column 9 should be alone on a line'
177             // comment
178         } catch (Throwable e) { // violation ''}' at column 9 should be alone on a line'
179         } finally { // violation ''}' at column 9 should be alone on a line'
180             // comment
181         }
182 
183         do {
184         } while (true); // violation ''}' at column 9 should be alone on a line'
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++) { new Object(); };
191         // violation above ''}' at column 53 should be alone on a line'
192     }
193 
194     static final java.util.concurrent.ThreadFactory threadFactory
195             = new java.util.concurrent.ThreadFactory() {
196         @Override
197         public Thread newThread(final Runnable r) {
198             return new Thread(r);
199         }};
200 
201     interface Interface1
202     {
203         int i = 1;
204         public void meth1(); }
205 
206     interface Interface2
207     { int i = 1; public void meth1(); }
208 
209     interface Interface3 {
210         void display();
211         interface Interface4 {
212             void myMethod();
213         }}
214 }