langtools/test/tools/javac/QualifiedThisAndSuper_2.java
author jeff
Wed, 22 Jun 2011 10:10:54 -0700
changeset 9916 c35ecac744a5
parent 5520 86e4b9a9da40
permissions -rw-r--r--
7057046: Add embedded license to THIRD PARTY README Reviewed-by: lana
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     2
 * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
 * @test
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
 * @bug 4147520
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
 * @summary Verify correct implementation of qualified 'this' and 'super'.
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
 * @run compile QualifiedThisAndSuper_2.java
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
 * @run main QualifiedThisAndSuper_2
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import p1.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
public class QualifiedThisAndSuper_2 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
    void check(String expr, String result, String expected) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
        if (!result.equals(expected)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
            throw new Error("Evaluated "+ expr +
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
                            " : result " + result + ", expected " + expected);
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
    public class A extends p1.AS {
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
        A() { super(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
        String s = "as";
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
        private String t = "at";
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
        protected String u = "au";
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
        String m() { return "am"; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
        private String n() { return "an"; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
        protected String o() { return "ao"; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        public class B extends p1.BS {
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
            B() { super(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
            String s = "bs";
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
            private String t = "bt";
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
            protected String u = "bu";
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
            String m() { return "bm"; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
            private String n() { return "bn"; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
            protected String o() { return "bo"; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
            public class C extends p1.CS {
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
                C() { super(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
                String s = "cs";
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
                private String t = "ct";
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
                protected String u = "cu";
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
                String m() { return "cm"; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
                private String n() { return "cn"; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
                protected String o() { return "co"; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
                void test() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
                    check("this.m()", this.m(), "cm");
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
                    check("A.this.m()", A.this.m(), "am");
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
                    check("B.this.m()", B.this.m(), "bm");
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
                    check("C.this.m()", C.this.m(), "cm");
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
                    //---
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
                    check("this.n()", this.n(), "cn");
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
                    check("A.this.n()", A.this.n(), "an");
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
                    check("B.this.n()", B.this.n(), "bn");
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
                    check("C.this.n()", C.this.n(), "cn");
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
                    //---
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
                    check("this.o()", this.o(), "co");
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
                    check("A.this.o()", A.this.o(), "ao");
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
                    check("B.this.o()", B.this.o(), "bo");
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
                    check("C.this.o()", C.this.o(), "co");
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
                    check("super.o()", super.o(), "cso");
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
                    check("A.super.o()", A.super.o(), "aso");
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
                    check("B.super.o()", B.super.o(), "bso");
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
                    check("C.super.o()", C.super.o(), "cso");
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
                    // should re-use access methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
                    check("A.super.o()", A.super.o(), "aso");
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
                    check("B.super.o()", B.super.o(), "bso");
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                    check("C.super.o()", C.super.o(), "cso");
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
                    //---
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
                    check("this.s", this.s, "cs");
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
                    check("A.this.s", A.this.s, "as");
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
                    check("B.this.s", B.this.s, "bs");
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
                    check("C.this.s", C.this.s, "cs");
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
                    //---
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
                    check("this.t", this.t, "ct");
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
                    check("A.this.t", A.this.t, "at");
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
                    check("B.this.t", B.this.t, "bt");
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
                    check("C.this.t", C.this.t, "ct");
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
                    //---
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
                    check("this.u", this.u, "cu");
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
                    check("A.this.u", A.this.u, "au");
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
                    check("B.this.u", B.this.u, "bu");
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
                    check("C.this.u", C.this.u, "cu");
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
                    //---
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
                    check("super.u", super.u, "csu");
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
                    check("A.super.u", A.super.u, "asu");
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
                    check("B.super.u", B.super.u, "bsu");
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
                    check("C.super.u", C.super.u, "csu");
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
                    //---
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
                    A.this.s = "foo";
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
                    System.out.println(A.this.s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
                    check("A.this.s", A.this.s, "foo");
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
                    B.this.s = "bar";
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
                    System.out.println(B.this.s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
                    check("B.this.s", B.this.s, "bar");
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                    C.this.s = "baz";
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
                    System.out.println(C.this.s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
                    check("C.this.s", C.this.s, "baz");
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
                    A.this.t = "foo";
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
                    System.out.println(A.this.t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
                    check("A.this.t", A.this.t, "foo");
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
                    B.this.t = "bar";
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
                    System.out.println(B.this.t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
                    check("B.this.t", B.this.t, "bar");
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
                    C.this.t = "baz";
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
                    System.out.println(C.this.t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
                    check("C.this.t", C.this.t, "baz");
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                    A.this.u = "foo";
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                    System.out.println(A.this.u);
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
                    check("A.this.u", A.this.u, "foo");
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
                    B.this.u = "bar";
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                    System.out.println(B.this.u);
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
                    check("B.this.u", B.this.u, "bar");
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
                    C.this.u = "baz";
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                    System.out.println(C.this.u);
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
                    check("C.this.u", C.this.u, "baz");
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
                    A.super.u = "foo";
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
                    System.out.println(A.super.u);
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
                    check("A.super.u", A.super.u, "foo");
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
                    B.super.u = "bar";
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
                    System.out.println(B.super.u);
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
                    check("B.super.u", B.super.u, "bar");
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
                    C.super.u = "baz";
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
                    System.out.println(C.super.u);
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
                    check("C.super.u", C.super.u, "baz");
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
            void test() throws Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
                C c = new C();
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
                c.test();
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        void test() throws Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
            B b = new B();
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
            b.test();
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    public static void main(String[] args) throws Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        A a = new QualifiedThisAndSuper_2().new A();
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        a.test();
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
}