1 package com.google.checkstyle.test.chapter4formatting.rule412nonemptyblocks; 2 3 /** some javadoc. */ 4 public class InputTryCatchIfElse { 5 6 @interface TesterAnnotation {} //ok 7 8 void foo() throws Exception { 9 int a = 90; 10 boolean test = true; 11 12 if (a == 1) { 13 } else {} 14 15 if (a == 1) { 16 } else { } 17 // violation above 'Empty blocks should have no spaces.' 18 19 if (a == 45) {} 20 21 if (a == 9) {} else {} 22 23 if (a == 99) { 24 System.out.println("test"); 25 // violation below ''}' at column 5 should be on the same line as .* multi-block statement' 26 } 27 else { 28 System.out.println("before"); 29 } 30 31 try (MyResource r = new MyResource()) { } 32 // violation above 'Empty blocks should have no spaces.' 33 34 try (MyResource r = new MyResource()) {} 35 36 try (MyResource r = new MyResource()) {} catch (Exception expected) {} 37 // 2 violations above: 38 // 'WhitespaceAround: '{' is not followed by whitespace.' 39 // ''}' at column 74 should be alone on a line.' 40 41 try (MyResource r = new MyResource()) {} catch (Exception expected) { } 42 // 3 violations above: 43 // 'Empty blocks should have no spaces.' 44 // 'WhitespaceAround: '{' is not followed by whitespace.' 45 // ''}' at column 75 should be alone on a line.' 46 47 try (MyResource r = new MyResource()) { 48 } catch (Exception expected) {} 49 // violation above ''}' at column 35 should be alone on a line.' 50 51 try (MyResource r = new MyResource()) { 52 } catch (Exception expected) { } 53 // 2 violations above: 54 // 'Empty blocks should have no spaces.' 55 // ''}' at column 36 should be alone on a line.' 56 57 try (MyResource r = new MyResource()) { ; } 58 // violation above ''{' at column 43 should have line break after.' 59 60 try { 61 /* foo */ 62 // violation below ''}' at column 35 should be alone on a line.' 63 } catch (Exception expected) {} 64 65 try { 66 /* foo */ 67 // violation below ''}' at column 5 should be on the same line as .* multi-block statement' 68 } 69 catch (NullPointerException e) { 70 /* foo */ 71 // violation below ''}' at column 5 should be on the same line as .* multi-block statement' 72 } 73 catch (Exception e) { 74 /* foo */ 75 // violation below ''}' at column 5 should be on the same line as .* multi-block statement' 76 } 77 finally { 78 test = true; 79 } 80 81 try { 82 /* foo */ 83 } catch (NullPointerException e) { 84 /* foo */ 85 // violation below ''}' at column 5 should be on the same line as .* multi-block statement' 86 } 87 catch (Exception e) { 88 /* foo */ 89 // violation below ''}' at column 5 should be on the same line as .* multi-block statement' 90 } 91 finally { 92 test = true; 93 } 94 95 try { 96 /* foo */ 97 // violation below ''}' at column 5 should be on the same line as .* multi-block statement' 98 } 99 catch (Exception e) { 100 /* foo */ 101 // violation below ''}' at column 5 should be on the same line as .* multi-block statement' 102 } 103 finally { 104 test = true; 105 } 106 107 try { 108 /* foo */ 109 } catch (Exception e) { 110 /* foo */ 111 // violation below ''}' at column 5 should be on the same line as .* multi-block statement' 112 } 113 finally { 114 test = true; 115 } 116 } 117 118 /** some javadoc. */ 119 public class MyResource implements AutoCloseable { 120 /** some javadoc. */ 121 @Override 122 public void close() throws Exception { 123 System.out.println("Closed MyResource"); 124 } 125 } 126 }