1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javap/output/RepeatingTypeAnnotations.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,427 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 8005220 1.30 + * @summary javap must display repeating annotations 1.31 + */ 1.32 +import java.io.*; 1.33 +import java.util.*; 1.34 + 1.35 +/** 1.36 + * This class extends the abstract {@link Tester} test-driver, and 1.37 + * encapusulates a number of test-case classes (i.e. classes extending 1.38 + * this class and annotated with {@code TestCase}). 1.39 + * <p> 1.40 + * By default (no argument), this test runs all test-cases, except 1.41 + * if annotated with {@code ignore}. 1.42 + * <p> 1.43 + * Individual test cases can be executed using a run action. 1.44 + * <p> 1.45 + * Example: @run main RepeatingTypeAnnotations RepeatingTypeAnnotations$TC4 1.46 + * <p> 1.47 + * Note: when specific test-cases are run, additional debug output is 1.48 + * produced to help debugging. Test annotated with {@code ignore} 1.49 + * can be executed explicitly. 1.50 + */ 1.51 +public class RepeatingTypeAnnotations extends Tester { 1.52 + 1.53 + /** 1.54 + * Main method instantiates test and run test-cases. 1.55 + */ 1.56 + public static void main(String... args) throws Exception { 1.57 + Tester tester = new RepeatingTypeAnnotations(); 1.58 + tester.run(args); 1.59 + } 1.60 + 1.61 + /** 1.62 + * Testcases are classes extending {@code RepeatingTypeAnnotations}, 1.63 + * and calling {@link setSrc}, followed by one or more invocations 1.64 + * of {@link verify} in the body of the constructor. 1.65 + */ 1.66 + public RepeatingTypeAnnotations() { 1.67 + setSrc(new TestSource(template)); 1.68 + } 1.69 + 1.70 + /** 1.71 + * Common template for test cases. The line TESTCASE is 1.72 + * replaced with the specific lines of individual tests. 1.73 + */ 1.74 + private static final String[] template = { 1.75 + "import java.lang.annotation.*;", 1.76 + "class Test {", 1.77 + " @Repeatable(As.class)", 1.78 + " @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})", 1.79 + " @Retention(RetentionPolicy.CLASS)", 1.80 + " @interface A {", 1.81 + " Class f() default int.class;", 1.82 + " }", 1.83 + 1.84 + " @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})", 1.85 + " @Retention(RetentionPolicy.CLASS)", 1.86 + " @interface As { A[] value(); }", 1.87 + 1.88 + " @Repeatable(Bs.class)", 1.89 + " @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})", 1.90 + " @Retention(RetentionPolicy.CLASS)", 1.91 + " @interface B {", 1.92 + " Class f() default int.class;", 1.93 + " }", 1.94 + 1.95 + " @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})", 1.96 + " @Retention(RetentionPolicy.CLASS)", 1.97 + " @interface Bs { B[] value(); }", 1.98 + 1.99 + " @Repeatable(Cs.class)", 1.100 + " @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})", 1.101 + " @Retention(RetentionPolicy.RUNTIME)", 1.102 + " @interface C {", 1.103 + " Class f() default int.class;", 1.104 + " }", 1.105 + 1.106 + " @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})", 1.107 + " @Retention(RetentionPolicy.RUNTIME)", 1.108 + " @interface Cs { C[] value(); }", 1.109 + "TESTCASE", 1.110 + "}" 1.111 + }; 1.112 + 1.113 + /* 1.114 + * The test cases covers annotation in the following locations: 1.115 + * - static and non-static fields 1.116 + * - local variables 1.117 + * - constructor and method return type and parameter types 1.118 + * - casts in class and method contexts. 1.119 + * For the above locations the test-cases covers: 1.120 + * - single annotation type 1.121 + * - two annotation types with same retention 1.122 + * - two annotation types with different retention 1.123 + * - three annotation types, two of same retention, one different. 1.124 + */ 1.125 + 1.126 + @TestCase 1.127 + public static class TC1 extends RepeatingTypeAnnotations { 1.128 + public TC1() { 1.129 + setSrc(" /* TC1 */ ", 1.130 + " static String so = \"hello world\";", 1.131 + " public @A @A @A Object o = (@A @A @A String) Test.so;"); 1.132 + verify("RuntimeInvisibleTypeAnnotations", 1.133 + "0: #25(#26=[@#27(),@#27(),@#27()]): FIELD", 1.134 + "0: #25(#26=[@#27(),@#27(),@#27()]): CAST, offset=5, type_index=0"); 1.135 + } 1.136 + } 1.137 + 1.138 + @TestCase 1.139 + public static class TC2 extends RepeatingTypeAnnotations { 1.140 + public TC2() { 1.141 + setSrc(" /* TC2 */ ", 1.142 + " static String so = \"hello world\";", 1.143 + " public @A @B @A Object o = (@B @A @B String) Test.so;"); 1.144 + verify("RuntimeInvisibleTypeAnnotations", 1.145 + "0: #25(#26=[@#27(),@#27()]): FIELD", 1.146 + "1: #28(): FIELD", 1.147 + "0: #36(#26=[@#28(),@#28()]): CAST, offset=5, type_index=0", 1.148 + "1: #27(): CAST, offset=5, type_index=0"); 1.149 + } 1.150 + } 1.151 + 1.152 + @TestCase 1.153 + public static class TC3 extends RepeatingTypeAnnotations { 1.154 + public TC3() { 1.155 + setSrc(" /* TC3 */ ", 1.156 + " static String so = \"hello world\";", 1.157 + " public @A @A @C Object o = (@B @C @B String) Test.so;"); 1.158 + verify("RuntimeVisibleTypeAnnotations", 1.159 + "RuntimeInvisibleTypeAnnotations", 1.160 + "0: #25(): FIELD", 1.161 + "0: #27(#28=[@#29(),@#29()]): FIELD", 1.162 + "0: #25(): CAST, offset=5, type_index=0", 1.163 + "0: #37(#28=[@#38(),@#38()]): CAST, offset=5, type_index=0"); 1.164 + } 1.165 + } 1.166 + 1.167 + @TestCase 1.168 + public static class TC4 extends RepeatingTypeAnnotations { 1.169 + public TC4() { 1.170 + setSrc(" /* TC4 */ ", 1.171 + " static String so = \"hello world\";", 1.172 + " public @A @B @C Object o = (@C @B @A String) Test.so;"); 1.173 + verify("RuntimeInvisibleTypeAnnotations", 1.174 + "RuntimeVisibleTypeAnnotations", 1.175 + "0: #25(): FIELD", 1.176 + "0: #27(): FIELD", 1.177 + "1: #28(): FIELD", 1.178 + "0: #25(): CAST, offset=5, type_index=0", 1.179 + "0: #28(): CAST, offset=5, type_index=0", 1.180 + "1: #27(): CAST, offset=5, type_index=0"); 1.181 + } 1.182 + } 1.183 + 1.184 + @TestCase 1.185 + public static class TC5 extends RepeatingTypeAnnotations { 1.186 + public TC5() { 1.187 + setSrc(" /* TC5 */ ", 1.188 + " static String so = \"hello world\";", 1.189 + " public static @A @A @A Object o = (@B @B @B String) Test.so;"); 1.190 + verify("RuntimeInvisibleTypeAnnotations", 1.191 + "0: #25(#26=[@#27(),@#27(),@#27()]): FIELD", 1.192 + "0: #36(#26=[@#37(),@#37(),@#37()]): CAST, offset=5, type_index=0"); 1.193 + } 1.194 + } 1.195 + 1.196 + @TestCase 1.197 + public static class TC6 extends RepeatingTypeAnnotations { 1.198 + public TC6() { 1.199 + setSrc(" /* TC6 */ ", 1.200 + " static String so = \"hello world\";", 1.201 + " public static @A @B @A Object o = (@B @A @B String) Test.so;"); 1.202 + verify("RuntimeInvisibleTypeAnnotations", 1.203 + "0: #25(#26=[@#27(),@#27()]): FIELD", 1.204 + "1: #28(): FIELD", 1.205 + "0: #37(#26=[@#28(),@#28()]): CAST, offset=5, type_index=0", 1.206 + "1: #27(): CAST, offset=5, type_index=0"); 1.207 + } 1.208 + } 1.209 + 1.210 + @TestCase 1.211 + public static class TC7 extends RepeatingTypeAnnotations { 1.212 + public TC7() { 1.213 + setSrc(" /* TC7 */ ", 1.214 + " static String so = \"hello world\";", 1.215 + " public static @A @A @C Object o = (@B @C @B String) Test.so;"); 1.216 + verify("RuntimeVisibleTypeAnnotations", 1.217 + "RuntimeInvisibleTypeAnnotations", 1.218 + "0: #25(): FIELD", 1.219 + "0: #27(#28=[@#29(),@#29()]): FIELD", 1.220 + "0: #25(): CAST, offset=5, type_index=0", 1.221 + "0: #38(#28=[@#39(),@#39()]): CAST, offset=5, type_index=0"); 1.222 + } 1.223 + } 1.224 + 1.225 + @TestCase 1.226 + public static class TC8 extends RepeatingTypeAnnotations { 1.227 + public TC8() { 1.228 + setSrc(" /* TC8 */ ", 1.229 + " static String so = \"hello world\";", 1.230 + " public static @A @B @C Object o = (@C @B @A String) Test.so;"); 1.231 + 1.232 + verify("RuntimeVisibleTypeAnnotations", 1.233 + "RuntimeInvisibleTypeAnnotations", 1.234 + "0: #25(): FIELD", 1.235 + "0: #27(): FIELD", 1.236 + "1: #28(): FIELD", 1.237 + "0: #25(): CAST, offset=5, type_index=0", 1.238 + "0: #28(): CAST, offset=5, type_index=0", 1.239 + "1: #27(): CAST, offset=5, type_index=0"); 1.240 + } 1.241 + } 1.242 + 1.243 + @TestCase 1.244 + public static class TC9 extends RepeatingTypeAnnotations { 1.245 + public TC9() { 1.246 + setSrc(" /* TC9 */ ", 1.247 + " public Test(@A @A @A Object o, @A int i, long l) {", 1.248 + " @A @A @A String ls = (@B @B @B String) o;", 1.249 + " }"); 1.250 + verify("RuntimeInvisibleTypeAnnotations", 1.251 + "0: #34(#35=[@#36(),@#36(),@#36()]): CAST, offset=4, type_index=0", 1.252 + "1: #37(#35=[@#38(),@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", 1.253 + "RuntimeInvisibleTypeAnnotations", 1.254 + "0: #37(#35=[@#38(),@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0", 1.255 + "1: #38(): METHOD_FORMAL_PARAMETER, param_index=1"); 1.256 + } 1.257 + } 1.258 + 1.259 + @TestCase 1.260 + public static class TC10 extends RepeatingTypeAnnotations { 1.261 + public TC10() { 1.262 + setSrc(" /* TC10 */ ", 1.263 + " public Test(@A @A @B Object o, @A @B int i, long l) {", 1.264 + " @A @A @B String ls = (@B @A @B String) o;", 1.265 + " }"); 1.266 + verify("RuntimeInvisibleTypeAnnotations", 1.267 + "0: #34(#35=[@#36(),@#36()]): CAST, offset=4, type_index=0", 1.268 + "1: #37(): CAST, offset=4, type_index=0", 1.269 + "2: #38(#35=[@#37(),@#37()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", 1.270 + "3: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", 1.271 + "RuntimeInvisibleTypeAnnotations", 1.272 + "0: #38(#35=[@#37(),@#37()]): METHOD_FORMAL_PARAMETER, param_index=0", 1.273 + "1: #36(): METHOD_FORMAL_PARAMETER, param_index=0", 1.274 + "2: #37(): METHOD_FORMAL_PARAMETER, param_index=1", 1.275 + "3: #36(): METHOD_FORMAL_PARAMETER, param_index=1"); 1.276 + } 1.277 + } 1.278 + 1.279 + @TestCase 1.280 + public static class TC11 extends RepeatingTypeAnnotations { 1.281 + public TC11() { 1.282 + setSrc(" /* TC11 */ ", 1.283 + " public Test(@C @C @A Object o, @A @B int i, long l) {", 1.284 + " @C @C @A String ls = (@A @A @C String) o;", 1.285 + " }"); 1.286 + verify("RuntimeVisibleTypeAnnotations", 1.287 + "RuntimeInvisibleTypeAnnotations", 1.288 + "0: #34(): CAST, offset=4, type_index=0", 1.289 + "1: #35(#36=[@#34(),@#34()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", 1.290 + "0: #38(#36=[@#39(),@#39()]): CAST, offset=4, type_index=0", 1.291 + "1: #39(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", 1.292 + "0: #35(#36=[@#34(),@#34()]): METHOD_FORMAL_PARAMETER, param_index=0", 1.293 + "0: #39(): METHOD_FORMAL_PARAMETER, param_index=0", 1.294 + "1: #39(): METHOD_FORMAL_PARAMETER, param_index=1", 1.295 + "2: #40(): METHOD_FORMAL_PARAMETER, param_index=1"); 1.296 + } 1.297 + } 1.298 + 1.299 + @TestCase 1.300 + public static class TC12 extends RepeatingTypeAnnotations { 1.301 + public TC12() { 1.302 + setSrc(" /* TC12 */ ", 1.303 + " public Test(@A @B @C Object o, @A @C int i, long l) {", 1.304 + " @A @B @C String ls = (@C @A @B String) o;", 1.305 + " }"); 1.306 + verify("RuntimeVisibleTypeAnnotations", 1.307 + "0: #34(): CAST, offset=4, type_index=0", 1.308 + "1: #34(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", 1.309 + "RuntimeInvisibleTypeAnnotations", 1.310 + "0: #36(): CAST, offset=4, type_index=0", 1.311 + "1: #37(): CAST, offset=4, type_index=0", 1.312 + "2: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", 1.313 + "3: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", 1.314 + "0: #34(): METHOD_FORMAL_PARAMETER, param_index=0", 1.315 + "1: #34(): METHOD_FORMAL_PARAMETER, param_index=1", 1.316 + "0: #36(): METHOD_FORMAL_PARAMETER, param_index=0", 1.317 + "1: #37(): METHOD_FORMAL_PARAMETER, param_index=0", 1.318 + "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1"); 1.319 + } 1.320 + } 1.321 + 1.322 + @TestCase 1.323 + public static class TC13 extends RepeatingTypeAnnotations { 1.324 + public TC13() { 1.325 + setSrc(" /* TC13 */ ", 1.326 + " public @A @A @A String foo(@A @A @A Object o, @A int i, long l) {", 1.327 + " @A @A @A String ls = (@B @B @B String) o;", 1.328 + " return (@A @A @A String) o;", 1.329 + " }"); 1.330 + verify("RuntimeInvisibleTypeAnnotations", 1.331 + "0: #36(#37=[@#38(),@#38(),@#38()]): CAST, offset=0, type_index=0", 1.332 + "1: #39(#37=[@#40(),@#40(),@#40()]): CAST, offset=6, type_index=0", 1.333 + "2: #39(#37=[@#40(),@#40(),@#40()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", 1.334 + "RuntimeInvisibleTypeAnnotations", 1.335 + "0: #39(#37=[@#40(),@#40(),@#40()]): METHOD_RETURN", 1.336 + "1: #39(#37=[@#40(),@#40(),@#40()]): METHOD_FORMAL_PARAMETER, param_index=0", 1.337 + "2: #40(): METHOD_FORMAL_PARAMETER, param_index=1"); 1.338 + } 1.339 + } 1.340 + 1.341 + @TestCase 1.342 + public static class TC14 extends RepeatingTypeAnnotations { 1.343 + public TC14() { 1.344 + setSrc(" /* TC14 */ ", 1.345 + " public @A @B @B String foo(@A @A @B Object o, @A @B int i, long l) {", 1.346 + " @A @A @B String ls = (@B @A @B String) o;", 1.347 + " return (@A @B @B String) o;", 1.348 + " }"); 1.349 + verify( 1.350 + "RuntimeInvisibleTypeAnnotations:", 1.351 + "0: #36(#37=[@#38(),@#38()]): CAST, offset=0, type_index=0", 1.352 + "1: #39(): CAST, offset=0, type_index=0", 1.353 + "2: #39(): CAST, offset=6, type_index=0", 1.354 + "3: #36(#37=[@#38(),@#38()]): CAST, offset=6, type_index=0", 1.355 + "4: #40(#37=[@#39(),@#39()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", 1.356 + "5: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", 1.357 + "RuntimeInvisibleTypeAnnotations:", 1.358 + "0: #39(): METHOD_RETURN", 1.359 + "1: #36(#37=[@#38(),@#38()]): METHOD_RETURN", 1.360 + "2: #40(#37=[@#39(),@#39()]): METHOD_FORMAL_PARAMETER, param_index=0", 1.361 + "3: #38(): METHOD_FORMAL_PARAMETER, param_index=0", 1.362 + "4: #39(): METHOD_FORMAL_PARAMETER, param_index=1", 1.363 + "5: #38(): METHOD_FORMAL_PARAMETER, param_index=1" 1.364 + ); 1.365 + } 1.366 + } 1.367 + 1.368 + @TestCase 1.369 + public static class TC15 extends RepeatingTypeAnnotations { 1.370 + public TC15() { 1.371 + setSrc(" /* TC15 */ ", 1.372 + " public @A @A @C String foo(@C @C @A Object o, @A @B int i, long l) {", 1.373 + " @C @C @A String ls = (@A @A @C String) o;", 1.374 + " return (@C @B @B String) o;", 1.375 + " }"); 1.376 + verify( 1.377 + "RuntimeVisibleTypeAnnotations:", 1.378 + "0: #36(): CAST, offset=0, type_index=0", 1.379 + "1: #36(): CAST, offset=6, type_index=0", 1.380 + "2: #37(#38=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", 1.381 + "RuntimeInvisibleTypeAnnotations:", 1.382 + "0: #40(#38=[@#41(),@#41()]): CAST, offset=0, type_index=0", 1.383 + "1: #42(#38=[@#43(),@#43()]): CAST, offset=6, type_index=0", 1.384 + "2: #41(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", 1.385 + "RuntimeVisibleTypeAnnotations:", 1.386 + "0: #36(): METHOD_RETURN", 1.387 + "1: #37(#38=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0", 1.388 + "RuntimeInvisibleTypeAnnotations:", 1.389 + "0: #40(#38=[@#41(),@#41()]): METHOD_RETURN", 1.390 + "1: #41(): METHOD_FORMAL_PARAMETER, param_index=0", 1.391 + "2: #41(): METHOD_FORMAL_PARAMETER, param_index=1", 1.392 + "3: #43(): METHOD_FORMAL_PARAMETER, param_index=1" 1.393 + ); 1.394 + } 1.395 + } 1.396 + 1.397 + @TestCase 1.398 + public static class TC16 extends RepeatingTypeAnnotations { 1.399 + public TC16() { 1.400 + setSrc(" /* TC16 */ ", 1.401 + " public @A @B @C String foo(@A @B @C Object o, @A @C int i, long l) {", 1.402 + " @A @B @C String ls = (@C @A @B String) o;", 1.403 + " return (@B @A @C String) o;", 1.404 + " }"); 1.405 + verify( 1.406 + "RuntimeVisibleTypeAnnotations:", 1.407 + "0: #36(): CAST, offset=0, type_index=0", 1.408 + "1: #36(): CAST, offset=6, type_index=0", 1.409 + "2: #36(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", 1.410 + "RuntimeInvisibleTypeAnnotations:", 1.411 + "0: #38(): CAST, offset=0, type_index=0", 1.412 + "1: #39(): CAST, offset=0, type_index=0", 1.413 + "2: #39(): CAST, offset=6, type_index=0", 1.414 + "3: #38(): CAST, offset=6, type_index=0", 1.415 + "4: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", 1.416 + "5: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", 1.417 + "RuntimeVisibleTypeAnnotations:", 1.418 + "0: #36(): METHOD_RETURN", 1.419 + "1: #36(): METHOD_FORMAL_PARAMETER, param_index=0", 1.420 + "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1", 1.421 + "RuntimeInvisibleTypeAnnotations:", 1.422 + "0: #38(): METHOD_RETURN", 1.423 + "1: #39(): METHOD_RETURN", 1.424 + "2: #38(): METHOD_FORMAL_PARAMETER, param_index=0", 1.425 + "3: #39(): METHOD_FORMAL_PARAMETER, param_index=0", 1.426 + "4: #38(): METHOD_FORMAL_PARAMETER, param_index=1" 1.427 + ); 1.428 + } 1.429 + } 1.430 +}