View Javadoc
1   package com.google.checkstyle.test.chapter4formatting.rule4861blockcommentstyle;
2   
3   /** Contains examples of using comments at the end of the block. */
4   public class InputCommentsIndentationCommentIsAtTheEndOfBlock {
5   
6     /** some javadoc. */
7     public void foo1() {
8       foo2();
9       // OOOO: missing functionality
10    }
11  
12    /** some javadoc. */
13    public void foo2() {
14      // violation 2 lines below '.* indentation should be the same level as line 15.'
15      foo3();
16                         // odd indentation comment
17    }
18  
19    /** some javadoc. */
20    public void foo3() {
21      foo2();
22      // refreshDisplay();
23    }
24  
25    /** some javadoc. */
26    public void foo4() {
27      foooooooooooooooooooooooooooooooooooooooooo();
28      // ^-- some hint
29    }
30  
31    /** some javadoc. */
32    public void foooooooooooooooooooooooooooooooooooooooooo() {}
33  
34       /////////////////////////////// odd indentation comment
35    // violation above '.* indentation should be the same level as line 38.'
36  
37    /** some javadoc. */
38    public void foo7() {
39      // violation 2 lines below'.* indentation should be the same level as line 40.'
40      int a = 0;
41  // odd indentation comment
42    }
43  
44    /////////////////////////////// (a single-line border to separate a group of methods)
45  
46    /** some javadoc. */
47    public void foo8() {}
48  
49    /** some javadoc. */
50    public class TestClass {
51      /** some javadoc. */
52      public void test() {
53        // violation 3 lines below '.* indentation should be the same level as line 55.'
54        // violation 4 lines below'.* indentation should be the same level as line 52.'
55        int a = 0;
56           // odd indentation comment
57      }
58        // odd indentation comment
59    }
60  
61    /** some javadoc. */
62    public void foo9() {
63      // violation 2 lines below '.* indentation should be the same level as line 64.'
64      this.foo1();
65           // odd indentation comment
66    }
67  
68    //    public void foo10() {
69    //
70    //    }
71  
72    /** some javadoc. */
73    public void foo11() {
74      String.valueOf(new Integer(0)).trim().length();
75      // comment
76    }
77  
78    /** some javadoc. */
79    public void foo12() {
80      // violation 5 lines below '.* indentation should be the same level as line 81.'
81      String
82          .valueOf(new Integer(0))
83          .trim()
84          .length();
85                // odd indentation comment
86    }
87  
88    /** some javadoc. */
89    public void foo13() {
90      String.valueOf(new Integer(0)).trim().length();
91      // comment
92    }
93  
94    /** some javadoc. */
95    public void foo14() {
96      // violation 4 lines below '.* indentation should be the same level as line 97.'
97      String.valueOf(new Integer(0))
98          .trim()
99          .length();
100                            // odd indentation comment
101   }
102 
103   /** some javadoc. */
104   public void foo15() {
105     String.valueOf(new Integer(0));
106     // comment
107   }
108 
109   /** some javadoc. */
110   public void foo16() {
111     // violation 3 lines below '.* indentation should be the same level as line 112.'
112     String
113         .valueOf(new Integer(0));
114                  // odd indentation comment
115   }
116 
117   /** some javadoc. */
118   public void foo17() {
119     String.valueOf(new Integer(0))
120             .trim()
121             // comment
122             .length();
123   }
124 
125   /** some javadoc. */
126   public void foo18() {
127     // violation 4 lines below '.* indentation should be the same level as line 132.'
128     String
129         .valueOf(new Integer(0))
130         .trim()
131                          // odd indentation comment
132         .length();
133   }
134 
135   /** some javadoc. */
136   public void foo19() {
137     (new Thread(
138             new Runnable() {
139               @Override
140               public void run() {}
141             }))
142             .run();
143     // comment
144   }
145 
146   /** some javadoc. */
147   public void foo20() {
148     // violation 8 lines below '.* indentation should be the same level as line 149.'
149     (new Thread(new Runnable() {
150         @Override
151         public void run() {
152 
153         }
154     }))
155         .run();
156                       // odd indentation comment
157   }
158 
159   /** some javadoc. */
160   public void foo21() {
161     int[] array = new int[5];
162 
163     java.util.List<String> expected = new java.util.ArrayList<>();
164     for (int i = 0; i < 5; i++) {
165       org.junit.Assert.assertEquals(expected.get(i), array[i]);
166     }
167     String s =
168             String.format(
169                     java.util.Locale.ENGLISH,
170                     "The array element "
171                             + "immediately following the end of the collection should be nulled",
172                     array[1]);
173     // the above example was taken from hibernate-orm and was modified a bit
174   }
175 
176   /** some javadoc. */
177   public void foo22() {
178     int[] array = new int[5];
179 
180     java.util.List<String> expected = new java.util.ArrayList<>();
181     for (int i = 0; i < 5; i++) {
182       org.junit.Assert.assertEquals(expected.get(i), array[i]);
183     }
184     // violation 4 lines below '.* indentation should be the same level as line 185.'
185     String s = String.format(java.util.Locale.ENGLISH, "The array element "
186             + "immediately following the end of the collection should be nulled",
187         array[1]);
188                              // odd indentation comment
189   }
190 
191   /** some javadoc. */
192   public void foo23() {
193     new Object();
194     // comment
195   }
196 
197   /** some javadoc. */
198   public void foo24() {
199     // violation 2 lines below '.* indentation should be the same level as line 200.'
200     new Object();
201                  // odd indentation comment
202   }
203 
204   /** some javadoc. */
205   public String foo25() {
206     return String.format(java.util.Locale.ENGLISH, "%d", 1);
207     // comment
208   }
209 
210   /** some javadoc. */
211   public String foo26() {
212     // violation 3 lines below '.* indentation should be the same level as line 213.'
213     return String.format(java.util.Locale.ENGLISH, "%d",
214         1);
215                               // odd indentation comment
216   }
217 
218   /** some javadoc. */
219   public void foo27() {
220     // comment
221     // block
222     foo17();
223 
224     // OOOO
225   }
226 
227   /** some javadoc. */
228   public String foo28() {
229     int a = 5;
230     return String.format(java.util.Locale.ENGLISH, "%d", 1);
231     // comment
232   }
233 
234   /** some javadoc. */
235   public String foo29() {
236     int a = 5;
237     // violation 3 lines below '.* indentation should be the same level as line 238.'
238     return String.format(java.util.Locale.ENGLISH, "%d",
239         1);
240                       // odd indentation comment
241   }
242 
243   /** some javadoc. */
244   public void foo30() {
245     // comment
246     // violation 2 lines below '.* indentation should be the same level as line 247.'
247     int a = 5;
248 // odd indentation comment
249   }
250 
251   /** some javadoc. */
252   public void foo31() {
253     String s = new String("A" + "B" + "C");
254     // comment
255   }
256 
257   /** some javadoc. */
258   public void foo32() {
259     // violation 4 lines below '.* indentation should be the same level as line 260.'
260     String s = new String("A"
261         + "B"
262         + "C");
263         // odd indentation comment
264   }
265 
266   /** some javadoc. */
267   public void foo33() {
268     // comment
269     // violation 2 lines below '.* indentation should be the same level as line 270.'
270     this.foo22();
271 // odd indentation comment
272   }
273 
274   /** some javadoc. */
275   public void foo34() throws Exception {
276     throw new Exception("", new Exception());
277     // comment
278   }
279 
280   /** some javadoc. */
281   public void foo35() throws Exception {
282     // violation 4 lines below '.* indentation should be the same level as line 283.'
283     throw new Exception("",
284         new Exception()
285     );
286         // odd indentation comment
287   }
288 
289   /** some javadoc. */
290   public void foo36() throws Exception {
291     // violation 4 lines below '.* indentation should be the same level as line 292.'
292     throw new Exception("",
293         new Exception()
294     );
295 // odd indentation comment
296   }
297 
298   /** some javadoc. */
299   public void foo37() throws Exception {
300     throw new Exception("", new Exception());
301     // comment
302   }
303 
304   /** some javadoc. */
305   public void foo38() throws Exception {
306     // violation 2 lines below '.* indentation should be the same level as line 307.'
307     throw new Exception("", new Exception());
308           // odd indentation comment
309   }
310 
311   /** some javadoc. */
312   public void foo39() throws Exception {
313     // violation 3 lines below'.* indentation should be the same level as line 314.'
314     throw new Exception("",
315         new Exception());
316      // odd indentation comment
317   }
318 
319   /** some javadoc. */
320   public void foo40() throws Exception {
321     int a = 88;
322     // violation 2 lines below '.* indentation should be the same level as line 323.'
323     throw new Exception("", new Exception());
324      // odd indentation comment
325   }
326 
327   /** some javadoc. */
328   public void foo41() throws Exception {
329     int a = 88;
330     throw new Exception("", new Exception());
331     // comment
332   }
333 
334   /** some javadoc. */
335   public void foo42() {
336     int a = 5;
337     if (a == 5) {
338       int b;
339       // comment
340     } else if (a == 6) {
341       /* foo */
342     }
343   }
344 
345   /** some javadoc. */
346   public void foo43() {
347     try {
348       int a;
349       // comment
350     } catch (Exception e) {
351       /* foo */
352     }
353   }
354 
355   /** some javadoc. */
356   public void foo44() {
357     int ar = 5;
358     // comment
359     ar = 6;
360     // comment
361   }
362 
363   /** some javadoc. */
364   public void foo45() {
365     int ar = 5;
366     // comment
367     // violation 2 lines below '.* indentation should be the same level as line 368.'
368     ar = 6;
369      // odd indentation comment
370   }
371 
372   /** some javadoc. */
373   public void foo46() {
374     // violation 3 lines below '.* indentation should be the same level as line 378.'
375 // comment
376 // block
377 // odd indentation comment
378   }
379 
380   /** some javadoc. */
381   public void foo47() {
382     int a = 5;
383     // comment
384     // block
385     // comment
386   }
387 
388   /** some javadoc. */
389   public void foo48() {
390     // violation 4 lines below '.* indentation should be the same level as line 391.'
391     int a = 5;
392 // comment
393 // block
394 // odd indentation comment
395   }
396 
397   /** some javadoc. */
398   public void foo49() {
399     // comment
400     // block
401     // ok
402   }
403 
404   /** some javadoc. */
405   public void foo50() {
406     return;
407 
408     // No NPE here!
409   }
410 
411   /** some javadoc. */
412   public String foo51() {
413     // violation 4 lines below '.* indentation should be the same level as line 414.'
414     return String
415         .valueOf("11"
416         );
417      // odd indentation comment
418   }
419 
420   /** some javadoc. */
421   public String foo52() {
422     return String.valueOf("11");
423     // comment
424   }
425 
426   // We almost reached the end of the class here.
427 }
428 // The END of the class.