View Javadoc
1   /*
2   RightCurly
3   option = \tALONE
4   tokens = LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, \
5            CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, \
6            STATIC_INIT, INSTANCE_INIT, ANNOTATION_DEF, ENUM_DEF
7   
8   
9   */
10  
11  package com.puppycrawl.tools.checkstyle.checks.blocks.rightcurly;
12  
13  class InputRightCurlyTestWithAnnotations
14  {
15  
16      @Deprecated
17      @Override
18      public boolean equals(Object other) { boolean flag = true; return flag; }
19      // violation above ''}' at column 77 should be alone on a line'
20      @Override
21      public String toString() { String s = "toString"; return s; }
22      // violation above ''}' at column 65 should be alone on a line'
23      @Override
24      @SuppressWarnings("unused")
25      public int hashCode()
26      {
27          int a = 10;
28          return 1;
29      }
30  
31      @SuppressWarnings("unused")
32      private void foo2() { int a = 9; return; }
33      // violation above ''}' at column 46 should be alone on a line'
34      @SuppressWarnings("unused")
35      private void foo3()
36      { int var1 = 5; var2 = 6; } // violation ''}' at column 31 should be alone on a line'
37  
38      @Deprecated
39      private void foo4() { return; } // violation ''}' at column 35 should be alone on a line'
40  
41      @SuppressWarnings("unused")
42      private int foo5() { return 1; } // violation ''}' at column 36 should be alone on a line'
43  
44      @SuppressWarnings("unused")
45      private String foo6() { return toString();
46      }
47      // violation below ''}' at column 73 should be alone on a line'
48      private String foo7() { String s = toString(); return s.toString(); }
49  
50      private void foo8() { ; return; } // violation ''}' at column 37 should be alone on a line'
51  
52      private int var1; private int v1;
53      private int var2; private int v2;
54      @SuppressWarnings("unused")
55      public InputRightCurlyTestWithAnnotations() { this.var1 = 1; }
56      // violation above ''}' at column 66 should be alone on a line'
57      @SuppressWarnings("unused")
58      public InputRightCurlyTestWithAnnotations(int v1, int v2) {this.var1 = v1; this.var2 = v2; }
59      // violation above ''}' at column 96 should be alone on a line'
60      @SuppressWarnings("unused")
61      private void foo9() { ;; } // violation ''}' at column 30 should be alone on a line'
62  
63      @SuppressWarnings("unused")
64      private void foo10() { ; } // violation ''}' at column 30 should be alone on a line'
65  
66      @SuppressWarnings("unused")
67      private void foo11() {  } // violation ''}' at column 29 should be alone on a line'
68  
69      @SuppressWarnings("unused")
70      private void foo12() {
71          try { int i = 5; int b = 10; } // violation ''}' at column 38 should be alone on a line'
72          catch (Exception e) { } // violation ''}' at column 31 should be alone on a line'
73      }
74  
75      @Deprecated
76      @SuppressWarnings("unused")
77      private void foo13() {
78          for (int i = 0; i < 10; i++) { int a = 5; int b = 6; }
79          // violation above ''}' at column 62 should be alone on a line'
80          do
81          {
82              var1 = 2;
83          }
84          while (var2 == 2);
85      }
86  
87      static { int a; int b; } // violation ''}' at column 28 should be alone on a line'
88  
89      static { int a; } // violation ''}' at column 21 should be alone on a line'
90  
91      { int c; int d;} // violation ''}' at column 20 should be alone on a line'
92  
93      { int c; } // violation ''}' at column 14 should be alone on a line'
94  
95      @Deprecated
96      private void foo14() {
97          if (var1 > 0) {
98              return;
99          }
100     }
101 
102     @Deprecated
103     private void foo15() {
104         class A { int a; } var1++; // violation ''}' at column 26 should be alone on a line'
105         class B {  } // violation ''}' at column 20 should be alone on a line'
106         if(true) {
107 
108         }
109         else;
110     }
111 
112     @Deprecated
113     private void foo16() {
114         if (true) { return; } else { } // 2 violations
115         if (false) {
116         }
117 
118         if (true) { return; } else { } // 2 violations
119     }
120 
121     @Deprecated
122     void foo17() { int v1 = 5; v2 = 6; } @Deprecated void foo18() {int v1 = 5; v2 = 6; }
123     // 2 violations above
124     private void foo19() {int var1 = 5;
125         var2 = 6;} // violation ''}' at column 18 should be alone on a line'
126 
127     @SuppressWarnings("Hello, world!")
128     private String foo20() {
129         do { var2 ++; } // violation ''}' at column 23 should be alone on a line'
130         while (var2 < 15);
131 
132         while (var1 < 10) { var1++; } // violation ''}' at column 37 should be alone on a line'
133         // violation below ''}' at column 30 should be alone on a line'
134         do { var2++; var1++; } while (var2 < 15); return ""+0xCAFEBABE;
135     }
136 
137     private void foo21() { // violation below ''}' at column 77 should be alone on a line'
138         new Object() { @Override protected void finalize() { "".toString(); }};
139     }
140 
141     @SuppressWarnings("All")
142     void foo22() {
143         long startTime = System.nanoTime();
144         try {
145             int a = 5;
146             toString();
147         } catch (Exception e) { // violation ''}' at column 9 should be alone on a line'
148             throw new RuntimeException(e);
149         } finally { toString(); } // 2 violations
150     }
151 
152     @SuppressWarnings("")
153     void doDoubleBraceInitialization() {
154         java.util.Map<String, String> map = new java.util.LinkedHashMap<String, String>() {{
155             put("Hello", "World");
156             put("first", "second");
157             put("polygene", "lubricants");
158             put("alpha", "betical");
159         }}; //NO violation
160         // violation below ''}' at col.* 75 should be alone on a line'
161         Thread t = new Thread() {@Override public void run() {super.run();}};
162         new Object() { public int hashCode() { return 1; }  { int a = 5; }}; // 2 violations
163         new Object() { public int hashCode() { return 1; }  int b = 10; };
164         // violation above ''}' at column 58 should be alone on a line'
165         new Object() { public int hashCode() { return 1; } { int c = 5; } int d = 8; };
166         // 2 violations above
167         java.util.Map<String, String> map2 = new java.util.LinkedHashMap<String, String>() {{
168             put("Hello", "World");
169             put("first", "second");
170             put("polygene", "lubricants");
171             put("alpha", "betical");}  // violation ''}' at column 37 should be alone on a line'
172         };
173 
174         java.util.Map<String, String> map3 = new java.util.LinkedHashMap<String, String>() {{
175             put("Hello", "World");
176             put("first", "second");
177             put("polygene", "lubricants");
178             put("alpha", "betical");}};  // violation ''}' at column 37 should be alone on a line'
179 
180         java.util.Map<String, String> map4 = new java.util.LinkedHashMap<String, String>() {{
181             put("Hello", "World");
182             put("first", "second");
183             put("polygene", "lubricants");
184             put("alpha", "betical");
185             }
186         };
187 
188         foo23(new java.util.HashSet<String>() {{
189             add("XZ13s");
190             add("AB21/X");
191             add("YYLEX");
192             add("AR5E");
193         }}); // violation ''}' at column 9 should be alone on a line'
194 
195         foo23(new java.util.HashSet<String>() {{
196             add("XZ13s");
197             add("AB21/X");
198             add("YYLEX");
199             add("AR5E");
200         }});} // 2 violations
201 
202     void foo23(java.util.HashSet<String> set) {
203     }
204 
205     void foo25() {
206         for (int i = 0; i < 10; i++) {
207             System.identityHashCode("Hello, world!");
208         }} // 2 violations
209 
210     void foo26() {
211         for (int i = 0; i < 10; i++) {
212             System.identityHashCode("Hello, world!");}} // 2 violations
213 
214     void foo27() {
215         for (int i = 0; i < 10; i++) {for (int j = 0; j < 15; j++) {int a;}}} // 3 violations
216 
217     private java.util.ArrayList<Integer> foo28(int delta) {
218         return new java.util.ArrayList<Integer>() {
219         @Override public int size() { return Math.max(0, super.size() + 1);};
220         }; // violation above ''}' at column 76 should be alone on a line'
221     }
222 
223     private void foo29() {
224         boolean flag = true;
225         if (flag) {
226             System.identityHashCode("heh");
227             flag = !flag; } String. // violation ''}' at column 27 should be alone on a line'
228                 CASE_INSENSITIVE_ORDER.equals("Xe-xe");
229     }
230 
231     public void testMethod() {}; // violation ''}' at column 31 should be alone on a line'
232 
233     public void testMethod1() {
234     }; // violation ''}' at column 5 should be alone on a line'
235 
236     public class TestClass {}; // violation ''}' at column 29 should be alone on a line'
237 
238     public class TestClass1 {
239     }; // violation ''}' at column 5 should be alone on a line'
240 
241     public class TestClass2 {
242         public TestClass2() {}; // violation ''}' at column 30 should be alone on a line'
243 
244         public TestClass2(String someValue) {
245         }; // violation ''}' at column 9 should be alone on a line'
246     }
247 
248     public @interface TestAnnotation {} // violation ''}' at column 39 should be alone on a line'
249     // violation below ''}' at column 56 should be alone on a line'
250     public @interface TestAnnotation1{ String value(); }
251 
252     public @interface TestAnnotation2 {
253         String value();} // violation ''}' at column 24 should be alone on a line'
254 
255     public @interface TestAnnotation3 {
256         String value();
257     }
258 
259     public @interface TestAnnottation4 { String value();
260     }
261 
262     public @interface TestAnnnotation5 {
263         String someValue(); }; // violation ''}' at column 29 should be alone on a line'
264 
265     public @interface TestAnnotation6 {}; // violation ''}' at column 40 should be alone on a line'
266 
267     public @interface TestAnnotation7 {
268         String someValue();
269     }; // violation ''}' at column 5 should be alone on a line'
270 
271     public @interface TestAnnotation8 { String someValue();
272     }; // violation ''}' at column 5 should be alone on a line'
273 
274     public @interface TestAnnotation9 { String someValue(); };
275     // violation above ''}' at column 61 should be alone on a line'
276 }