1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javap/output/RepeatingTypeAnnotations.java Mon Mar 18 08:46:09 2013 -0700 1.3 @@ -0,0 +1,400 @@ 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 + @ignore // 8008082:missing type annotation for cast 1.128 + public static class TC1 extends RepeatingTypeAnnotations { 1.129 + public TC1() { 1.130 + setSrc(" 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 + "1: #25(#26=[@#27(),@#27(),@#27()]): CAST, offset=5"); 1.135 + } 1.136 + } 1.137 + 1.138 + @TestCase 1.139 + public static class TC2 extends RepeatingTypeAnnotations { 1.140 + public TC2() { 1.141 + setSrc(" static String so = \"hello world\";", 1.142 + " public @A @B @A Object o = (@B @A @B String) Test.so;"); 1.143 + verify("RuntimeInvisibleTypeAnnotations", 1.144 + "0: #25(#26=[@#27(),@#27()]): FIELD", 1.145 + "1: #28(): FIELD", 1.146 + "2: #29(#26=[@#28(),@#28()]): CAST, offset=5", 1.147 + "3: #27(): CAST, offset=5"); 1.148 + } 1.149 + } 1.150 + 1.151 + @TestCase 1.152 + public static class TC3 extends RepeatingTypeAnnotations { 1.153 + public TC3() { 1.154 + setSrc(" static String so = \"hello world\";", 1.155 + " public @A @A @C Object o = (@B @C @B String) Test.so;"); 1.156 + verify("RuntimeInvisibleTypeAnnotations", 1.157 + "0: #25(): FIELD", 1.158 + "1: #25(): CAST, offset=5", 1.159 + "RuntimeVisibleTypeAnnotations", 1.160 + "0: #27(#28=[@#29(),@#29()]): FIELD", 1.161 + "1: #30(#28=[@#31(),@#31()]): CAST, offset=5"); 1.162 + } 1.163 + } 1.164 + 1.165 + @TestCase 1.166 + public static class TC4 extends RepeatingTypeAnnotations { 1.167 + public TC4() { 1.168 + setSrc(" static String so = \"hello world\";", 1.169 + " public @A @B @C Object o = (@C @B @A String) Test.so;"); 1.170 + verify("RuntimeInvisibleTypeAnnotations", 1.171 + "RuntimeVisibleTypeAnnotations", 1.172 + "0: #25(): FIELD", 1.173 + "1: #25(): CAST, offset=5", 1.174 + "0: #27(): FIELD", 1.175 + "1: #28(): FIELD", 1.176 + "2: #28(): CAST, offset=5", 1.177 + "3: #27(): CAST, offset=5"); 1.178 + } 1.179 + } 1.180 + 1.181 + @TestCase 1.182 + @ignore // 8008082:missing type annotation for cast 1.183 + public static class TC5 extends RepeatingTypeAnnotations { 1.184 + public TC5() { 1.185 + setSrc(" static String so = \"hello world\";", 1.186 + " public static @A @A @A Object o = (@B @B @B String) Test.so;"); 1.187 + verify("RuntimeInvisibleTypeAnnotations", 1.188 + "0: #25(#26=[@#27(),@#27(),@#27()]): FIELD", 1.189 + "1: #28(#26=[@#29(),@#29(),@#29()]): CAST, offset=5, type_index=0"); 1.190 + } 1.191 + } 1.192 + 1.193 + @TestCase 1.194 + public static class TC6 extends RepeatingTypeAnnotations { 1.195 + public TC6() { 1.196 + setSrc(" static String so = \"hello world\";", 1.197 + " public static @A @B @A Object o = (@B @A @B String) Test.so;"); 1.198 + verify("RuntimeInvisibleTypeAnnotations", 1.199 + "0: #25(#26=[@#27(),@#27()]): FIELD", 1.200 + "1: #28(): FIELD", 1.201 + "2: #29(#26=[@#28(),@#28()]): CAST, offset=5", 1.202 + "3: #27(): CAST, offset=5"); 1.203 + } 1.204 + } 1.205 + 1.206 + @TestCase 1.207 + public static class TC7 extends RepeatingTypeAnnotations { 1.208 + public TC7() { 1.209 + setSrc(" static String so = \"hello world\";", 1.210 + " public static @A @A @C Object o = (@B @C @B String) Test.so;"); 1.211 + verify("RuntimeInvisibleTypeAnnotations", 1.212 + "RuntimeVisibleTypeAnnotations", 1.213 + "0: #25(): FIELD", 1.214 + "1: #25(): CAST, offset=5", 1.215 + "0: #27(#28=[@#29(),@#29()]): FIELD", 1.216 + "1: #30(#28=[@#31(),@#31()]): CAST, offset=5"); 1.217 + } 1.218 + } 1.219 + 1.220 + @TestCase 1.221 + public static class TC8 extends RepeatingTypeAnnotations { 1.222 + public TC8() { 1.223 + setSrc(" static String so = \"hello world\";", 1.224 + " public static @A @B @C Object o = (@C @B @A String) Test.so;"); 1.225 + verify("RuntimeInvisibleTypeAnnotations", 1.226 + "RuntimeVisibleTypeAnnotations", 1.227 + "0: #25(): FIELD", 1.228 + "1: #25(): CAST, offset=5", 1.229 + "0: #27(): FIELD", 1.230 + "1: #28(): FIELD", 1.231 + "2: #28(): CAST, offset=5", 1.232 + "3: #27(): CAST, offset=5"); 1.233 + } 1.234 + } 1.235 + 1.236 + @TestCase 1.237 + @ignore // 8008082:missing type annotation for cast 1.238 + public static class TC9 extends RepeatingTypeAnnotations { 1.239 + public TC9() { 1.240 + setSrc(" public Test(@A @A @A Object o, @A int i, long l) {", 1.241 + " @A @A @A String ls = (@B @B @B String) o;", 1.242 + " }"); 1.243 + verify("RuntimeInvisibleTypeAnnotations", 1.244 + "0: #34(#35=[@#36(),@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0", 1.245 + "1: #36(): METHOD_FORMAL_PARAMETER, param_index=1", 1.246 + "2: #37(#35=[@#38(),@#38(),@#38()]): CAST, offset=4, type_index=0", 1.247 + "3: #34(#35=[@#36(),@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}"); 1.248 + } 1.249 + } 1.250 + 1.251 + @TestCase 1.252 + public static class TC10 extends RepeatingTypeAnnotations { 1.253 + public TC10() { 1.254 + setSrc(" public Test(@A @A @B Object o, @A @B int i, long l) {", 1.255 + " @A @A @B String ls = (@B @A @B String) o;", 1.256 + " }"); 1.257 + verify("RuntimeInvisibleTypeAnnotations:", 1.258 + "0: #34(#35=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0", 1.259 + "1: #37(): METHOD_FORMAL_PARAMETER, param_index=0", 1.260 + "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1", 1.261 + "3: #37(): METHOD_FORMAL_PARAMETER, param_index=1", 1.262 + "4: #38(#35=[@#37(),@#37()]): CAST, offset=4, type_index=0", 1.263 + "5: #36(): CAST, offset=4, type_index=0", 1.264 + "6: #34(#35=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", 1.265 + "7: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}"); 1.266 + } 1.267 + } 1.268 + 1.269 + @TestCase 1.270 + public static class TC11 extends RepeatingTypeAnnotations { 1.271 + public TC11() { 1.272 + setSrc(" public Test(@C @C @A Object o, @A @B int i, long l) {", 1.273 + " @C @C @A String ls = (@A @A @C String) o;", 1.274 + " }"); 1.275 + verify("RuntimeInvisibleTypeAnnotations", 1.276 + "RuntimeVisibleTypeAnnotations", 1.277 + "0: #34(#35=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0", 1.278 + "1: #36(): CAST, offset=4", 1.279 + "2: #34(#35=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", 1.280 + "0: #38(): METHOD_FORMAL_PARAMETER, param_index=0", 1.281 + "1: #38(): METHOD_FORMAL_PARAMETER, param_index=1", 1.282 + "2: #39(): METHOD_FORMAL_PARAMETER, param_index=1", 1.283 + "3: #40(#35=[@#38(),@#38()]): CAST, offset=4", 1.284 + "4: #38(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}"); 1.285 + } 1.286 + } 1.287 + 1.288 + @TestCase 1.289 + public static class TC12 extends RepeatingTypeAnnotations { 1.290 + public TC12() { 1.291 + setSrc(" public Test(@A @B @C Object o, @A @C int i, long l) {", 1.292 + " @A @B @C String ls = (@C @A @B String) o;", 1.293 + " }"); 1.294 + verify("RuntimeInvisibleTypeAnnotations", 1.295 + "RuntimeVisibleTypeAnnotations", 1.296 + "0: #34(): METHOD_FORMAL_PARAMETER, param_index=0", 1.297 + "1: #34(): METHOD_FORMAL_PARAMETER, param_index=1", 1.298 + "2: #34(): CAST, offset=4", 1.299 + "3: #34(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", 1.300 + "0: #36(): METHOD_FORMAL_PARAMETER, param_index=0", 1.301 + "1: #37(): METHOD_FORMAL_PARAMETER, param_index=0", 1.302 + "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1", 1.303 + "3: #36(): CAST, offset=4", 1.304 + "4: #37(): CAST, offset=4", 1.305 + "5: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", 1.306 + "6: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}"); 1.307 + } 1.308 + } 1.309 + 1.310 + @TestCase 1.311 + @ignore // 8008082:missing type annotation for cast 1.312 + public static class TC13 extends RepeatingTypeAnnotations { 1.313 + public TC13() { 1.314 + setSrc(" public @A @A @A String foo(@A @A @A Object o, @A int i, long l) {", 1.315 + " @A @A @A String ls = (@B @B @B String) o;", 1.316 + " return (@A @A @A String) o;", 1.317 + " }"); 1.318 + verify("RuntimeInvisibleTypeAnnotations", 1.319 + "0: #36(#37=[@#38(),@#38(),@#38()]): METHOD_RETURN", 1.320 + "1: #36(#37=[@#38(),@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0", 1.321 + "2: #38(): METHOD_FORMAL_PARAMETER, param_index=1", 1.322 + "3: #39(#37=[@#40(),@#40(),@#40()]): CAST, offset=0, type_index=0", 1.323 + "4: #36(#37=[@#38(),@#38(),@#38()]): CAST, offset=6, type_index=0", 1.324 + "5: #36(#37=[@#38(),@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}"); 1.325 + } 1.326 + } 1.327 + 1.328 + @TestCase 1.329 + public static class TC14 extends RepeatingTypeAnnotations { 1.330 + public TC14() { 1.331 + setSrc(" public @A @B @B String foo(@A @A @B Object o, @A @B int i, long l) {", 1.332 + " @A @A @B String ls = (@B @A @B String) o;", 1.333 + " return (@A @B @B String) o;", 1.334 + " }"); 1.335 + verify("RuntimeInvisibleTypeAnnotations", 1.336 + "0: #36(): METHOD_RETURN", 1.337 + "1: #37(#38=[@#39(),@#39()]): METHOD_RETURN", 1.338 + "2: #40(#38=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0", 1.339 + "3: #39(): METHOD_FORMAL_PARAMETER, param_index=0", 1.340 + "4: #36(): METHOD_FORMAL_PARAMETER, param_index=1", 1.341 + "5: #39(): METHOD_FORMAL_PARAMETER, param_index=1", 1.342 + "6: #37(#38=[@#39(),@#39()]): CAST, offset=0", 1.343 + "7: #36(): CAST, offset=0", 1.344 + "8: #36(): CAST, offset=6", 1.345 + "9: #37(#38=[@#39(),@#39()]): CAST, offset=6", 1.346 + "10: #40(#38=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", 1.347 + "11: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}"); 1.348 + } 1.349 + } 1.350 + 1.351 + @TestCase 1.352 + public static class TC15 extends RepeatingTypeAnnotations { 1.353 + public TC15() { 1.354 + setSrc(" public @A @A @C String foo(@C @C @A Object o, @A @B int i, long l) {", 1.355 + " @C @C @A String ls = (@A @A @C String) o;", 1.356 + " return (@C @B @B String) o;", 1.357 + " }"); 1.358 + verify("RuntimeInvisibleTypeAnnotations", 1.359 + "RuntimeVisibleTypeAnnotations", 1.360 + "0: #36(): METHOD_RETURN", 1.361 + "1: #37(#38=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0", 1.362 + "2: #36(): CAST, offset=0", 1.363 + "3: #36(): CAST, offset=6", 1.364 + "4: #37(#38=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", 1.365 + "0: #40(#38=[@#41(),@#41()]): METHOD_RETURN", 1.366 + "1: #41(): METHOD_FORMAL_PARAMETER, param_index=0", 1.367 + "2: #41(): METHOD_FORMAL_PARAMETER, param_index=1", 1.368 + "3: #42(): METHOD_FORMAL_PARAMETER, param_index=1", 1.369 + "4: #40(#38=[@#41(),@#41()]): CAST, offset=0", 1.370 + "5: #43(#38=[@#42(),@#42()]): CAST, offset=6", 1.371 + "6: #41(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}"); 1.372 + } 1.373 + } 1.374 + 1.375 + @TestCase 1.376 + public static class TC16 extends RepeatingTypeAnnotations { 1.377 + public TC16() { 1.378 + setSrc(" public @A @B @C String foo(@A @B @C Object o, @A @C int i, long l) {", 1.379 + " @A @B @C String ls = (@C @A @B String) o;", 1.380 + " return (@B @A @C String) o;", 1.381 + " }"); 1.382 + verify("RuntimeInvisibleTypeAnnotations", 1.383 + "RuntimeVisibleTypeAnnotations", 1.384 + "0: #36(): METHOD_RETURN", 1.385 + "1: #36(): METHOD_FORMAL_PARAMETER, param_index=0", 1.386 + "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1", 1.387 + "3: #36(): CAST, offset=0", 1.388 + "4: #36(): CAST, offset=6", 1.389 + "5: #36(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", 1.390 + "0: #38(): METHOD_RETURN", 1.391 + "1: #39(): METHOD_RETURN", 1.392 + "2: #38(): METHOD_FORMAL_PARAMETER, param_index=0", 1.393 + "3: #39(): METHOD_FORMAL_PARAMETER, param_index=0", 1.394 + "4: #38(): METHOD_FORMAL_PARAMETER, param_index=1", 1.395 + "5: #38(): CAST, offset=0", 1.396 + "6: #39(): CAST, offset=0", 1.397 + "7: #39(): CAST, offset=6", 1.398 + "8: #38(): CAST, offset=6", 1.399 + "9: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", 1.400 + "10: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}"); 1.401 + } 1.402 + } 1.403 +}