KickJava   Java API By Example, From Geeks To Geeks.

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


1 ////////////////////////////////////////////////////////////////////////////////
2
// Test case file for checkstyle.
3
// Created: 2003
4
////////////////////////////////////////////////////////////////////////////////
5
package com.puppycrawl.tools.checkstyle;
6
7 import javax.swing.AbstractAction JavaDoc;
8 import javax.swing.Action JavaDoc;
9 import java.awt.event.ActionEvent JavaDoc;
10
11 /**
12  * Test case for detecting missing final parameters.
13  * @author Lars Kühne
14  **/

15 class InputFinalParameters
16 {
17     /** no param constructor */
18     InputFinalParameters()
19     {
20     }
21
22     /** non final param constructor */
23     InputFinalParameters(String JavaDoc s)
24     {
25     }
26
27     /** non final param constructor */
28     InputFinalParameters(final Integer JavaDoc i)
29     {
30     }
31
32     /** final param constructor with annotation */
33     InputFinalParameters(final @MyAnnotation3 Class JavaDoc i)
34     {
35     }
36
37     /** non-final param constructor with annotation*/
38     InputFinalParameters(@MyAnnotation3 Boolean JavaDoc i)
39     {
40     }
41
42     /** mixed */
43     InputFinalParameters(String JavaDoc s, final Integer JavaDoc i)
44     {
45     }
46
47     /** no param method */
48     void method()
49     {
50     }
51
52     /** non final param method */
53     void method(String JavaDoc s)
54     {
55     }
56
57     /** final param method */
58     void method(final Integer JavaDoc i)
59     {
60     }
61
62     /** final param method with annotation **/
63     void method(@MyAnnotation3 final Object JavaDoc s)
64     {
65
66     }
67
68     /** non-final param method with annotation **/
69     void method(@MyAnnotation3 Class JavaDoc s)
70     {
71
72     }
73
74     /** mixed */
75     void method(String JavaDoc s, final Integer JavaDoc i)
76     {
77     }
78
79     /** interface methods should not be flagged. */
80     interface TestInterface
81     {
82         void method(String JavaDoc s);
83     }
84
85     /** methods in anonymous inner classes */
86     void holder()
87     {
88         Action JavaDoc a = new AbstractAction JavaDoc()
89             {
90                 public void actionPerformed(ActionEvent JavaDoc e)
91                 {
92                 }
93                 void somethingElse(@MyAnnotation3 ActionEvent JavaDoc e)
94                 {
95                 }
96             };
97
98         Action JavaDoc b = new AbstractAction JavaDoc()
99             {
100                 public void actionPerformed(final ActionEvent JavaDoc e)
101                 {
102                 }
103                 void somethingElse(@MyAnnotation3 final ActionEvent JavaDoc e)
104                 {
105                 }
106             };
107     }
108
109     /** methods with complicated types of the parameters. */
110     void methodA(java.lang.String JavaDoc aParam) {
111     }
112
113     void methodB(String JavaDoc[] args) {
114     }
115
116     void methodC(java.lang.String JavaDoc[] args) {
117     }
118
119     /** some catch blocks */
120     void method1()
121     {
122         try {
123             System.err.println("");
124         }
125         catch (java.lang.NullPointerException JavaDoc npe) {
126             npe.printStackTrace();
127         }
128         catch (@MyAnnotation3 final ClassCastException JavaDoc e) {
129             e.printStackTrace();
130         }
131         catch (RuntimeException JavaDoc e) {
132             e.printStackTrace();
133         }
134         catch (@MyAnnotation3 NoClassDefFoundError JavaDoc e) {
135             e.printStackTrace();
136         }
137     }
138 }
139
140 abstract class AbstractClass
141 {
142     public abstract void abstractMethod(int aParam);
143 }
144
145 class Foo
146 {
147     /* Some for-each clauses */
148     public void Bar()
149     {
150         for(String JavaDoc s : someExpression())
151         {
152
153         }
154         for(final String JavaDoc s : someExpression())
155         {
156
157         }
158         for(@MyAnnotation3 String JavaDoc s : someExpression())
159         {
160
161         }
162         for(@MyAnnotation3 final String JavaDoc s : someExpression())
163         {
164
165         }
166     }
167
168     private String JavaDoc[] someExpression()
169     {
170         return null;
171     }
172 }
173
174 @interface MyAnnotation3 {
175 }
176
Popular Tags