1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/QualifiedThisAndSuper_1.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,283 @@ 1.4 +/* 1.5 + * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 4147520 1.30 + * @summary Verify correct implementation of qualified 'this' and 'super'. 1.31 + * @author maddox 1.32 + * 1.33 + * @run compile QualifiedThisAndSuper_1.java 1.34 + * @run main QualifiedThisAndSuper_1 1.35 + */ 1.36 + 1.37 +public class QualifiedThisAndSuper_1 { 1.38 + 1.39 + public class AS { 1.40 + String s = "ass"; 1.41 + private String t = "ast"; 1.42 + protected String u = "asu"; 1.43 + String m() { return "asm"; } 1.44 + private String n() { return "asn"; } 1.45 + protected String o() { return "aso"; } 1.46 + } 1.47 + 1.48 + public class BS { 1.49 + String s = "bss"; 1.50 + private String t = "bst"; 1.51 + protected String u = "bsu"; 1.52 + String m() { return "bsm"; } 1.53 + private String n() { return "bsn"; } 1.54 + protected String o() { return "bso"; } 1.55 + } 1.56 + 1.57 + public class CS { 1.58 + String s = "css"; 1.59 + private String t = "cst"; 1.60 + protected String u = "csu"; 1.61 + String m() { return "csm"; } 1.62 + private String n() { return "csn"; } 1.63 + protected String o() { return "cso"; } 1.64 + } 1.65 + 1.66 + 1.67 + void check(String expr, String result, String expected) { 1.68 + if (!result.equals(expected)) { 1.69 + throw new Error("Evaluated "+ expr + 1.70 + " : result " + result + ", expected " + expected); 1.71 + } 1.72 + } 1.73 + 1.74 + public class A extends AS { 1.75 + A() { super(); } 1.76 + String s = "as"; 1.77 + private String t = "at"; 1.78 + protected String u = "au"; 1.79 + String m() { return "am"; } 1.80 + private String n() { return "an"; } 1.81 + protected String o() { return "ao"; } 1.82 + public class B extends BS { 1.83 + B() { super(); } 1.84 + String s = "bs"; 1.85 + private String t = "bt"; 1.86 + protected String u = "bu"; 1.87 + String m() { return "bm"; } 1.88 + private String n() { return "bn"; } 1.89 + protected String o() { return "bo"; } 1.90 + public class C extends CS { 1.91 + C() { super(); } 1.92 + String s = "cs"; 1.93 + private String t = "ct"; 1.94 + protected String u = "cu"; 1.95 + String m() { return "cm"; } 1.96 + private String n() { return "cn"; } 1.97 + protected String o() { return "co"; } 1.98 + void test() { 1.99 + 1.100 + check("this.m()", this.m(), "cm"); 1.101 + 1.102 + check("A.this.m()", A.this.m(), "am"); 1.103 + check("B.this.m()", B.this.m(), "bm"); 1.104 + check("C.this.m()", C.this.m(), "cm"); 1.105 + 1.106 + check("super.m()", super.m(), "csm"); 1.107 + 1.108 + check("A.super.m()", A.super.m(), "asm"); 1.109 + check("B.super.m()", B.super.m(), "bsm"); 1.110 + check("C.super.m()", C.super.m(), "csm"); 1.111 + 1.112 + // should re-use access methods. 1.113 + check("A.super.m()", A.super.m(), "asm"); 1.114 + check("B.super.m()", B.super.m(), "bsm"); 1.115 + check("C.super.m()", C.super.m(), "csm"); 1.116 + 1.117 + //--- 1.118 + 1.119 + check("this.n()", this.n(), "cn"); 1.120 + 1.121 + check("A.this.n()", A.this.n(), "an"); 1.122 + check("B.this.n()", B.this.n(), "bn"); 1.123 + check("C.this.n()", C.this.n(), "cn"); 1.124 + 1.125 + 1.126 + check("super.n()", super.n(), "csn"); 1.127 + 1.128 + 1.129 + 1.130 + check("A.super.n()", A.super.n(), "asn"); 1.131 + 1.132 + check("B.super.n()", B.super.n(), "bsn"); 1.133 + check("C.super.n()", C.super.n(), "csn"); 1.134 + 1.135 + // should re-use access methods. 1.136 + check("A.super.n()", A.super.n(), "asn"); 1.137 + check("B.super.n()", B.super.n(), "bsn"); 1.138 + check("C.super.n()", C.super.n(), "csn"); 1.139 + 1.140 + //--- 1.141 + 1.142 + check("this.o()", this.o(), "co"); 1.143 + 1.144 + check("A.this.o()", A.this.o(), "ao"); 1.145 + check("B.this.o()", B.this.o(), "bo"); 1.146 + check("C.this.o()", C.this.o(), "co"); 1.147 + 1.148 + check("super.o()", super.o(), "cso"); 1.149 + 1.150 + check("A.super.o()", A.super.o(), "aso"); 1.151 + check("B.super.o()", B.super.o(), "bso"); 1.152 + check("C.super.o()", C.super.o(), "cso"); 1.153 + 1.154 + // should re-use access methods. 1.155 + check("A.super.o()", A.super.o(), "aso"); 1.156 + check("B.super.o()", B.super.o(), "bso"); 1.157 + check("C.super.o()", C.super.o(), "cso"); 1.158 + 1.159 + //--- 1.160 + 1.161 + check("this.s", this.s, "cs"); 1.162 + 1.163 + check("A.this.s", A.this.s, "as"); 1.164 + check("B.this.s", B.this.s, "bs"); 1.165 + check("C.this.s", C.this.s, "cs"); 1.166 + 1.167 + //--- 1.168 + 1.169 + check("this.t", this.t, "ct"); 1.170 + 1.171 + check("A.this.t", A.this.t, "at"); 1.172 + check("B.this.t", B.this.t, "bt"); 1.173 + check("C.this.t", C.this.t, "ct"); 1.174 + 1.175 + //--- 1.176 + 1.177 + check("this.u", this.u, "cu"); 1.178 + 1.179 + check("A.this.u", A.this.u, "au"); 1.180 + check("B.this.u", B.this.u, "bu"); 1.181 + check("C.this.u", C.this.u, "cu"); 1.182 + 1.183 + //--- 1.184 + 1.185 + check("super.s", super.s, "css"); 1.186 + 1.187 + check("A.super.s", A.super.s, "ass"); 1.188 + check("B.super.s", B.super.s, "bss"); 1.189 + check("C.super.s", C.super.s, "css"); 1.190 + 1.191 + //--- 1.192 + 1.193 + check("super.t", super.t, "cst"); 1.194 + 1.195 + check("A.super.t", A.super.t, "ast"); 1.196 + check("B.super.t", B.super.t, "bst"); 1.197 + check("C.super.t", C.super.t, "cst"); 1.198 + 1.199 + //--- 1.200 + 1.201 + check("super.u", super.u, "csu"); 1.202 + 1.203 + check("A.super.u", A.super.u, "asu"); 1.204 + check("B.super.u", B.super.u, "bsu"); 1.205 + check("C.super.u", C.super.u, "csu"); 1.206 + 1.207 + //--- 1.208 + 1.209 + A.this.s = "foo"; 1.210 + System.out.println(A.this.s); 1.211 + check("A.this.s", A.this.s, "foo"); 1.212 + B.this.s = "bar"; 1.213 + System.out.println(B.this.s); 1.214 + check("B.this.s", B.this.s, "bar"); 1.215 + C.this.s = "baz"; 1.216 + System.out.println(C.this.s); 1.217 + check("C.this.s", C.this.s, "baz"); 1.218 + 1.219 + A.this.t = "foo"; 1.220 + System.out.println(A.this.t); 1.221 + check("A.this.t", A.this.t, "foo"); 1.222 + B.this.t = "bar"; 1.223 + System.out.println(B.this.t); 1.224 + check("B.this.t", B.this.t, "bar"); 1.225 + C.this.t = "baz"; 1.226 + System.out.println(C.this.t); 1.227 + check("C.this.t", C.this.t, "baz"); 1.228 + 1.229 + A.this.u = "foo"; 1.230 + System.out.println(A.this.u); 1.231 + check("A.this.u", A.this.u, "foo"); 1.232 + B.this.u = "bar"; 1.233 + System.out.println(B.this.u); 1.234 + check("B.this.u", B.this.u, "bar"); 1.235 + C.this.u = "baz"; 1.236 + System.out.println(C.this.u); 1.237 + check("C.this.u", C.this.u, "baz"); 1.238 + 1.239 + A.super.s = "foo"; 1.240 + System.out.println(A.super.s); 1.241 + check("A.super.s", A.super.s, "foo"); 1.242 + B.super.s = "bar"; 1.243 + System.out.println(B.super.s); 1.244 + check("B.super.s", B.super.s, "bar"); 1.245 + C.super.s = "baz"; 1.246 + System.out.println(C.super.s); 1.247 + check("C.super.s", C.super.s, "baz"); 1.248 + 1.249 + A.super.t = "foo"; 1.250 + System.out.println(A.super.t); 1.251 + check("A.super.t", A.super.t, "foo"); 1.252 + B.super.t = "bar"; 1.253 + System.out.println(B.super.t); 1.254 + check("B.super.t", B.super.t, "bar"); 1.255 + C.super.t = "baz"; 1.256 + System.out.println(C.super.t); 1.257 + check("C.super.t", C.super.t, "baz"); 1.258 + 1.259 + A.super.u = "foo"; 1.260 + System.out.println(A.super.u); 1.261 + check("A.super.u", A.super.u, "foo"); 1.262 + B.super.u = "bar"; 1.263 + System.out.println(B.super.u); 1.264 + check("B.super.u", B.super.u, "bar"); 1.265 + C.super.u = "baz"; 1.266 + System.out.println(C.super.u); 1.267 + check("C.super.u", C.super.u, "baz"); 1.268 + 1.269 + } 1.270 + } 1.271 + void test() throws Exception { 1.272 + C c = new C(); 1.273 + c.test(); 1.274 + } 1.275 + } 1.276 + void test() throws Exception { 1.277 + B b = new B(); 1.278 + b.test(); 1.279 + } 1.280 + } 1.281 + 1.282 + public static void main(String[] args) throws Exception { 1.283 + A a = new QualifiedThisAndSuper_1().new A(); 1.284 + a.test(); 1.285 + } 1.286 +}