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