QualifiedThisAndSuper_2.java revision 0
4340N/A/*
4340N/A * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
4340N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4340N/A *
4340N/A * This code is free software; you can redistribute it and/or modify it
4340N/A * under the terms of the GNU General Public License version 2 only, as
4340N/A * published by the Free Software Foundation.
4340N/A *
4340N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4340N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4340N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4340N/A * version 2 for more details (a copy is included in the LICENSE file that
4340N/A * accompanied this code).
4340N/A *
4340N/A * You should have received a copy of the GNU General Public License version
4340N/A * 2 along with this work; if not, write to the Free Software Foundation,
4340N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4340N/A *
4340N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
4340N/A * CA 95054 USA or visit www.sun.com if you need additional information or
4340N/A * have any questions.
4340N/A */
4340N/A
4340N/A/*
4340N/A * @test
4340N/A * @bug 4147520
4340N/A * @summary Verify correct implementation of qualified 'this' and 'super'.
4340N/A *
4340N/A * @run compile QualifiedThisAndSuper_2.java
4340N/A * @run main QualifiedThisAndSuper_2
4340N/A */
4340N/A
4340N/Aimport p1.*;
4340N/A
4340N/Apublic class QualifiedThisAndSuper_2 {
4340N/A
4340N/A void check(String expr, String result, String expected) {
4340N/A if (!result.equals(expected)) {
4340N/A throw new Error("Evaluated "+ expr +
4340N/A " : result " + result + ", expected " + expected);
4340N/A }
4340N/A }
4340N/A
4340N/A public class A extends p1.AS {
A() { super(); }
String s = "as";
private String t = "at";
protected String u = "au";
String m() { return "am"; }
private String n() { return "an"; }
protected String o() { return "ao"; }
public class B extends p1.BS {
B() { super(); }
String s = "bs";
private String t = "bt";
protected String u = "bu";
String m() { return "bm"; }
private String n() { return "bn"; }
protected String o() { return "bo"; }
public class C extends p1.CS {
C() { super(); }
String s = "cs";
private String t = "ct";
protected String u = "cu";
String m() { return "cm"; }
private String n() { return "cn"; }
protected String o() { return "co"; }
void test() {
check("this.m()", this.m(), "cm");
check("A.this.m()", A.this.m(), "am");
check("B.this.m()", B.this.m(), "bm");
check("C.this.m()", C.this.m(), "cm");
//---
check("this.n()", this.n(), "cn");
check("A.this.n()", A.this.n(), "an");
check("B.this.n()", B.this.n(), "bn");
check("C.this.n()", C.this.n(), "cn");
//---
check("this.o()", this.o(), "co");
check("A.this.o()", A.this.o(), "ao");
check("B.this.o()", B.this.o(), "bo");
check("C.this.o()", C.this.o(), "co");
check("super.o()", super.o(), "cso");
check("A.super.o()", A.super.o(), "aso");
check("B.super.o()", B.super.o(), "bso");
check("C.super.o()", C.super.o(), "cso");
// should re-use access methods.
check("A.super.o()", A.super.o(), "aso");
check("B.super.o()", B.super.o(), "bso");
check("C.super.o()", C.super.o(), "cso");
//---
check("this.s", this.s, "cs");
check("A.this.s", A.this.s, "as");
check("B.this.s", B.this.s, "bs");
check("C.this.s", C.this.s, "cs");
//---
check("this.t", this.t, "ct");
check("A.this.t", A.this.t, "at");
check("B.this.t", B.this.t, "bt");
check("C.this.t", C.this.t, "ct");
//---
check("this.u", this.u, "cu");
check("A.this.u", A.this.u, "au");
check("B.this.u", B.this.u, "bu");
check("C.this.u", C.this.u, "cu");
//---
check("super.u", super.u, "csu");
check("A.super.u", A.super.u, "asu");
check("B.super.u", B.super.u, "bsu");
check("C.super.u", C.super.u, "csu");
//---
A.this.s = "foo";
System.out.println(A.this.s);
check("A.this.s", A.this.s, "foo");
B.this.s = "bar";
System.out.println(B.this.s);
check("B.this.s", B.this.s, "bar");
C.this.s = "baz";
System.out.println(C.this.s);
check("C.this.s", C.this.s, "baz");
A.this.t = "foo";
System.out.println(A.this.t);
check("A.this.t", A.this.t, "foo");
B.this.t = "bar";
System.out.println(B.this.t);
check("B.this.t", B.this.t, "bar");
C.this.t = "baz";
System.out.println(C.this.t);
check("C.this.t", C.this.t, "baz");
A.this.u = "foo";
System.out.println(A.this.u);
check("A.this.u", A.this.u, "foo");
B.this.u = "bar";
System.out.println(B.this.u);
check("B.this.u", B.this.u, "bar");
C.this.u = "baz";
System.out.println(C.this.u);
check("C.this.u", C.this.u, "baz");
A.super.u = "foo";
System.out.println(A.super.u);
check("A.super.u", A.super.u, "foo");
B.super.u = "bar";
System.out.println(B.super.u);
check("B.super.u", B.super.u, "bar");
C.super.u = "baz";
System.out.println(C.super.u);
check("C.super.u", C.super.u, "baz");
}
}
void test() throws Exception {
C c = new C();
c.test();
}
}
void test() throws Exception {
B b = new B();
b.test();
}
}
public static void main(String[] args) throws Exception {
A a = new QualifiedThisAndSuper_2().new A();
a.test();
}
}