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