KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > InputDesignForExtension


1 ////////////////////////////////////////////////////////////////////////////////
2
// Test case file for checkstyle.
3
// Created: 2001
4
////////////////////////////////////////////////////////////////////////////////
5
package com.puppycrawl.tools.checkstyle;
6
7 /**
8  * Test case for the "design for inheritance" check.
9  * @author Lars Kühne
10  **/

11 public abstract class InputDesignForExtension
12 {
13     // some methods that are OK
14

15     public interface InterfaceOK
16     {
17         void implicitlyAbstract();
18     }
19
20     final class ClassOK
21     {
22         protected void finalThroughClassDef()
23         {
24             System.out.println("no way to override");
25         }
26     }
27
28     protected void nonFinalButEmpty()
29     {
30     }
31
32     public void nonFinalButEmpty2()
33     {
34         // comments don't count as content...
35
}
36
37     private void aPrivateMethod()
38     {
39         System.out.println("no way to override");
40     }
41
42     protected abstract void nonFinalButAbstract();
43
44     // this one is bad: neither abtract, final, or empty
45

46     protected void doh()
47     {
48         System.out.println("nonempty and overriding possible");
49     }
50
51     // has a potentially complex implementation in native code.
52
// We can't check that, so to be safe DesignForExtension requires
53
// native methods to also be final
54
public native void aNativeMethod();
55
56     // tries to trigger bug #884035
57
// MyComparator is a private class, so there cannot be subclasses
58
// and it should not be neccessary to declare compare() as final
59
private class MyComparator implements java.util.Comparator JavaDoc
60     {
61         public int compare(Object JavaDoc o1, Object JavaDoc o2)
62         {
63             // some complex stuff that would normally trigger an error report
64
if (o1.hashCode() > o2.hashCode()) {
65                 return -1;
66             }
67             else {
68                 return 1;
69             }
70         }
71     }
72 }
73
74 // enums should be skipped
75
enum TEnum
76 {
77     FIRST,
78     SECOND;
79
80     public int value()
81     {
82         return 3;
83     }
84 }
85
Popular Tags