|
1 /* |
|
2 * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 4147520 |
|
27 * @summary Verify correct implementation of qualified 'this' and 'super'. |
|
28 * @author maddox |
|
29 * |
|
30 * @run compile QualifiedThisAndSuper_3.java |
|
31 * @run main QualifiedThisAndSuper_3 |
|
32 */ |
|
33 |
|
34 class AS { |
|
35 String s = "ass"; |
|
36 private String t = "ast"; |
|
37 protected String u = "asu"; |
|
38 String m() { return "asm"; } |
|
39 private String n() { return "asn"; } |
|
40 protected String o() { return "aso"; } |
|
41 |
|
42 static String xs = "xass"; |
|
43 static private String xt = "xast"; |
|
44 static protected String xu = "xasu"; |
|
45 static String xm() { return "xasm"; } |
|
46 static private String xn() { return "xasn"; } |
|
47 static protected String xo() { return "xaso"; } |
|
48 } |
|
49 |
|
50 class BS { |
|
51 String s = "bss"; |
|
52 private String t = "bst"; |
|
53 protected String u = "bsu"; |
|
54 String m() { return "bsm"; } |
|
55 private String n() { return "bsn"; } |
|
56 protected String o() { return "bso"; } |
|
57 } |
|
58 |
|
59 class CS { |
|
60 String s = "css"; |
|
61 private String t = "cst"; |
|
62 protected String u = "csu"; |
|
63 String m() { return "csm"; } |
|
64 private String n() { return "csn"; } |
|
65 protected String o() { return "cso"; } |
|
66 } |
|
67 |
|
68 public class QualifiedThisAndSuper_3 extends AS { |
|
69 |
|
70 void check(String expr, String result, String expected) { |
|
71 if (!result.equals(expected)) { |
|
72 throw new Error("Evaluated "+ expr + |
|
73 " : result " + result + ", expected " + expected); |
|
74 } |
|
75 } |
|
76 |
|
77 |
|
78 QualifiedThisAndSuper_3() { super(); } |
|
79 String s = "as"; |
|
80 private String t = "at"; |
|
81 protected String u = "au"; |
|
82 String m() { return "am"; } |
|
83 private String n() { return "an"; } |
|
84 protected String o() { return "ao"; } |
|
85 |
|
86 static String xs = "xas"; |
|
87 static private String xt = "xat"; |
|
88 static protected String xu = "xau"; |
|
89 static String xm() { return "xam"; } |
|
90 static private String xn() { return "xan"; } |
|
91 static protected String xo() { return "xao"; } |
|
92 |
|
93 public class B extends BS { |
|
94 B() { super(); } |
|
95 String s = "bs"; |
|
96 private String t = "bt"; |
|
97 protected String u = "bu"; |
|
98 String m() { return "bm"; } |
|
99 private String n() { return "bn"; } |
|
100 protected String o() { return "bo"; } |
|
101 public class C extends CS { |
|
102 C() { super(); } |
|
103 String s = "cs"; |
|
104 private String t = "ct"; |
|
105 protected String u = "cu"; |
|
106 String m() { return "cm"; } |
|
107 private String n() { return "cn"; } |
|
108 protected String o() { return "co"; } |
|
109 void test() { |
|
110 |
|
111 check("QualifiedThisAndSuper_3.super.xm()", QualifiedThisAndSuper_3.super.xm(), "xasm"); |
|
112 // Private to another package-member class: not accessible |
|
113 // check("QualifiedThisAndSuper_3.super.xn()", QualifiedThisAndSuper_3.super.xn(), "xasn"); |
|
114 check("QualifiedThisAndSuper_3.super.xo()", QualifiedThisAndSuper_3.super.xo(), "xaso"); |
|
115 |
|
116 check("QualifiedThisAndSuper_3.super.xs", QualifiedThisAndSuper_3.super.xs, "xass"); |
|
117 // Private to another package-member class: not accessible |
|
118 // check("QualifiedThisAndSuper_3.super.xt", QualifiedThisAndSuper_3.super.xt, "xast"); |
|
119 check("QualifiedThisAndSuper_3.super.xu", QualifiedThisAndSuper_3.super.xu, "xasu"); |
|
120 |
|
121 check("QualifiedThisAndSuper_3.this.xm()", QualifiedThisAndSuper_3.this.xm(), "xam"); |
|
122 check("QualifiedThisAndSuper_3.this.xn()", QualifiedThisAndSuper_3.this.xn(), "xan"); |
|
123 check("QualifiedThisAndSuper_3.this.xo()", QualifiedThisAndSuper_3.this.xo(), "xao"); |
|
124 |
|
125 check("QualifiedThisAndSuper_3.this.xs", QualifiedThisAndSuper_3.this.xs, "xas"); |
|
126 check("QualifiedThisAndSuper_3.this.xt", QualifiedThisAndSuper_3.this.xt, "xat"); |
|
127 check("QualifiedThisAndSuper_3.this.xu", QualifiedThisAndSuper_3.this.xu, "xau"); |
|
128 |
|
129 //--- |
|
130 |
|
131 check("this.m()", this.m(), "cm"); |
|
132 |
|
133 check("QualifiedThisAndSuper_3.this.m()", QualifiedThisAndSuper_3.this.m(), "am"); |
|
134 check("B.this.m()", B.this.m(), "bm"); |
|
135 check("C.this.m()", C.this.m(), "cm"); |
|
136 |
|
137 check("super.m()", super.m(), "csm"); |
|
138 |
|
139 check("QualifiedThisAndSuper_3.super.m()", QualifiedThisAndSuper_3.super.m(), "asm"); |
|
140 check("B.super.m()", B.super.m(), "bsm"); |
|
141 check("C.super.m()", C.super.m(), "csm"); |
|
142 |
|
143 // should re-use access methods. |
|
144 check("QualifiedThisAndSuper_3.super.m()", QualifiedThisAndSuper_3.super.m(), "asm"); |
|
145 check("B.super.m()", B.super.m(), "bsm"); |
|
146 check("C.super.m()", C.super.m(), "csm"); |
|
147 |
|
148 //--- |
|
149 |
|
150 check("this.n()", this.n(), "cn"); |
|
151 |
|
152 check("QualifiedThisAndSuper_3.this.n()", QualifiedThisAndSuper_3.this.n(), "an"); |
|
153 check("B.this.n()", B.this.n(), "bn"); |
|
154 check("C.this.n()", C.this.n(), "cn"); |
|
155 |
|
156 /***** |
|
157 check("super.n()", super.n(), "csn"); |
|
158 |
|
159 check("QualifiedThisAndSuper_3.super.n()", QualifiedThisAndSuper_3.super.n(), "asn"); |
|
160 check("B.super.n()", B.super.n(), "bsn"); |
|
161 check("C.super.n()", C.super.n(), "csn"); |
|
162 |
|
163 // should re-use access methods. |
|
164 check("QualifiedThisAndSuper_3.super.n()", QualifiedThisAndSuper_3.super.n(), "asn"); |
|
165 check("B.super.n()", B.super.n(), "bsn"); |
|
166 check("C.super.n()", C.super.n(), "csn"); |
|
167 *****/ |
|
168 |
|
169 //--- |
|
170 |
|
171 check("this.o()", this.o(), "co"); |
|
172 |
|
173 check("QualifiedThisAndSuper_3.this.o()", QualifiedThisAndSuper_3.this.o(), "ao"); |
|
174 check("B.this.o()", B.this.o(), "bo"); |
|
175 check("C.this.o()", C.this.o(), "co"); |
|
176 |
|
177 check("super.o()", super.o(), "cso"); |
|
178 |
|
179 check("QualifiedThisAndSuper_3.super.o()", QualifiedThisAndSuper_3.super.o(), "aso"); |
|
180 check("B.super.o()", B.super.o(), "bso"); |
|
181 check("C.super.o()", C.super.o(), "cso"); |
|
182 |
|
183 // should re-use access methods. |
|
184 check("QualifiedThisAndSuper_3.super.o()", QualifiedThisAndSuper_3.super.o(), "aso"); |
|
185 check("B.super.o()", B.super.o(), "bso"); |
|
186 check("C.super.o()", C.super.o(), "cso"); |
|
187 |
|
188 //--- |
|
189 |
|
190 check("this.s", this.s, "cs"); |
|
191 |
|
192 check("QualifiedThisAndSuper_3.this.s", QualifiedThisAndSuper_3.this.s, "as"); |
|
193 check("B.this.s", B.this.s, "bs"); |
|
194 check("C.this.s", C.this.s, "cs"); |
|
195 |
|
196 //--- |
|
197 |
|
198 check("this.t", this.t, "ct"); |
|
199 |
|
200 check("QualifiedThisAndSuper_3.this.t", QualifiedThisAndSuper_3.this.t, "at"); |
|
201 check("B.this.t", B.this.t, "bt"); |
|
202 check("C.this.t", C.this.t, "ct"); |
|
203 |
|
204 //--- |
|
205 |
|
206 check("this.u", this.u, "cu"); |
|
207 |
|
208 check("QualifiedThisAndSuper_3.this.u", QualifiedThisAndSuper_3.this.u, "au"); |
|
209 check("B.this.u", B.this.u, "bu"); |
|
210 check("C.this.u", C.this.u, "cu"); |
|
211 |
|
212 //--- |
|
213 |
|
214 check("super.s", super.s, "css"); |
|
215 |
|
216 check("QualifiedThisAndSuper_3.super.s", QualifiedThisAndSuper_3.super.s, "ass"); |
|
217 check("B.super.s", B.super.s, "bss"); |
|
218 check("C.super.s", C.super.s, "css"); |
|
219 |
|
220 //--- |
|
221 |
|
222 /***** |
|
223 check("super.t", super.t, "cst"); |
|
224 |
|
225 check("QualifiedThisAndSuper_3.super.t", QualifiedThisAndSuper_3.super.t, "ast"); |
|
226 check("B.super.t", B.super.t, "bst"); |
|
227 check("C.super.t", C.super.t, "cst"); |
|
228 *****/ |
|
229 |
|
230 //--- |
|
231 |
|
232 check("super.u", super.u, "csu"); |
|
233 |
|
234 check("QualifiedThisAndSuper_3.super.u", QualifiedThisAndSuper_3.super.u, "asu"); |
|
235 check("B.super.u", B.super.u, "bsu"); |
|
236 check("C.super.u", C.super.u, "csu"); |
|
237 |
|
238 //--- |
|
239 |
|
240 QualifiedThisAndSuper_3.this.s = "foo"; |
|
241 System.out.println(QualifiedThisAndSuper_3.this.s); |
|
242 check("QualifiedThisAndSuper_3.this.s", QualifiedThisAndSuper_3.this.s, "foo"); |
|
243 B.this.s = "bar"; |
|
244 System.out.println(B.this.s); |
|
245 check("B.this.s", B.this.s, "bar"); |
|
246 C.this.s = "baz"; |
|
247 System.out.println(C.this.s); |
|
248 check("C.this.s", C.this.s, "baz"); |
|
249 |
|
250 QualifiedThisAndSuper_3.this.t = "foo"; |
|
251 System.out.println(QualifiedThisAndSuper_3.this.t); |
|
252 check("QualifiedThisAndSuper_3.this.t", QualifiedThisAndSuper_3.this.t, "foo"); |
|
253 B.this.t = "bar"; |
|
254 System.out.println(B.this.t); |
|
255 check("B.this.t", B.this.t, "bar"); |
|
256 C.this.t = "baz"; |
|
257 System.out.println(C.this.t); |
|
258 check("C.this.t", C.this.t, "baz"); |
|
259 |
|
260 QualifiedThisAndSuper_3.this.u = "foo"; |
|
261 System.out.println(QualifiedThisAndSuper_3.this.u); |
|
262 check("QualifiedThisAndSuper_3.this.u", QualifiedThisAndSuper_3.this.u, "foo"); |
|
263 B.this.u = "bar"; |
|
264 System.out.println(B.this.u); |
|
265 check("B.this.u", B.this.u, "bar"); |
|
266 C.this.u = "baz"; |
|
267 System.out.println(C.this.u); |
|
268 check("C.this.u", C.this.u, "baz"); |
|
269 |
|
270 QualifiedThisAndSuper_3.super.s = "foo"; |
|
271 System.out.println(QualifiedThisAndSuper_3.super.s); |
|
272 check("QualifiedThisAndSuper_3.super.s", QualifiedThisAndSuper_3.super.s, "foo"); |
|
273 B.super.s = "bar"; |
|
274 System.out.println(B.super.s); |
|
275 check("B.super.s", B.super.s, "bar"); |
|
276 C.super.s = "baz"; |
|
277 System.out.println(C.super.s); |
|
278 check("C.super.s", C.super.s, "baz"); |
|
279 |
|
280 /***** |
|
281 QualifiedThisAndSuper_3.super.t = "foo"; |
|
282 System.out.println(QualifiedThisAndSuper_3.super.t); |
|
283 check("QualifiedThisAndSuper_3.super.t", QualifiedThisAndSuper_3.super.t, "foo"); |
|
284 B.super.t = "bar"; |
|
285 System.out.println(B.super.t); |
|
286 check("B.super.t", B.super.t, "bar"); |
|
287 C.super.t = "baz"; |
|
288 System.out.println(C.super.t); |
|
289 check("C.super.t", C.super.t, "baz"); |
|
290 *****/ |
|
291 |
|
292 QualifiedThisAndSuper_3.super.u = "foo"; |
|
293 System.out.println(QualifiedThisAndSuper_3.super.u); |
|
294 check("QualifiedThisAndSuper_3.super.u", QualifiedThisAndSuper_3.super.u, "foo"); |
|
295 B.super.u = "bar"; |
|
296 System.out.println(B.super.u); |
|
297 check("B.super.u", B.super.u, "bar"); |
|
298 C.super.u = "baz"; |
|
299 System.out.println(C.super.u); |
|
300 check("C.super.u", C.super.u, "baz"); |
|
301 |
|
302 } |
|
303 } |
|
304 void test() throws Exception { |
|
305 C c = new C(); |
|
306 c.test(); |
|
307 } |
|
308 } |
|
309 void test() throws Exception { |
|
310 B b = new B(); |
|
311 b.test(); |
|
312 } |
|
313 |
|
314 public static void main(String[] args) throws Exception { |
|
315 QualifiedThisAndSuper_3 a = new QualifiedThisAndSuper_3(); |
|
316 a.test(); |
|
317 } |
|
318 } |