View Javadoc
1   // comment
2   
3   package com.google.checkstyle.test.chapter4formatting.rule4861blockcommentstyle;
4   
5   import java.util.Arrays;
6   
7   // some
8   /** some javadoc. */
9   public class InputCommentsIndentationSurroundingCode {
10    private void foo1() {
11      if (true) {
12        // here initialize some variables
13        int k = 0; // trailing comment
14          // odd indentation comment
15        // violation above '.* indentation should be the same level as line 16.'
16        int b = 10;
17        // sss
18      }
19    }
20  
21    private void foo2() {
22      if (true) {
23        /* some */
24        int k = 0;
25            /* // odd indentation comment
26             */
27        // violation 2 lines above '.* indentation should be the same level as line 28.'
28        int b = 10;
29            /* // odd indentation comment
30             * */
31        // violation 2 lines above '.* indentation should be the same level as line 32.'
32        double d; /* trailing comment */
33             /* // odd indentation comment
34         *
35         */
36        // violation 3 lines above '.* indentation should be the same level as line 37.'
37        boolean bb;
38        /* my comment*/
39        /*
40         *
41         *
42         *  some
43         */
44        /*
45         * comment
46         */
47        boolean x;
48      }
49    }
50  
51    private void foo3() {
52      int a = 5;
53      int b = 3;
54      int v = 6;
55      if (a == b && v == b
56              || (a == 1
57                  /// // odd indentation comment
58            /* // odd indentation comment
59             * one fine day ... */
60              // violation 3 lines above '.* indentation should.* as line 62.'
61              // violation 3 lines above '.* indentation should.* as line 62.'
62              && b == 1)) { /* foo */ }
63    }
64  
65    private static void com() {
66      /* here's my weird trailing comment */ boolean b = true;
67    }
68  
69    private static final String[][] mergeMatrix = {
70            // This example of trailing block comments was found in PMD sources.
71            /* TOP */ {
72            "",
73      },
74            /* ALWAYS */ {
75            "", "",
76      },
77            /* NEVER */ {
78            "NEVER", "UNKNOWN", "NEVER",
79      },
80            /* UNKNOWN */ {"UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN"},
81    };
82  
83    private void foo4() {
84      if (!Arrays.equals(new String[] {""}, new String[] {""})/* wierd comment */) { /* foo */ }
85    }
86  
87    /** some javadoc. */
88    private static void testing() {}
89  
90    /** some javadoc. */
91    public void foid5() {
92      String s = "";
93      s.toString().toString().toString();
94      // comment
95    }
96  
97    /** some javadoc. */
98    public void foo6() {
99      // comment
100     // ...
101     // block
102     // ...
103           // odd indentation comment
104     // violation above '.* indentation should be the same level as line 105.'
105     String someStr = new String();
106   }
107 
108   /** some javadoc. */
109   public void foo7() {
110     // comment
111     // ...
112     // block
113         // odd indentation comment
114     // comment
115     // violation 2 lines above'.* indentation should be the same level as line 116.'
116     String someStr = new String();
117   }
118 
119   /** some javadoc. */
120   public void foo8() {
121     String s = new String(); // comment
122     // ...
123     // block
124     // ...
125             // odd indentation comment
126     // violation above '.* indentation should be the same level as line 127.'
127     String someStr = new String();
128   }
129 
130   /** some javadoc. */
131   public String foo9(String s1, String s2, String s3) {
132     return "";
133   }
134 
135   /** some javadoc. */
136   public void foo10() throws Exception {
137 
138     final String pattern = "^foo$";
139 
140     final String[] expected = {
141         "7:13: " + foo9("", "", ""),
142         // comment
143     };
144   }
145 } // The Check should not throw NPE here!
146 // The Check should not throw NPE here!