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