KickJava   Java API By Example, From Geeks To Geeks.

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


1 ////////////////////////////////////////////////////////////////////////////////
2
// Test case file for checkstyle.
3
// Created: 2001
4
////////////////////////////////////////////////////////////////////////////////
5

6 package com.puppycrawl.tools.checkstyle;
7
8 /**
9  * Test case for Modifier checks:
10  * - order of modifiers
11  * - use of 'public' in interface definition
12  * @author lkuehne
13  */

14 strictfp final class InputModifier // illegal order of modifiers for class
15
{
16
17     /** Illegal order of modifiers for variables */
18     static private boolean sModifierOrderVar = false;
19
20     /**
21      * Illegal order of modifiers for methods. Make sure that the
22      * first and last modifier from the JLS sequence is used.
23      */

24     strictfp private void doStuff()
25     {
26     }
27
28     /** Single annotation without other modifiers */
29     @MyAnnotation2 void someMethod()
30     {
31     }
32
33     /** Illegal order of annotation - must come first */
34     private @MyAnnotation2 void someMethod2()
35     {
36     }
37
38     /** Annotation in middle of other modifiers otherwise in correct order */
39     private @MyAnnotation2 strictfp void someMethod3()
40     {
41     }
42
43     /** Correct order */
44     @MyAnnotation2 private strictfp void someMethod4()
45     {
46     }
47
48     /** Annotation in middle of other modifiers otherwise in correct order */
49     @MyAnnotation2 private static @MyAnnotation4 strictfp void someMethod5()
50     {
51     }
52
53     /** holder for redundant 'public' modifier check. */
54     public interface InputRedundantPublicModifier
55     {
56         /** redundant 'public' modifier */
57         public void a();
58
59         /** all OK */
60         void b();
61
62         /** redundant abstract modifier */
63         abstract void c();
64
65         /** redundant 'public' modifier */
66         public float PI_PUBLIC = (float) 3.14;
67
68         /** redundant 'abstract' modifier (field can not be absract)*/
69 // abstract float PI_ABSTRACT = (float) 3.14;
70

71         /** redundant 'final' modifier */
72         final float PI_FINAL = (float) 3.14;
73
74         /** all OK */
75         float PI_OK = (float) 3.14;
76     }
77
78     /** redundant 'final' modifier */
79     private final void method()
80     {
81     }
82 }
83
84 /** Holder for redundant 'final' check. */
85 final class RedundantFinalClass
86 {
87     /** redundant 'final' modifier */
88     public final void finalMethod()
89     {
90     }
91
92     /** OK */
93     public void method()
94     {
95     }
96 }
97
98 /** Holder for redundant modifiers of inner implementation */
99 interface InnerImplementation
100 {
101     InnerImplementation inner =
102         new InnerImplementation()
103         {
104             /** compiler requires 'public' modifier */
105             public void method()
106             {
107             }
108         };
109     
110     void method();
111 }
112
113 /** Holder for redundant modifiers of annotation fields/variables */
114 @interface Annotation
115 {
116     public String JavaDoc s1 = "";
117     final String JavaDoc s2 = "";
118     static String JavaDoc s3 = "";
119     String JavaDoc s4 = "";
120     public String JavaDoc blah();
121     abstract String JavaDoc blah2();
122 }
123
124 @interface MyAnnotation2 {
125 }
126
127 @interface MyAnnotation4 {
128 }
129
Popular Tags