1/* 2 * Copyright (c) 1998, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 4147520 27 * @summary Verify correct implementation of qualified 'this' and 'super'. 28 * 29 * @run compile QualifiedThisAndSuper_2.java 30 * @run main QualifiedThisAndSuper_2 31 */ 32 33import p1.*; 34 35public class QualifiedThisAndSuper_2 { 36 37 void check(String expr, String result, String expected) { 38 if (!result.equals(expected)) { 39 throw new Error("Evaluated "+ expr + 40 " : result " + result + ", expected " + expected); 41 } 42 } 43 44 public class A extends p1.AS { 45 A() { super(); } 46 String s = "as"; 47 private String t = "at"; 48 protected String u = "au"; 49 String m() { return "am"; } 50 private String n() { return "an"; } 51 protected String o() { return "ao"; } 52 public class B extends p1.BS { 53 B() { super(); } 54 String s = "bs"; 55 private String t = "bt"; 56 protected String u = "bu"; 57 String m() { return "bm"; } 58 private String n() { return "bn"; } 59 protected String o() { return "bo"; } 60 public class C extends p1.CS { 61 C() { super(); } 62 String s = "cs"; 63 private String t = "ct"; 64 protected String u = "cu"; 65 String m() { return "cm"; } 66 private String n() { return "cn"; } 67 protected String o() { return "co"; } 68 void test() { 69 70 check("this.m()", this.m(), "cm"); 71 72 check("A.this.m()", A.this.m(), "am"); 73 check("B.this.m()", B.this.m(), "bm"); 74 check("C.this.m()", C.this.m(), "cm"); 75 76 //--- 77 78 check("this.n()", this.n(), "cn"); 79 80 check("A.this.n()", A.this.n(), "an"); 81 check("B.this.n()", B.this.n(), "bn"); 82 check("C.this.n()", C.this.n(), "cn"); 83 84 //--- 85 86 check("this.o()", this.o(), "co"); 87 88 check("A.this.o()", A.this.o(), "ao"); 89 check("B.this.o()", B.this.o(), "bo"); 90 check("C.this.o()", C.this.o(), "co"); 91 92 check("super.o()", super.o(), "cso"); 93 94 check("A.super.o()", A.super.o(), "aso"); 95 check("B.super.o()", B.super.o(), "bso"); 96 check("C.super.o()", C.super.o(), "cso"); 97 98 // should re-use access methods. 99 check("A.super.o()", A.super.o(), "aso"); 100 check("B.super.o()", B.super.o(), "bso"); 101 check("C.super.o()", C.super.o(), "cso"); 102 103 //--- 104 105 check("this.s", this.s, "cs"); 106 107 check("A.this.s", A.this.s, "as"); 108 check("B.this.s", B.this.s, "bs"); 109 check("C.this.s", C.this.s, "cs"); 110 111 //--- 112 113 check("this.t", this.t, "ct"); 114 115 check("A.this.t", A.this.t, "at"); 116 check("B.this.t", B.this.t, "bt"); 117 check("C.this.t", C.this.t, "ct"); 118 119 //--- 120 121 check("this.u", this.u, "cu"); 122 123 check("A.this.u", A.this.u, "au"); 124 check("B.this.u", B.this.u, "bu"); 125 check("C.this.u", C.this.u, "cu"); 126 127 //--- 128 129 check("super.u", super.u, "csu"); 130 131 check("A.super.u", A.super.u, "asu"); 132 check("B.super.u", B.super.u, "bsu"); 133 check("C.super.u", C.super.u, "csu"); 134 135 //--- 136 137 A.this.s = "foo"; 138 System.out.println(A.this.s); 139 check("A.this.s", A.this.s, "foo"); 140 B.this.s = "bar"; 141 System.out.println(B.this.s); 142 check("B.this.s", B.this.s, "bar"); 143 C.this.s = "baz"; 144 System.out.println(C.this.s); 145 check("C.this.s", C.this.s, "baz"); 146 147 A.this.t = "foo"; 148 System.out.println(A.this.t); 149 check("A.this.t", A.this.t, "foo"); 150 B.this.t = "bar"; 151 System.out.println(B.this.t); 152 check("B.this.t", B.this.t, "bar"); 153 C.this.t = "baz"; 154 System.out.println(C.this.t); 155 check("C.this.t", C.this.t, "baz"); 156 157 A.this.u = "foo"; 158 System.out.println(A.this.u); 159 check("A.this.u", A.this.u, "foo"); 160 B.this.u = "bar"; 161 System.out.println(B.this.u); 162 check("B.this.u", B.this.u, "bar"); 163 C.this.u = "baz"; 164 System.out.println(C.this.u); 165 check("C.this.u", C.this.u, "baz"); 166 167 A.super.u = "foo"; 168 System.out.println(A.super.u); 169 check("A.super.u", A.super.u, "foo"); 170 B.super.u = "bar"; 171 System.out.println(B.super.u); 172 check("B.super.u", B.super.u, "bar"); 173 C.super.u = "baz"; 174 System.out.println(C.super.u); 175 check("C.super.u", C.super.u, "baz"); 176 177 } 178 } 179 void test() throws Exception { 180 C c = new C(); 181 c.test(); 182 } 183 } 184 void test() throws Exception { 185 B b = new B(); 186 b.test(); 187 } 188 } 189 190 public static void main(String[] args) throws Exception { 191 A a = new QualifiedThisAndSuper_2().new A(); 192 a.test(); 193 } 194} 195