test/tools/javap/output/RepeatingTypeAnnotations.java

Fri, 03 May 2013 09:56:56 -0700

author
jjg
date
Fri, 03 May 2013 09:56:56 -0700
changeset 1721
abd153854f16
parent 1643
1f8c28134ffc
child 1755
ddb4a2bfcd82
permissions
-rw-r--r--

8012728: Normalize @ignore comments on langtools tests
Reviewed-by: vromero, mcimadamore

     1 /*
     2  * Copyright (c) 2013, 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 8005220
    27  * @summary javap must display repeating annotations
    28  */
    29 import java.io.*;
    30 import java.util.*;
    32 /**
    33  * This class extends the abstract {@link Tester} test-driver, and
    34  * encapusulates a number of test-case classes (i.e. classes extending
    35  * this class and annotated with {@code TestCase}).
    36  * <p>
    37  * By default (no argument), this test runs all test-cases, except
    38  * if annotated with {@code ignore}.
    39  * <p>
    40  * Individual test cases can be executed using a run action.
    41  * <p>
    42  * Example: @run main RepeatingTypeAnnotations RepeatingTypeAnnotations$TC4
    43  * <p>
    44  * Note: when specific test-cases are run, additional debug output is
    45  * produced to help debugging. Test annotated with {@code ignore}
    46  * can be executed explicitly.
    47  */
    48 public class RepeatingTypeAnnotations extends Tester {
    50     /**
    51      * Main method instantiates test and run test-cases.
    52      */
    53     public static void main(String... args) throws Exception {
    54         Tester tester = new RepeatingTypeAnnotations();
    55         tester.run(args);
    56     }
    58     /**
    59      * Testcases are classes extending {@code RepeatingTypeAnnotations},
    60      * and calling {@link setSrc}, followed by one or more invocations
    61      * of {@link verify} in the body of the constructor.
    62      */
    63     public RepeatingTypeAnnotations() {
    64         setSrc(new TestSource(template));
    65     }
    67     /**
    68      * Common template for test cases. The line TESTCASE is
    69      * replaced with the specific lines of individual tests.
    70      */
    71     private static final String[] template = {
    72         "import java.lang.annotation.*;",
    73         "class Test {",
    74         "    @Repeatable(As.class)",
    75         "    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})",
    76         "    @Retention(RetentionPolicy.CLASS)",
    77         "    @interface A {",
    78         "        Class f() default int.class;",
    79         "    }",
    81         "    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})",
    82         "    @Retention(RetentionPolicy.CLASS)",
    83         "    @interface As { A[] value(); }",
    85         "    @Repeatable(Bs.class)",
    86         "    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})",
    87         "    @Retention(RetentionPolicy.CLASS)",
    88         "    @interface B {",
    89         "        Class f() default int.class;",
    90         "    }",
    92         "    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})",
    93         "    @Retention(RetentionPolicy.CLASS)",
    94         "    @interface Bs { B[] value(); }",
    96         "    @Repeatable(Cs.class)",
    97         "    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})",
    98         "    @Retention(RetentionPolicy.RUNTIME)",
    99         "    @interface C {",
   100         "        Class f() default int.class;",
   101         "    }",
   103         "    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})",
   104         "    @Retention(RetentionPolicy.RUNTIME)",
   105         "    @interface Cs { C[] value(); }",
   106         "TESTCASE",
   107         "}"
   108     };
   110     /*
   111      * The test cases covers annotation in the following locations:
   112      * - static and non-static fields
   113      * - local variables
   114      * - constructor and method return type and parameter types
   115      * - casts in class and method contexts.
   116      * For the above locations the test-cases covers:
   117      * - single annotation type
   118      * - two annotation types with same retention
   119      * - two annotation types with different retention
   120      * - three annotation types, two of same retention, one different.
   121      */
   123     @TestCase
   124     @ignore // 8008082: missing type annotation for cast
   125     public static class TC1 extends RepeatingTypeAnnotations {
   126         public TC1() {
   127             setSrc("    static String so = \"hello world\";",
   128                    "    public @A @A @A Object o = (@A @A @A String) Test.so;");
   129             verify("RuntimeInvisibleTypeAnnotations",
   130                    "0: #25(#26=[@#27(),@#27(),@#27()]): FIELD",
   131                    "1: #25(#26=[@#27(),@#27(),@#27()]): CAST, offset=5");
   132         }
   133     }
   135     @TestCase
   136     public static class TC2 extends RepeatingTypeAnnotations {
   137         public TC2() {
   138             setSrc("    static String so = \"hello world\";",
   139                    "    public @A @B @A Object o = (@B @A @B String) Test.so;");
   140             verify("RuntimeInvisibleTypeAnnotations",
   141                    "0: #25(#26=[@#27(),@#27()]): FIELD",
   142                    "1: #28(): FIELD",
   143                    "2: #29(#26=[@#28(),@#28()]): CAST, offset=5",
   144                    "3: #27(): CAST, offset=5");
   145         }
   146     }
   148     @TestCase
   149     public static class TC3 extends RepeatingTypeAnnotations {
   150         public TC3() {
   151             setSrc("    static String so = \"hello world\";",
   152                    "    public @A @A @C Object o = (@B @C @B String) Test.so;");
   153             verify("RuntimeInvisibleTypeAnnotations",
   154                    "0: #25(): FIELD",
   155                    "1: #25(): CAST, offset=5",
   156                    "RuntimeVisibleTypeAnnotations",
   157                    "0: #27(#28=[@#29(),@#29()]): FIELD",
   158                    "1: #30(#28=[@#31(),@#31()]): CAST, offset=5");
   159         }
   160     }
   162     @TestCase
   163     public static class TC4 extends RepeatingTypeAnnotations {
   164         public TC4() {
   165             setSrc("    static String so = \"hello world\";",
   166                    "    public @A @B @C Object o = (@C @B @A String) Test.so;");
   167             verify("RuntimeInvisibleTypeAnnotations",
   168                    "RuntimeVisibleTypeAnnotations",
   169                    "0: #25(): FIELD",
   170                    "1: #25(): CAST, offset=5",
   171                    "0: #27(): FIELD",
   172                    "1: #28(): FIELD",
   173                    "2: #28(): CAST, offset=5",
   174                    "3: #27(): CAST, offset=5");
   175         }
   176     }
   178     @TestCase
   179     @ignore // 8008082: missing type annotation for cast
   180     public static class TC5 extends RepeatingTypeAnnotations {
   181         public TC5() {
   182             setSrc("    static String so = \"hello world\";",
   183                    "    public static @A @A @A Object o = (@B @B @B String) Test.so;");
   184             verify("RuntimeInvisibleTypeAnnotations",
   185                    "0: #25(#26=[@#27(),@#27(),@#27()]): FIELD",
   186                    "1: #28(#26=[@#29(),@#29(),@#29()]): CAST, offset=5, type_index=0");
   187         }
   188     }
   190     @TestCase
   191     public static class TC6 extends RepeatingTypeAnnotations {
   192         public TC6() {
   193             setSrc("    static String so = \"hello world\";",
   194                    "    public static @A @B @A Object o = (@B @A @B String) Test.so;");
   195             verify("RuntimeInvisibleTypeAnnotations",
   196                    "0: #25(#26=[@#27(),@#27()]): FIELD",
   197                    "1: #28(): FIELD",
   198                    "2: #29(#26=[@#28(),@#28()]): CAST, offset=5",
   199                    "3: #27(): CAST, offset=5");
   200         }
   201     }
   203     @TestCase
   204     public static class TC7 extends RepeatingTypeAnnotations {
   205         public TC7() {
   206             setSrc("    static String so = \"hello world\";",
   207                    "    public static @A @A @C Object o = (@B @C @B String) Test.so;");
   208             verify("RuntimeInvisibleTypeAnnotations",
   209                    "RuntimeVisibleTypeAnnotations",
   210                    "0: #25(): FIELD",
   211                    "1: #25(): CAST, offset=5",
   212                    "0: #27(#28=[@#29(),@#29()]): FIELD",
   213                    "1: #30(#28=[@#31(),@#31()]): CAST, offset=5");
   214         }
   215     }
   217     @TestCase
   218     public static class TC8 extends RepeatingTypeAnnotations {
   219         public TC8() {
   220             setSrc("    static String so = \"hello world\";",
   221                    "    public static @A @B @C Object o = (@C @B @A String) Test.so;");
   222             verify("RuntimeInvisibleTypeAnnotations",
   223                    "RuntimeVisibleTypeAnnotations",
   224                    "0: #25(): FIELD",
   225                    "1: #25(): CAST, offset=5",
   226                    "0: #27(): FIELD",
   227                    "1: #28(): FIELD",
   228                    "2: #28(): CAST, offset=5",
   229                    "3: #27(): CAST, offset=5");
   230         }
   231     }
   233     @TestCase
   234     @ignore // 8008082: missing type annotation for cast
   235     public static class TC9 extends RepeatingTypeAnnotations {
   236         public TC9() {
   237             setSrc("    public Test(@A @A @A Object o, @A int i, long l) {",
   238                    "        @A @A @A String ls = (@B @B @B String) o;",
   239                    "    }");
   240             verify("RuntimeInvisibleTypeAnnotations",
   241                    "0: #34(#35=[@#36(),@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0",
   242                    "1: #36(): METHOD_FORMAL_PARAMETER, param_index=1",
   243                    "2: #37(#35=[@#38(),@#38(),@#38()]): CAST, offset=4, type_index=0",
   244                    "3: #34(#35=[@#36(),@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}");
   245         }
   246     }
   248     @TestCase
   249     public static class TC10 extends RepeatingTypeAnnotations {
   250         public TC10() {
   251             setSrc("    public Test(@A @A @B Object o, @A @B int i, long l) {",
   252                    "        @A @A @B String ls = (@B @A @B String) o;",
   253                    "    }");
   254             verify("RuntimeInvisibleTypeAnnotations:",
   255                    "0: #34(#35=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0",
   256                    "1: #37(): METHOD_FORMAL_PARAMETER, param_index=0",
   257                    "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1",
   258                    "3: #37(): METHOD_FORMAL_PARAMETER, param_index=1",
   259                    "4: #38(#35=[@#37(),@#37()]): CAST, offset=4, type_index=0",
   260                    "5: #36(): CAST, offset=4, type_index=0",
   261                    "6: #34(#35=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
   262                    "7: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}");
   263         }
   264     }
   266     @TestCase
   267     public static class TC11 extends RepeatingTypeAnnotations {
   268         public TC11() {
   269             setSrc("    public Test(@C @C @A Object o, @A @B int i, long l) {",
   270                    "        @C @C @A String ls = (@A @A @C String) o;",
   271                    "    }");
   272             verify("RuntimeInvisibleTypeAnnotations",
   273                    "RuntimeVisibleTypeAnnotations",
   274                    "0: #34(#35=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0",
   275                    "1: #36(): CAST, offset=4",
   276                    "2: #34(#35=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
   277                    "0: #38(): METHOD_FORMAL_PARAMETER, param_index=0",
   278                    "1: #38(): METHOD_FORMAL_PARAMETER, param_index=1",
   279                    "2: #39(): METHOD_FORMAL_PARAMETER, param_index=1",
   280                    "3: #40(#35=[@#38(),@#38()]): CAST, offset=4",
   281                    "4: #38(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}");
   282         }
   283     }
   285     @TestCase
   286     public static class TC12 extends RepeatingTypeAnnotations {
   287         public TC12() {
   288             setSrc("    public Test(@A @B @C Object o, @A @C int i, long l) {",
   289                    "        @A @B @C String ls = (@C @A @B String) o;",
   290                    "    }");
   291             verify("RuntimeInvisibleTypeAnnotations",
   292                    "RuntimeVisibleTypeAnnotations",
   293                    "0: #34(): METHOD_FORMAL_PARAMETER, param_index=0",
   294                    "1: #34(): METHOD_FORMAL_PARAMETER, param_index=1",
   295                    "2: #34(): CAST, offset=4",
   296                    "3: #34(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
   297                    "0: #36(): METHOD_FORMAL_PARAMETER, param_index=0",
   298                    "1: #37(): METHOD_FORMAL_PARAMETER, param_index=0",
   299                    "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1",
   300                    "3: #36(): CAST, offset=4",
   301                    "4: #37(): CAST, offset=4",
   302                    "5: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
   303                    "6: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}");
   304         }
   305     }
   307     @TestCase
   308     @ignore // 8008082: missing type annotation for cast
   309     public static class TC13 extends RepeatingTypeAnnotations {
   310         public TC13() {
   311             setSrc("    public @A @A @A String foo(@A @A @A Object o, @A int i, long l) {",
   312                    "        @A @A @A String ls = (@B @B @B String) o;",
   313                    "        return (@A @A @A String) o;",
   314                    "    }");
   315             verify("RuntimeInvisibleTypeAnnotations",
   316                    "0: #36(#37=[@#38(),@#38(),@#38()]): METHOD_RETURN",
   317                    "1: #36(#37=[@#38(),@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0",
   318                    "2: #38(): METHOD_FORMAL_PARAMETER, param_index=1",
   319                    "3: #39(#37=[@#40(),@#40(),@#40()]): CAST, offset=0, type_index=0",
   320                    "4: #36(#37=[@#38(),@#38(),@#38()]): CAST, offset=6, type_index=0",
   321                    "5: #36(#37=[@#38(),@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}");
   322         }
   323     }
   325     @TestCase
   326     public static class TC14 extends RepeatingTypeAnnotations {
   327         public TC14() {
   328             setSrc("    public @A @B @B String foo(@A @A @B Object o, @A @B int i, long l) {",
   329                    "        @A @A @B String ls = (@B @A @B String) o;",
   330                    "        return (@A @B @B String) o;",
   331                    "    }");
   332             verify("RuntimeInvisibleTypeAnnotations",
   333                     "0: #36(): METHOD_RETURN",
   334                     "1: #37(#38=[@#39(),@#39()]): METHOD_RETURN",
   335                     "2: #40(#38=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0",
   336                     "3: #39(): METHOD_FORMAL_PARAMETER, param_index=0",
   337                     "4: #36(): METHOD_FORMAL_PARAMETER, param_index=1",
   338                     "5: #39(): METHOD_FORMAL_PARAMETER, param_index=1",
   339                     "6: #37(#38=[@#39(),@#39()]): CAST, offset=0",
   340                     "7: #36(): CAST, offset=0",
   341                     "8: #36(): CAST, offset=6",
   342                     "9: #37(#38=[@#39(),@#39()]): CAST, offset=6",
   343                     "10: #40(#38=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
   344                     "11: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}");
   345         }
   346     }
   348     @TestCase
   349     public static class TC15 extends RepeatingTypeAnnotations {
   350         public TC15() {
   351             setSrc("    public @A @A @C String foo(@C @C @A Object o, @A @B int i, long l) {",
   352                    "        @C @C @A String ls = (@A @A @C String) o;",
   353                    "        return (@C @B @B String) o;",
   354                    "    }");
   355             verify("RuntimeInvisibleTypeAnnotations",
   356                     "RuntimeVisibleTypeAnnotations",
   357                     "0: #36(): METHOD_RETURN",
   358                     "1: #37(#38=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0",
   359                     "2: #36(): CAST, offset=0",
   360                     "3: #36(): CAST, offset=6",
   361                     "4: #37(#38=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
   362                     "0: #40(#38=[@#41(),@#41()]): METHOD_RETURN",
   363                     "1: #41(): METHOD_FORMAL_PARAMETER, param_index=0",
   364                     "2: #41(): METHOD_FORMAL_PARAMETER, param_index=1",
   365                     "3: #42(): METHOD_FORMAL_PARAMETER, param_index=1",
   366                     "4: #40(#38=[@#41(),@#41()]): CAST, offset=0",
   367                     "5: #43(#38=[@#42(),@#42()]): CAST, offset=6",
   368                     "6: #41(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}");
   369         }
   370     }
   372     @TestCase
   373     public static class TC16 extends RepeatingTypeAnnotations {
   374         public TC16() {
   375             setSrc("    public @A @B @C String foo(@A @B @C Object o, @A @C int i, long l) {",
   376                    "        @A @B @C String ls = (@C @A @B String) o;",
   377                    "        return (@B @A @C String) o;",
   378                    "    }");
   379             verify("RuntimeInvisibleTypeAnnotations",
   380                    "RuntimeVisibleTypeAnnotations",
   381                    "0: #36(): METHOD_RETURN",
   382                    "1: #36(): METHOD_FORMAL_PARAMETER, param_index=0",
   383                    "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1",
   384                    "3: #36(): CAST, offset=0",
   385                    "4: #36(): CAST, offset=6",
   386                    "5: #36(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
   387                    "0: #38(): METHOD_RETURN",
   388                    "1: #39(): METHOD_RETURN",
   389                    "2: #38(): METHOD_FORMAL_PARAMETER, param_index=0",
   390                    "3: #39(): METHOD_FORMAL_PARAMETER, param_index=0",
   391                    "4: #38(): METHOD_FORMAL_PARAMETER, param_index=1",
   392                    "5: #38(): CAST, offset=0",
   393                    "6: #39(): CAST, offset=0",
   394                    "7: #39(): CAST, offset=6",
   395                    "8: #38(): CAST, offset=6",
   396                    "9: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
   397                    "10: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}");
   398         }
   399     }
   400 }

mercurial