KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.puppycrawl.tools.checkstyle;
2
3 ////////////////////////////////////////////////////////////////////////////////
4
// Test case file for checkstyle.
5
// Created: 2002
6
////////////////////////////////////////////////////////////////////////////////
7

8 /**
9  * Test case for hidden fields
10  * @author Rick Giles
11  **/

12 class InputHiddenField
13 {
14     private int hidden = 0;
15     
16     public InputHiddenField()
17     {
18         int hidden = 0; //shadows field
19
}
20     
21     public InputHiddenField(int hidden) //parameter shadows field
22
{
23     }
24     
25     public void shadow()
26     {
27         int hidden = 0; //shadows field
28
}
29     
30     public void shadowFor()
31     {
32         for (int hidden = 0; hidden < 1; hidden++) { //shadows field
33
}
34     }
35     
36     public void shadowParam(int hidden) //parameter shadows field
37
{
38     }
39     
40     public class Inner
41     {
42         private int innerHidden = 0;
43         
44         public Inner()
45         {
46             int innerHidden = 0; //shadows field
47
}
48     
49         public Inner(int innerHidden) //shadows field
50
{
51         }
52         
53         private void innerShadow()
54         {
55             int innerHidden = 0; //shadows inner field
56
int hidden = 0; //shadows outer field
57
}
58         
59         private void innerShadowFor()
60         {
61             for (int innerHidden = 0; innerHidden < 1; innerHidden++) {
62             }
63             //shadows outer field
64
for (int hidden = 0; hidden < 1; hidden++) {
65             }
66         }
67         
68         private void shadowParam(
69             int innerHidden, //parameter shadows inner field
70
int hidden //parameter shadows outer field
71
)
72         {
73         }
74         
75         {
76             int innerHidden = 0;//shadows inner field
77
int hidden = 0; //shadows outer field
78
}
79     }
80
81     {
82         int hidden = 0;//shadows field
83
}
84 }
85     
86 interface NothingHidden
87 {
88     public static int notHidden = 0;
89     
90     // not an error
91
public void noShadow(int notHidden);
92 }
93
94 /** tests ignoring the parameter of a property setter method */
95 class PropertySetter
96 {
97     private int prop;
98     
99     /** setter */
100     public void setProp(int prop)
101     {
102         this.prop = prop;
103     }
104     
105     /** error - incorrect method name */
106     public void setprop(int prop)
107     {
108         this.prop = prop;
109     }
110     
111     /** error - more than one parameter */
112     public void setProp(int prop, int extra)
113     {
114         this.prop = prop;
115     }
116 }
117
118 /** tests a non-void method */
119 class PropertySetter2
120 {
121     private int prop;
122     
123     /** error - not a void method */
124     public int setProp(int prop)
125     {
126         this.prop = prop;
127         return 0;
128     }
129 }
130
131 /** tests for static fields */
132 class StaticFields
133 {
134     private static int hidden;
135     
136     public static void staticMethod()
137     {
138         int hidden;
139     }
140     
141     public void method()
142     {
143         int hidden;
144     }
145     
146     static
147     {
148         int hidden;
149     }
150     
151     {
152         int hidden;
153     }
154 }
155
156 /** tests static methods & initializers */
157 class StaticMethods
158 {
159     private int notHidden;
160     
161     public static void method()
162     {
163         // local variables of static methods don't hide instance fields.
164
int notHidden;
165     }
166     
167     static
168     {
169         // local variables of static initializers don't hide instance fields.
170
int notHidden;
171     }
172
173     private int x;
174     private static int y;
175     static class Inner {
176         void useX(int x) {
177             x++;
178         }
179         void useY(int y) {
180             y++;
181         }
182     }
183 }
184
185 enum HiddenEnum
186 {
187     A(129),
188     B(283),
189     C(1212)
190     {
191         /**
192          * Should not be flagged as error as we don't check
193          * hidden class level fields
194          */

195         int hidden;
196
197         public void doSomething()
198         {
199             //Should be flagged as hiding enum constant member
200
int hidden = 0;
201         }
202     };
203
204     int hidden;
205     static int hiddenStatic;
206
207     /**
208      * ctor parameter hides member
209      */

210     HiddenEnum(int hidden)
211     {
212     }
213
214     public void doSomething()
215     {
216         //Should be flagged as hiding static member
217
int hidden = 0;
218     }
219
220     public static void doSomethingStatic()
221     {
222         //Should be flagged as hiding static member
223
int hiddenStatic = 0;
224     }
225 }
226
227 // we should ignore this if user wants (ignoreAbstractMethods is true)
228
abstract class InputHiddenFieldBug1084512 {
229     String JavaDoc x;
230     public abstract void methodA(String JavaDoc x);
231 }
232
Popular Tags