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 package com.google.checkstyle.test.chapter3filestructure.rule3sourcefile; 20 21 // violation 2 lines above ''package' should be separated from previous line.' 22 23 import java.util.concurrent.Callable; 24 25 class InputFormattedSourceFileStructure { 26 public static final double FOO_PI = 3.1415; 27 private boolean flag = true; 28 29 static { 30 // empty static initializer 31 } 32 33 { 34 // empty instance initializer 35 } 36 37 /** Some javadoc... */ 38 private InputFormattedSourceFileStructure() { 39 // empty 40 } 41 42 public int compareTo(InputFormattedSourceFileStructure obj) { 43 int number = 0; 44 return 0; 45 } 46 47 /** 48 * Some javadoc... 49 * 50 * @param task some description.... 51 * @param result some description.... 52 * @return some description.... 53 */ 54 public static <T> Callable<T> callable(Runnable task, T result) { 55 return null; 56 } 57 58 public int getBeastNumber() { 59 return 666; 60 } 61 62 interface IntEnum {} 63 64 class InnerClass { 65 66 public static final double FOO_PI_INNER = 3.1415; 67 private boolean flagInner = true; 68 69 { 70 // empty instance initializer 71 } 72 73 private InnerClass() { 74 // empty 75 } 76 } 77 78 class InnerClass2 { // ok 79 private InnerClass2() { // ok 80 // empty 81 } 82 } 83 84 class InnerClass3 { // ok 85 public int compareTo(InputSourceFileStructure obj) { // ok 86 int number = 0; 87 return 0; 88 } 89 } 90 } 91 92 // violation below 'Top-level class ExtraClass1 has to reside in its own source file.' 93 class ExtraClass1 { // ok 94 private ExtraClass1() {} // ok 95 } 96 97 class ExtraClass2 { 98 // violation above 'Top-level class ExtraClass2 has to reside in its own source file.' 99 public int compareTo(InputSourceFileStructure obj) { // ok 100 int number = 0; 101 return 0; 102 } 103 104 Class2 anon = 105 new Class2() { 106 public int compareTo(InputSourceFileStructure obj) { // ok 107 int number = 0; 108 return 0; 109 } 110 }; 111 }