test/tools/javac/QualifiedThisAndSuper_3.java

Wed, 13 Aug 2014 14:50:00 -0700

author
katleman
date
Wed, 13 Aug 2014 14:50:00 -0700
changeset 2549
0b6cc4ea670f
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u40-b01 for changeset bf89a471779d

     1 /*
     2  * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 4147520
    27  * @summary Verify correct implementation of qualified 'this' and 'super'.
    28  * @author maddox
    29  *
    30  * @run compile QualifiedThisAndSuper_3.java
    31  * @run main QualifiedThisAndSuper_3
    32  */
    34 class AS {
    35     String s = "ass";
    36     private String t = "ast";
    37     protected String u = "asu";
    38     String m() { return "asm"; }
    39     private String n() { return "asn"; }
    40     protected String o() { return "aso"; }
    42     static String xs = "xass";
    43     static private String xt = "xast";
    44     static protected String xu = "xasu";
    45     static String xm() { return "xasm"; }
    46     static private String xn() { return "xasn"; }
    47     static protected String xo() { return "xaso"; }
    48 }
    50 class BS {
    51     String s = "bss";
    52     private String t = "bst";
    53     protected String u = "bsu";
    54     String m() { return "bsm"; }
    55     private String n() { return "bsn"; }
    56     protected String o() { return "bso"; }
    57 }
    59 class CS {
    60     String s = "css";
    61     private String t = "cst";
    62     protected String u = "csu";
    63     String m() { return "csm"; }
    64     private String n() { return "csn"; }
    65     protected String o() { return "cso"; }
    66 }
    68 public class QualifiedThisAndSuper_3 extends AS {
    70     void check(String expr, String result, String expected) {
    71         if (!result.equals(expected)) {
    72             throw new Error("Evaluated "+ expr +
    73                             " : result " + result + ", expected " + expected);
    74         }
    75     }
    78     QualifiedThisAndSuper_3() { super(); }
    79     String s = "as";
    80     private String t = "at";
    81     protected String u = "au";
    82     String m() { return "am"; }
    83     private String n() { return "an"; }
    84     protected String o() { return "ao"; }
    86     static String xs = "xas";
    87     static private String xt = "xat";
    88     static protected String xu = "xau";
    89     static String xm() { return "xam"; }
    90     static private String xn() { return "xan"; }
    91     static protected String xo() { return "xao"; }
    93     public class B extends BS {
    94         B() { super(); }
    95         String s = "bs";
    96         private String t = "bt";
    97         protected String u = "bu";
    98         String m() { return "bm"; }
    99         private String n() { return "bn"; }
   100         protected String o() { return "bo"; }
   101         public class C extends CS {
   102             C() { super(); }
   103             String s = "cs";
   104             private String t = "ct";
   105             protected String u = "cu";
   106             String m() { return "cm"; }
   107             private String n() { return "cn"; }
   108             protected String o() { return "co"; }
   109             void test() {
   111                 check("QualifiedThisAndSuper_3.super.xm()", QualifiedThisAndSuper_3.super.xm(), "xasm");
   112                 // Private to another package-member class: not accessible
   113                 // check("QualifiedThisAndSuper_3.super.xn()", QualifiedThisAndSuper_3.super.xn(), "xasn");
   114                 check("QualifiedThisAndSuper_3.super.xo()", QualifiedThisAndSuper_3.super.xo(), "xaso");
   116                 check("QualifiedThisAndSuper_3.super.xs", QualifiedThisAndSuper_3.super.xs, "xass");
   117                 // Private to another package-member class: not accessible
   118                 // check("QualifiedThisAndSuper_3.super.xt", QualifiedThisAndSuper_3.super.xt, "xast");
   119                 check("QualifiedThisAndSuper_3.super.xu", QualifiedThisAndSuper_3.super.xu, "xasu");
   121                 check("QualifiedThisAndSuper_3.this.xm()", QualifiedThisAndSuper_3.this.xm(), "xam");
   122                 check("QualifiedThisAndSuper_3.this.xn()", QualifiedThisAndSuper_3.this.xn(), "xan");
   123                 check("QualifiedThisAndSuper_3.this.xo()", QualifiedThisAndSuper_3.this.xo(), "xao");
   125                 check("QualifiedThisAndSuper_3.this.xs", QualifiedThisAndSuper_3.this.xs, "xas");
   126                 check("QualifiedThisAndSuper_3.this.xt", QualifiedThisAndSuper_3.this.xt, "xat");
   127                 check("QualifiedThisAndSuper_3.this.xu", QualifiedThisAndSuper_3.this.xu, "xau");
   129                 //---
   131                 check("this.m()", this.m(), "cm");
   133                 check("QualifiedThisAndSuper_3.this.m()", QualifiedThisAndSuper_3.this.m(), "am");
   134                 check("B.this.m()", B.this.m(), "bm");
   135                 check("C.this.m()", C.this.m(), "cm");
   137                 check("super.m()", super.m(), "csm");
   139                 check("QualifiedThisAndSuper_3.super.m()", QualifiedThisAndSuper_3.super.m(), "asm");
   140                 check("B.super.m()", B.super.m(), "bsm");
   141                 check("C.super.m()", C.super.m(), "csm");
   143                 // should re-use access methods.
   144                 check("QualifiedThisAndSuper_3.super.m()", QualifiedThisAndSuper_3.super.m(), "asm");
   145                 check("B.super.m()", B.super.m(), "bsm");
   146                 check("C.super.m()", C.super.m(), "csm");
   148                 //---
   150                 check("this.n()", this.n(), "cn");
   152                 check("QualifiedThisAndSuper_3.this.n()", QualifiedThisAndSuper_3.this.n(), "an");
   153                 check("B.this.n()", B.this.n(), "bn");
   154                 check("C.this.n()", C.this.n(), "cn");
   156                 /*****
   157                 check("super.n()", super.n(), "csn");
   159                 check("QualifiedThisAndSuper_3.super.n()", QualifiedThisAndSuper_3.super.n(), "asn");
   160                 check("B.super.n()", B.super.n(), "bsn");
   161                 check("C.super.n()", C.super.n(), "csn");
   163                 // should re-use access methods.
   164                 check("QualifiedThisAndSuper_3.super.n()", QualifiedThisAndSuper_3.super.n(), "asn");
   165                 check("B.super.n()", B.super.n(), "bsn");
   166                 check("C.super.n()", C.super.n(), "csn");
   167                 *****/
   169                 //---
   171                 check("this.o()", this.o(), "co");
   173                 check("QualifiedThisAndSuper_3.this.o()", QualifiedThisAndSuper_3.this.o(), "ao");
   174                 check("B.this.o()", B.this.o(), "bo");
   175                 check("C.this.o()", C.this.o(), "co");
   177                 check("super.o()", super.o(), "cso");
   179                 check("QualifiedThisAndSuper_3.super.o()", QualifiedThisAndSuper_3.super.o(), "aso");
   180                 check("B.super.o()", B.super.o(), "bso");
   181                 check("C.super.o()", C.super.o(), "cso");
   183                 // should re-use access methods.
   184                 check("QualifiedThisAndSuper_3.super.o()", QualifiedThisAndSuper_3.super.o(), "aso");
   185                 check("B.super.o()", B.super.o(), "bso");
   186                 check("C.super.o()", C.super.o(), "cso");
   188                 //---
   190                 check("this.s", this.s, "cs");
   192                 check("QualifiedThisAndSuper_3.this.s", QualifiedThisAndSuper_3.this.s, "as");
   193                 check("B.this.s", B.this.s, "bs");
   194                 check("C.this.s", C.this.s, "cs");
   196                 //---
   198                 check("this.t", this.t, "ct");
   200                 check("QualifiedThisAndSuper_3.this.t", QualifiedThisAndSuper_3.this.t, "at");
   201                 check("B.this.t", B.this.t, "bt");
   202                 check("C.this.t", C.this.t, "ct");
   204                 //---
   206                 check("this.u", this.u, "cu");
   208                 check("QualifiedThisAndSuper_3.this.u", QualifiedThisAndSuper_3.this.u, "au");
   209                 check("B.this.u", B.this.u, "bu");
   210                 check("C.this.u", C.this.u, "cu");
   212                 //---
   214                 check("super.s", super.s, "css");
   216                 check("QualifiedThisAndSuper_3.super.s", QualifiedThisAndSuper_3.super.s, "ass");
   217                 check("B.super.s", B.super.s, "bss");
   218                 check("C.super.s", C.super.s, "css");
   220                 //---
   222                 /*****
   223                 check("super.t", super.t, "cst");
   225                 check("QualifiedThisAndSuper_3.super.t", QualifiedThisAndSuper_3.super.t, "ast");
   226                 check("B.super.t", B.super.t, "bst");
   227                 check("C.super.t", C.super.t, "cst");
   228                 *****/
   230                 //---
   232                 check("super.u", super.u, "csu");
   234                 check("QualifiedThisAndSuper_3.super.u", QualifiedThisAndSuper_3.super.u, "asu");
   235                 check("B.super.u", B.super.u, "bsu");
   236                 check("C.super.u", C.super.u, "csu");
   238                 //---
   240                 QualifiedThisAndSuper_3.this.s = "foo";
   241                 System.out.println(QualifiedThisAndSuper_3.this.s);
   242                 check("QualifiedThisAndSuper_3.this.s", QualifiedThisAndSuper_3.this.s, "foo");
   243                 B.this.s = "bar";
   244                 System.out.println(B.this.s);
   245                 check("B.this.s", B.this.s, "bar");
   246                 C.this.s = "baz";
   247                 System.out.println(C.this.s);
   248                 check("C.this.s", C.this.s, "baz");
   250                 QualifiedThisAndSuper_3.this.t = "foo";
   251                 System.out.println(QualifiedThisAndSuper_3.this.t);
   252                 check("QualifiedThisAndSuper_3.this.t", QualifiedThisAndSuper_3.this.t, "foo");
   253                 B.this.t = "bar";
   254                 System.out.println(B.this.t);
   255                 check("B.this.t", B.this.t, "bar");
   256                 C.this.t = "baz";
   257                 System.out.println(C.this.t);
   258                 check("C.this.t", C.this.t, "baz");
   260                 QualifiedThisAndSuper_3.this.u = "foo";
   261                 System.out.println(QualifiedThisAndSuper_3.this.u);
   262                 check("QualifiedThisAndSuper_3.this.u", QualifiedThisAndSuper_3.this.u, "foo");
   263                 B.this.u = "bar";
   264                 System.out.println(B.this.u);
   265                 check("B.this.u", B.this.u, "bar");
   266                 C.this.u = "baz";
   267                 System.out.println(C.this.u);
   268                 check("C.this.u", C.this.u, "baz");
   270                 QualifiedThisAndSuper_3.super.s = "foo";
   271                 System.out.println(QualifiedThisAndSuper_3.super.s);
   272                 check("QualifiedThisAndSuper_3.super.s", QualifiedThisAndSuper_3.super.s, "foo");
   273                 B.super.s = "bar";
   274                 System.out.println(B.super.s);
   275                 check("B.super.s", B.super.s, "bar");
   276                 C.super.s = "baz";
   277                 System.out.println(C.super.s);
   278                 check("C.super.s", C.super.s, "baz");
   280                 /*****
   281                 QualifiedThisAndSuper_3.super.t = "foo";
   282                 System.out.println(QualifiedThisAndSuper_3.super.t);
   283                 check("QualifiedThisAndSuper_3.super.t", QualifiedThisAndSuper_3.super.t, "foo");
   284                 B.super.t = "bar";
   285                 System.out.println(B.super.t);
   286                 check("B.super.t", B.super.t, "bar");
   287                 C.super.t = "baz";
   288                 System.out.println(C.super.t);
   289                 check("C.super.t", C.super.t, "baz");
   290                 *****/
   292                 QualifiedThisAndSuper_3.super.u = "foo";
   293                 System.out.println(QualifiedThisAndSuper_3.super.u);
   294                 check("QualifiedThisAndSuper_3.super.u", QualifiedThisAndSuper_3.super.u, "foo");
   295                 B.super.u = "bar";
   296                 System.out.println(B.super.u);
   297                 check("B.super.u", B.super.u, "bar");
   298                 C.super.u = "baz";
   299                 System.out.println(C.super.u);
   300                 check("C.super.u", C.super.u, "baz");
   302             }
   303         }
   304         void test() throws Exception {
   305             C c = new C();
   306             c.test();
   307         }
   308     }
   309     void test() throws Exception {
   310         B b = new B();
   311         b.test();
   312     }
   314     public static void main(String[] args) throws Exception {
   315         QualifiedThisAndSuper_3 a = new QualifiedThisAndSuper_3();
   316         a.test();
   317     }
   318 }

mercurial