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 class InputLeftCurlyTestDefault3 17 { // violation ''{' at column 1 should be on the previous line' 18 /** @see test method **/ 19 int foo() throws InterruptedException 20 { // violation ''{' at column 5 should be on the previous line' 21 int x = 1; 22 int a = 2; 23 while (true) 24 { // violation ''{' at column 9 should be on the previous line' 25 try 26 { // violation ''{' at column 13 should be on the previous line' 27 if (x > 0) 28 { // violation ''{' at column 17 should be on the previous line' 29 break; 30 } 31 else if (x < 0) { 32 ; 33 } 34 else 35 { // violation ''{' at column 17 should be on the previous line' 36 break; 37 } 38 switch (a) 39 { // violation ''{' at column 17 should be on the previous line' 40 case 0: 41 break; 42 default: 43 break; 44 } 45 } 46 catch (Exception e) 47 { // violation ''{' at column 13 should be on the previous line' 48 break; 49 } 50 finally 51 { // violation ''{' at column 13 should be on the previous line' 52 break; 53 } 54 } 55 56 synchronized (this) 57 { // violation ''{' at column 9 should be on the previous line' 58 do 59 { // violation ''{' at column 13 should be on the previous line' 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 { // violation ''{' at column 9 should be on the previous line' 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 { // violation ''{' at column 5 should be on the previous line' 82 int x = 1; // should not require any javadoc 83 } 84 85 86 87 public enum GreetingsEnum 88 { // violation ''{' at column 5 should be on the previous line' 89 HELLO, 90 GOODBYE 91 }; 92 93 void method2() 94 { // violation ''{' at column 5 should be on the previous line' 95 boolean flag = true; 96 if (flag) { 97 System.identityHashCode("heh"); 98 flag = !flag; } String.CASE_INSENSITIVE_ORDER. 99 equals("Xe-xe"); 100 101 // violation below ''{' at column 19 should have line break after' 102 if (flag) { String.CASE_INSENSITIVE_ORDER.equals("it is ok."); } 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 FooCtor 111 { // violation ''{' at column 1 should be on the previous line' 112 int i; 113 public FooCtor() 114 { // violation ''{' at column 5 should be on the previous line' 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 FooMethod 123 { // violation ''{' at column 1 should be on the previous line' 124 public void fooMethod() 125 { // violation ''{' at column 5 should be on the previous line' 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 FooInner 134 { // violation ''{' at column 1 should be on the previous line' 135 class InnerFoo 136 { // violation ''{' at column 5 should be on the previous line' 137 public void fooInnerMethod () 138 { // violation ''{' at column 9 should be on the previous line' 139 140 } 141 }} 142 143 /** 144 * False positive 145 * 146 */ 147 class Absent_CustomFieldSerializer3 { 148 149 public static void serialize() {} // Expected nothing but was "'}' should be alone on a line." 150 } 151 152 class Absent_CustomFieldSerializer4 153 { // violation ''{' at column 1 should be on the previous line' 154 public Absent_CustomFieldSerializer4() {} 155 } 156 157 class EmptyClass2 {} 158 159 interface EmptyInterface3 {} 160 161 class ClassWithStaticInitializers 162 { // violation ''{' at column 1 should be on the previous line' 163 static { 164 } 165 static 166 {} 167 168 static class Inner 169 { // violation ''{' at column 5 should be on the previous line' 170 static { 171 int i = 1; 172 } 173 } 174 175 }