test/tools/javac/QualifiedThisAndSuper_2.java

changeset 1
9a66ca7c79fa
child 554
9d9f26857129
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/QualifiedThisAndSuper_2.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,194 @@
     1.4 +/*
     1.5 + * Copyright 1998 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 4147520
    1.30 + * @summary Verify correct implementation of qualified 'this' and 'super'.
    1.31 + *
    1.32 + * @run compile QualifiedThisAndSuper_2.java
    1.33 + * @run main QualifiedThisAndSuper_2
    1.34 + */
    1.35 +
    1.36 +import p1.*;
    1.37 +
    1.38 +public class QualifiedThisAndSuper_2 {
    1.39 +
    1.40 +    void check(String expr, String result, String expected) {
    1.41 +        if (!result.equals(expected)) {
    1.42 +            throw new Error("Evaluated "+ expr +
    1.43 +                            " : result " + result + ", expected " + expected);
    1.44 +        }
    1.45 +    }
    1.46 +
    1.47 +    public class A extends p1.AS {
    1.48 +        A() { super(); }
    1.49 +        String s = "as";
    1.50 +        private String t = "at";
    1.51 +        protected String u = "au";
    1.52 +        String m() { return "am"; }
    1.53 +        private String n() { return "an"; }
    1.54 +        protected String o() { return "ao"; }
    1.55 +        public class B extends p1.BS {
    1.56 +            B() { super(); }
    1.57 +            String s = "bs";
    1.58 +            private String t = "bt";
    1.59 +            protected String u = "bu";
    1.60 +            String m() { return "bm"; }
    1.61 +            private String n() { return "bn"; }
    1.62 +            protected String o() { return "bo"; }
    1.63 +            public class C extends p1.CS {
    1.64 +                C() { super(); }
    1.65 +                String s = "cs";
    1.66 +                private String t = "ct";
    1.67 +                protected String u = "cu";
    1.68 +                String m() { return "cm"; }
    1.69 +                private String n() { return "cn"; }
    1.70 +                protected String o() { return "co"; }
    1.71 +                void test() {
    1.72 +
    1.73 +                    check("this.m()", this.m(), "cm");
    1.74 +
    1.75 +                    check("A.this.m()", A.this.m(), "am");
    1.76 +                    check("B.this.m()", B.this.m(), "bm");
    1.77 +                    check("C.this.m()", C.this.m(), "cm");
    1.78 +
    1.79 +                    //---
    1.80 +
    1.81 +                    check("this.n()", this.n(), "cn");
    1.82 +
    1.83 +                    check("A.this.n()", A.this.n(), "an");
    1.84 +                    check("B.this.n()", B.this.n(), "bn");
    1.85 +                    check("C.this.n()", C.this.n(), "cn");
    1.86 +
    1.87 +                    //---
    1.88 +
    1.89 +                    check("this.o()", this.o(), "co");
    1.90 +
    1.91 +                    check("A.this.o()", A.this.o(), "ao");
    1.92 +                    check("B.this.o()", B.this.o(), "bo");
    1.93 +                    check("C.this.o()", C.this.o(), "co");
    1.94 +
    1.95 +                    check("super.o()", super.o(), "cso");
    1.96 +
    1.97 +                    check("A.super.o()", A.super.o(), "aso");
    1.98 +                    check("B.super.o()", B.super.o(), "bso");
    1.99 +                    check("C.super.o()", C.super.o(), "cso");
   1.100 +
   1.101 +                    // should re-use access methods.
   1.102 +                    check("A.super.o()", A.super.o(), "aso");
   1.103 +                    check("B.super.o()", B.super.o(), "bso");
   1.104 +                    check("C.super.o()", C.super.o(), "cso");
   1.105 +
   1.106 +                    //---
   1.107 +
   1.108 +                    check("this.s", this.s, "cs");
   1.109 +
   1.110 +                    check("A.this.s", A.this.s, "as");
   1.111 +                    check("B.this.s", B.this.s, "bs");
   1.112 +                    check("C.this.s", C.this.s, "cs");
   1.113 +
   1.114 +                    //---
   1.115 +
   1.116 +                    check("this.t", this.t, "ct");
   1.117 +
   1.118 +                    check("A.this.t", A.this.t, "at");
   1.119 +                    check("B.this.t", B.this.t, "bt");
   1.120 +                    check("C.this.t", C.this.t, "ct");
   1.121 +
   1.122 +                    //---
   1.123 +
   1.124 +                    check("this.u", this.u, "cu");
   1.125 +
   1.126 +                    check("A.this.u", A.this.u, "au");
   1.127 +                    check("B.this.u", B.this.u, "bu");
   1.128 +                    check("C.this.u", C.this.u, "cu");
   1.129 +
   1.130 +                    //---
   1.131 +
   1.132 +                    check("super.u", super.u, "csu");
   1.133 +
   1.134 +                    check("A.super.u", A.super.u, "asu");
   1.135 +                    check("B.super.u", B.super.u, "bsu");
   1.136 +                    check("C.super.u", C.super.u, "csu");
   1.137 +
   1.138 +                    //---
   1.139 +
   1.140 +                    A.this.s = "foo";
   1.141 +                    System.out.println(A.this.s);
   1.142 +                    check("A.this.s", A.this.s, "foo");
   1.143 +                    B.this.s = "bar";
   1.144 +                    System.out.println(B.this.s);
   1.145 +                    check("B.this.s", B.this.s, "bar");
   1.146 +                    C.this.s = "baz";
   1.147 +                    System.out.println(C.this.s);
   1.148 +                    check("C.this.s", C.this.s, "baz");
   1.149 +
   1.150 +                    A.this.t = "foo";
   1.151 +                    System.out.println(A.this.t);
   1.152 +                    check("A.this.t", A.this.t, "foo");
   1.153 +                    B.this.t = "bar";
   1.154 +                    System.out.println(B.this.t);
   1.155 +                    check("B.this.t", B.this.t, "bar");
   1.156 +                    C.this.t = "baz";
   1.157 +                    System.out.println(C.this.t);
   1.158 +                    check("C.this.t", C.this.t, "baz");
   1.159 +
   1.160 +                    A.this.u = "foo";
   1.161 +                    System.out.println(A.this.u);
   1.162 +                    check("A.this.u", A.this.u, "foo");
   1.163 +                    B.this.u = "bar";
   1.164 +                    System.out.println(B.this.u);
   1.165 +                    check("B.this.u", B.this.u, "bar");
   1.166 +                    C.this.u = "baz";
   1.167 +                    System.out.println(C.this.u);
   1.168 +                    check("C.this.u", C.this.u, "baz");
   1.169 +
   1.170 +                    A.super.u = "foo";
   1.171 +                    System.out.println(A.super.u);
   1.172 +                    check("A.super.u", A.super.u, "foo");
   1.173 +                    B.super.u = "bar";
   1.174 +                    System.out.println(B.super.u);
   1.175 +                    check("B.super.u", B.super.u, "bar");
   1.176 +                    C.super.u = "baz";
   1.177 +                    System.out.println(C.super.u);
   1.178 +                    check("C.super.u", C.super.u, "baz");
   1.179 +
   1.180 +                }
   1.181 +            }
   1.182 +            void test() throws Exception {
   1.183 +                C c = new C();
   1.184 +                c.test();
   1.185 +            }
   1.186 +        }
   1.187 +        void test() throws Exception {
   1.188 +            B b = new B();
   1.189 +            b.test();
   1.190 +        }
   1.191 +    }
   1.192 +
   1.193 +    public static void main(String[] args) throws Exception {
   1.194 +        A a = new QualifiedThisAndSuper_2().new A();
   1.195 +        a.test();
   1.196 +    }
   1.197 +}

mercurial