View Javadoc
1   /*
2   LeftCurly
3   option = nl
4   ignoreEnums = (default)true
5   tokens = (default)ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, \
6            ENUM_DEF, INTERFACE_DEF, LAMBDA, LITERAL_CASE, LITERAL_CATCH, \
7            LITERAL_DEFAULT, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, \
8            LITERAL_IF, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, \
9            METHOD_DEF, OBJBLOCK, STATIC_INIT, RECORD_DEF, COMPACT_CTOR_DEF
10  
11  
12  */
13  
14  package com.puppycrawl.tools.checkstyle.checks.blocks.leftcurly;
15  
16  class InputLeftCurlyTestNewLine3
17  {
18      /** @see test method **/
19      int foo() throws InterruptedException
20      {
21          int x = 1;
22          int a = 2;
23          while (true)
24          {
25              try
26              {
27                  if (x > 0)
28                  {
29                      break;
30                  }
31                  else if (x < 0) { // violation ''{' at column 33 should be on a new line'
32                      ;
33                  }
34                  else
35                  {
36                      break;
37                  }
38                  switch (a)
39                  {
40                  case 0:
41                      break;
42                  default:
43                      break;
44                  }
45              }
46              catch (Exception e)
47              {
48                  break;
49              }
50              finally
51              {
52                  break;
53              }
54          }
55  
56          synchronized (this)
57          {
58              do
59              {
60                  x = 2;
61              } while (x == 2);
62          }
63  
64          this.wait(666
65                   ); // Bizarre, but legal
66  
67          for (int k = 0; k < 1; k++)
68          {
69              String innerBlockVariable = "";
70          }
71  
72          // test input for bug reported by Joe Comuzzi
73          if (System.currentTimeMillis() > 1000)
74              return 1;
75          else
76              return 2;
77      }
78  
79      // Test static initialiser
80      static
81      {
82          int x = 1; // should not require any javadoc
83      }
84  
85  
86  
87      public enum GreetingsEnum
88      {
89          HELLO,
90          GOODBYE
91      };
92  
93      void method2()
94      {
95          boolean flag = true;
96          if (flag) { // violation ''{' at column 19 should be on a new line'
97              System.identityHashCode("heh");
98              flag = !flag; } String.CASE_INSENSITIVE_ORDER.
99                equals("Xe-xe");
100         // it is ok to have rcurly on the same line as previous
101         // statement if lcurly on the same line.
102         if (flag) { String.valueOf("ok"); } // violation ''{' at column 19 should be on a new line'
103     }
104 }
105 
106 /**
107  * Test input for closing brace if that brace terminates
108  * a statement or the body of a constructor.
109  */
110 class FooCtorTestNewLine3
111 {
112         int i;
113         public void FooCtor()
114     {
115                 i = 1;
116     }}
117 
118 /**
119 * Test input for closing brace if that brace terminates
120 * a statement or the body of a method.
121 */
122 class FooMethodTestNewLine3
123 {
124         public void fooMethod()
125     {
126                 int i = 1;
127     }}
128 
129 /**
130 * Test input for closing brace if that brace terminates
131 * a statement or the body of a named class.
132 */
133 class FooInnerTestNewLine3
134 {
135         class InnerFoo
136     {
137                 public void fooInnerMethod ()
138         {
139 
140                 }
141     }}
142 
143 /**
144  * False positive
145  *
146  */
147 class Absent_CustomFieldSerializer3TestNewLine3 {
148     // violation above ''{' at column 49 should be on a new line'
149     public static void serialize() {} // Expected nothing but was "'}' should be alone on a line."
150 }
151 
152 class Absent_CustomFieldSerializer4TestNewLine3
153 {
154     public void Absent_CustomFieldSerializer4() {}
155 }
156 
157 class EmptyClass2TestNewLine3 {}
158 
159 interface EmptyInterface3TestNewLine3 {}
160 
161 class ClassWithStaticInitializersTestNewLine3
162 {
163     static { // violation ''{' at column 12 should be on a new line'
164     }
165     static
166     {}
167 
168     static class Inner
169     {
170         static { // violation ''{' at column 16 should be on a new line'
171             int i = 1;
172         }
173     }
174 
175 }