View Javadoc
1   /*
2   LeftCurly
3   option = (default)EOL
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  import java.lang.annotation.ElementType;
17  import java.lang.annotation.Target;
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  class InputLeftCurlyTestLineBreakAfter
22  { // violation ''{' at column 1 should be on the previous line'
23      /** @see test method **/
24      int foo() throws InterruptedException
25      { // violation ''{' at column 5 should be on the previous line'
26          int x = 1;
27          int a = 2;
28          while (true)
29          { // violation ''{' at column 9 should be on the previous line'
30              try
31              { // violation ''{' at column 13 should be on the previous line'
32                  if (x > 0)
33                  { // violation ''{' at column 17 should be on the previous line'
34                      break;
35                  }
36                  else if (x < 0) {
37                      ;
38                  }
39                  else { break; } // violation ''{' at column 22 should have line break after'
40                  switch (a)
41                  { // violation ''{' at column 17 should be on the previous line'
42                  case 0:
43                      break;
44                  default:
45                      break;
46                  }
47              }
48              catch (Exception e) { ; } // violation ''{' at column 33 should have line break after'
49              finally { break; } // violation ''{' at column 21 should have line break after'
50          }
51  
52          synchronized (this) { do { x = 2; } while (x == 2); } // 2 violations
53  
54          synchronized (this) {
55              do {} while (x == 2);
56          }
57          // violation below ''{' at column 37 should have line break after'
58          for (int k = 0; k < 1; k++) { String innerBlockVariable = ""; }
59  
60          for (int k = 0; k < 1; k++) {}
61                  return a;
62      }
63  
64      static { int x = 1; } // violation ''{' at column 12 should have line break after'
65  
66      void method2()
67      { // violation ''{' at column 5 should be on the previous line'
68          boolean flag = false;
69          if (flag) { int k = 0; } // violation ''{' at column 19 should have line break after'
70      }
71  }
72  
73  class Absent_CustomFieldSerializer1 {
74  
75      public static void serialize() {}
76  }
77  
78  class Absent_CustomFieldSerializer2
79  { // violation ''{' at column 1 should be on the previous line'
80      public Absent_CustomFieldSerializer2() {}
81  }
82  
83  class EmptyClass1 {}
84  
85  interface EmptyInterface1 {}
86  
87  enum KnownOrder { KNOWN_ORDER, UNKNOWN_ORDER }