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 * @author maddox
0N/A *
0N/A * @run compile QualifiedThisAndSuper_3.java
0N/A * @run main QualifiedThisAndSuper_3
0N/A */
0N/A
0N/Aclass AS {
0N/A String s = "ass";
0N/A private String t = "ast";
0N/A protected String u = "asu";
0N/A String m() { return "asm"; }
0N/A private String n() { return "asn"; }
0N/A protected String o() { return "aso"; }
0N/A
0N/A static String xs = "xass";
0N/A static private String xt = "xast";
0N/A static protected String xu = "xasu";
0N/A static String xm() { return "xasm"; }
0N/A static private String xn() { return "xasn"; }
0N/A static protected String xo() { return "xaso"; }
0N/A}
0N/A
0N/Aclass BS {
0N/A String s = "bss";
0N/A private String t = "bst";
0N/A protected String u = "bsu";
0N/A String m() { return "bsm"; }
0N/A private String n() { return "bsn"; }
0N/A protected String o() { return "bso"; }
0N/A}
0N/A
0N/Aclass CS {
0N/A String s = "css";
0N/A private String t = "cst";
0N/A protected String u = "csu";
0N/A String m() { return "csm"; }
0N/A private String n() { return "csn"; }
0N/A protected String o() { return "cso"; }
0N/A}
0N/A
0N/Apublic class QualifiedThisAndSuper_3 extends AS {
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
0N/A QualifiedThisAndSuper_3() { 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
0N/A static String xs = "xas";
0N/A static private String xt = "xat";
0N/A static protected String xu = "xau";
0N/A static String xm() { return "xam"; }
0N/A static private String xn() { return "xan"; }
0N/A static protected String xo() { return "xao"; }
0N/A
0N/A public class B extends 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 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("QualifiedThisAndSuper_3.super.xm()", QualifiedThisAndSuper_3.super.xm(), "xasm");
0N/A // Private to another package-member class: not accessible
0N/A // check("QualifiedThisAndSuper_3.super.xn()", QualifiedThisAndSuper_3.super.xn(), "xasn");
0N/A check("QualifiedThisAndSuper_3.super.xo()", QualifiedThisAndSuper_3.super.xo(), "xaso");
0N/A
0N/A check("QualifiedThisAndSuper_3.super.xs", QualifiedThisAndSuper_3.super.xs, "xass");
0N/A // Private to another package-member class: not accessible
0N/A // check("QualifiedThisAndSuper_3.super.xt", QualifiedThisAndSuper_3.super.xt, "xast");
0N/A check("QualifiedThisAndSuper_3.super.xu", QualifiedThisAndSuper_3.super.xu, "xasu");
0N/A
0N/A check("QualifiedThisAndSuper_3.this.xm()", QualifiedThisAndSuper_3.this.xm(), "xam");
0N/A check("QualifiedThisAndSuper_3.this.xn()", QualifiedThisAndSuper_3.this.xn(), "xan");
0N/A check("QualifiedThisAndSuper_3.this.xo()", QualifiedThisAndSuper_3.this.xo(), "xao");
0N/A
0N/A check("QualifiedThisAndSuper_3.this.xs", QualifiedThisAndSuper_3.this.xs, "xas");
0N/A check("QualifiedThisAndSuper_3.this.xt", QualifiedThisAndSuper_3.this.xt, "xat");
0N/A check("QualifiedThisAndSuper_3.this.xu", QualifiedThisAndSuper_3.this.xu, "xau");
0N/A
0N/A //---
0N/A
0N/A check("this.m()", this.m(), "cm");
0N/A
0N/A check("QualifiedThisAndSuper_3.this.m()", QualifiedThisAndSuper_3.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 check("super.m()", super.m(), "csm");
0N/A
0N/A check("QualifiedThisAndSuper_3.super.m()", QualifiedThisAndSuper_3.super.m(), "asm");
0N/A check("B.super.m()", B.super.m(), "bsm");
0N/A check("C.super.m()", C.super.m(), "csm");
0N/A
0N/A // should re-use access methods.
0N/A check("QualifiedThisAndSuper_3.super.m()", QualifiedThisAndSuper_3.super.m(), "asm");
0N/A check("B.super.m()", B.super.m(), "bsm");
0N/A check("C.super.m()", C.super.m(), "csm");
0N/A
0N/A //---
0N/A
0N/A check("this.n()", this.n(), "cn");
0N/A
0N/A check("QualifiedThisAndSuper_3.this.n()", QualifiedThisAndSuper_3.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 check("super.n()", super.n(), "csn");
0N/A
0N/A check("QualifiedThisAndSuper_3.super.n()", QualifiedThisAndSuper_3.super.n(), "asn");
0N/A check("B.super.n()", B.super.n(), "bsn");
0N/A check("C.super.n()", C.super.n(), "csn");
0N/A
0N/A // should re-use access methods.
0N/A check("QualifiedThisAndSuper_3.super.n()", QualifiedThisAndSuper_3.super.n(), "asn");
0N/A check("B.super.n()", B.super.n(), "bsn");
0N/A check("C.super.n()", C.super.n(), "csn");
0N/A *****/
0N/A
0N/A //---
0N/A
0N/A check("this.o()", this.o(), "co");
0N/A
0N/A check("QualifiedThisAndSuper_3.this.o()", QualifiedThisAndSuper_3.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("QualifiedThisAndSuper_3.super.o()", QualifiedThisAndSuper_3.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("QualifiedThisAndSuper_3.super.o()", QualifiedThisAndSuper_3.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("QualifiedThisAndSuper_3.this.s", QualifiedThisAndSuper_3.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("QualifiedThisAndSuper_3.this.t", QualifiedThisAndSuper_3.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("QualifiedThisAndSuper_3.this.u", QualifiedThisAndSuper_3.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.s", super.s, "css");
0N/A
0N/A check("QualifiedThisAndSuper_3.super.s", QualifiedThisAndSuper_3.super.s, "ass");
0N/A check("B.super.s", B.super.s, "bss");
0N/A check("C.super.s", C.super.s, "css");
0N/A
0N/A //---
0N/A
0N/A /*****
0N/A check("super.t", super.t, "cst");
0N/A
0N/A check("QualifiedThisAndSuper_3.super.t", QualifiedThisAndSuper_3.super.t, "ast");
0N/A check("B.super.t", B.super.t, "bst");
0N/A check("C.super.t", C.super.t, "cst");
0N/A *****/
0N/A
0N/A //---
0N/A
0N/A check("super.u", super.u, "csu");
0N/A
0N/A check("QualifiedThisAndSuper_3.super.u", QualifiedThisAndSuper_3.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 QualifiedThisAndSuper_3.this.s = "foo";
0N/A System.out.println(QualifiedThisAndSuper_3.this.s);
0N/A check("QualifiedThisAndSuper_3.this.s", QualifiedThisAndSuper_3.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 QualifiedThisAndSuper_3.this.t = "foo";
0N/A System.out.println(QualifiedThisAndSuper_3.this.t);
0N/A check("QualifiedThisAndSuper_3.this.t", QualifiedThisAndSuper_3.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 QualifiedThisAndSuper_3.this.u = "foo";
0N/A System.out.println(QualifiedThisAndSuper_3.this.u);
0N/A check("QualifiedThisAndSuper_3.this.u", QualifiedThisAndSuper_3.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 QualifiedThisAndSuper_3.super.s = "foo";
0N/A System.out.println(QualifiedThisAndSuper_3.super.s);
0N/A check("QualifiedThisAndSuper_3.super.s", QualifiedThisAndSuper_3.super.s, "foo");
0N/A B.super.s = "bar";
0N/A System.out.println(B.super.s);
0N/A check("B.super.s", B.super.s, "bar");
0N/A C.super.s = "baz";
0N/A System.out.println(C.super.s);
0N/A check("C.super.s", C.super.s, "baz");
0N/A
0N/A /*****
0N/A QualifiedThisAndSuper_3.super.t = "foo";
0N/A System.out.println(QualifiedThisAndSuper_3.super.t);
0N/A check("QualifiedThisAndSuper_3.super.t", QualifiedThisAndSuper_3.super.t, "foo");
0N/A B.super.t = "bar";
0N/A System.out.println(B.super.t);
0N/A check("B.super.t", B.super.t, "bar");
0N/A C.super.t = "baz";
0N/A System.out.println(C.super.t);
0N/A check("C.super.t", C.super.t, "baz");
0N/A *****/
0N/A
0N/A QualifiedThisAndSuper_3.super.u = "foo";
0N/A System.out.println(QualifiedThisAndSuper_3.super.u);
0N/A check("QualifiedThisAndSuper_3.super.u", QualifiedThisAndSuper_3.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 public static void main(String[] args) throws Exception {
0N/A QualifiedThisAndSuper_3 a = new QualifiedThisAndSuper_3();
0N/A a.test();
0N/A }
0N/A}