View Javadoc
1   /*
2   CommentsIndentation
3   tokens = (default)SINGLE_LINE_COMMENT, BLOCK_COMMENT_BEGIN
4   
5   
6   */
7   
8   package com.puppycrawl.tools.checkstyle.checks.indentation.commentsindentation;
9   
10  
11  
12  
13  /**
14   * Contains examples of using comments at the end of the block.
15   */
16  public class InputCommentsIndentationCommentIsAtTheEndOfBlockTwo {
17  
18      public void foo18() {
19          String
20              .valueOf(new Integer(0))
21              .trim()
22                               //violation '.* incorrect .* level 29, expected is 12,.*as line 23.'
23              .length();
24      }
25  
26      public void foo19() {
27          (new Thread(new Runnable() {
28              @Override
29              public void run() {
30  
31              }
32          })).
33                  run();
34          // comment
35      }
36  
37      public void foo20() {
38          (new Thread(new Runnable() {
39              @Override
40              public void run() {
41  
42              }
43          })).
44              run();
45                            //violation '.* incorrect .* level 26, expected is 8, .* as line 38.'
46      }
47  
48      public void foo21() {
49          int[] array = new int[5];
50  
51          java.util.List<String> expected = new java.util.ArrayList<>();
52          for (int i = 0; i < 5; i++) {
53              org.junit.Assert.assertEquals(expected.get(i), array[i]);
54          }
55          String s = String.format(java.util.Locale.ENGLISH, "The array element "
56                          + "immediately following the end of the collection should be nulled",
57                  array[1]);
58          // the above example was taken from hibernate-orm and was modified a bit
59      }
60  
61      public void foo22() {
62          int[] array = new int[5];
63  
64          java.util.List<String> expected = new java.util.ArrayList<>();
65          for (int i = 0; i < 5; i++) {
66              org.junit.Assert.assertEquals(expected.get(i), array[i]);
67          }
68          String s = String.format(java.util.Locale.ENGLISH, "The array element "
69                          + "immediately following the end of the collection should be nulled",
70                  array[1]);
71                                   //violation '.*incorrect.*level 33, expected is 8,.*as line 68.'
72      }
73  
74      public void foo23() {
75          new Object();
76          // comment
77      }
78  
79      public void foo24() {
80          new Object();
81                       //violation '.* incorrect .* level 21, expected is 8,.* same .* as line 80.'
82      }
83  
84      public String foo25() {
85          return String.format(java.util.Locale.ENGLISH, "%d",
86                  1);
87          // comment
88      }
89  
90      public String foo26() {
91          return String.format(java.util.Locale.ENGLISH, "%d",
92                  1);
93                                    //violation '.*incorrect.*level 34, expected is 8,.*as line 91.'
94      }
95  
96      public void foo27() {
97          // comment
98          // block
99          new InputCommentsIndentationCommentIsAtTheEndOfBlockOne().foo17();
100 
101         // OOOO
102     }
103 
104     public String foo28() {
105         int a = 5;
106         return String.format(java.util.Locale.ENGLISH, "%d",
107                 1);
108         // comment
109     }
110 
111     public String foo29() {
112         int a = 5;
113         return String.format(java.util.Locale.ENGLISH, "%d",
114             1);
115                           //violation '.* incorrect .* level 26, expected is 8, .* as line 113.'
116     }
117 
118 
119 }