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