View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   //
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ///////////////////////////////////////////////////////////////////////////////////////////////
19  // violation below ''package' should be separated from previous line.'
20  package com.google.checkstyle.test.chapter3filestructure.rule3sourcefile;
21  import java.util.concurrent.Callable; // violation ''import' should be separated from previous line.'
22  class InputSourceFileStructure { // violation ''CLASS_DEF' should be separated from previous line.'
23    public static final double FOO_PI = 3.1415;
24    private boolean flag = true;
25    static { // violation ''STATIC_INIT' should be separated from previous line.'
26      // empty static initializer
27    }
28  
29    {
30      // empty instance initializer
31    }
32  
33    /** Some javadoc... */
34    private InputSourceFileStructure() {
35      // empty
36    }
37  
38    public int compareTo(InputSourceFileStructure obj) {
39      int number = 0;
40      return 0;
41    }
42    /**
43     * Some javadoc...
44     *
45     * @param task some description....
46     * @param result some description....
47     * @return some description....
48     */
49    public static <T> Callable<T> callable(Runnable task, T result) {
50      // violation above ''METHOD_DEF' should be separated from previous line.'
51      return null;
52    }
53  
54    public int getBeastNumber() {
55      return 666;
56    }
57    interface IntEnum {
58      // violation above ''INTERFACE_DEF' should be separated from previous line.'
59    }
60  
61    class InnerClass {
62  
63      public static final double FOO_PI_INNER = 3.1415;
64      private boolean flagInner = true;
65      { // violation ''INSTANCE_INIT' should be separated from previous line.'
66        // empty instance initializer
67      }
68  
69      private InnerClass() {
70        // empty
71      }
72    }
73  
74    class InnerClass2 { // ok
75      private InnerClass2() { // ok
76        // empty
77      }
78    }
79  
80    class InnerClass3 { // ok
81      public int compareTo(InputSourceFileStructure obj) { // ok
82        int number = 0;
83        return 0;
84      }
85    }
86  }
87  
88  // violation below 'Top-level class Class1 has to reside in its own source file.'
89  class Class1 { // ok
90    private Class1() {} // ok
91  }
92  class Class2 {
93    // 2 violations above:
94    //  'Top-level class Class2 has to reside in its own source file.'
95    //  'CLASS_DEF' should be separated from previous line.'
96    public int compareTo(InputSourceFileStructure obj) { // ok
97      int number = 0;
98      return 0;
99    }
100   Class2 anon = // violation ''VARIABLE_DEF' should be separated from previous line.'
101           new Class2() {
102             public int compareTo(InputSourceFileStructure obj) { // ok
103               int number = 0;
104               return 0;
105             }
106           };
107 }