test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest1.java

changeset 1755
ddb4a2bfcd82
parent 1721
abd153854f16
child 2525
2eb010b6cb22
     1.1 --- a/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest1.java	Tue May 14 13:55:35 2013 -0700
     1.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest1.java	Tue May 14 15:04:06 2013 -0700
     1.3 @@ -24,7 +24,6 @@
     1.4  /*
     1.5   * @test
     1.6   * @bug 8005085 8005877 8004829 8005681 8006734 8006775
     1.7 - * @ignore 8013409: test failures for type annotations
     1.8   * @summary Combinations of Target ElementTypes on (repeated)type annotations.
     1.9   */
    1.10  
    1.11 @@ -32,10 +31,25 @@
    1.12  import java.io.File;
    1.13  
    1.14  public class CombinationsTargetTest1 extends ClassfileTestHelper {
    1.15 -    // Helps identify test case in event of failure.
    1.16 +
    1.17 +    // Test count helps identify test case in event of failure.
    1.18      int testcount = 0;
    1.19 -    int src1 = 1, src2 = 2, src4 = 4,
    1.20 -        src5 = 5, src6 = 6, src7 = 7;
    1.21 +
    1.22 +    // Base test case template descriptions
    1.23 +    enum srce  {
    1.24 +        src1("(repeating) type annotations at class level"),
    1.25 +        src2("(repeating) type annotations on method"),
    1.26 +        src3("(repeating) type annotations on wildcard, type arguments in anonymous class"),
    1.27 +        src4("(repeating) type annotations on type parameters, bounds and  type arguments on class decl"),
    1.28 +        src5("(repeating) type annotations on type parameters, bounds and  type arguments on method"),
    1.29 +        src6("(repeating) type annotations on type parameters, bounds and  type arguments in method");
    1.30 +
    1.31 +        String description;
    1.32 +
    1.33 +        srce(String desc) {
    1.34 +            this.description = this + ": " +desc;
    1.35 +        }
    1.36 +    }
    1.37  
    1.38      String[] ETypes={"TYPE", "FIELD", "METHOD", "PARAMETER", "CONSTRUCTOR",
    1.39                       "LOCAL_VARIABLE", "ANNOTATION_TYPE", "PACKAGE"};
    1.40 @@ -52,7 +66,6 @@
    1.41          // Determines which repeat and order in source(ABMix).
    1.42          Boolean As= false, BDs=true, ABMix=false;
    1.43          int testrun=0;
    1.44 -        // A repeats and/or B/D repeats, ABMix for order of As and Bs.
    1.45          Boolean [][] bRepeat = new Boolean[][]{{false,false,false},//no repeats
    1.46                                                 {true,false,false}, //repeat @A
    1.47                                                 {false,true,false}, //repeat @B
    1.48 @@ -64,29 +77,29 @@
    1.49              for(String et : ETypes) {
    1.50                 switch(et) {
    1.51                     case "METHOD":
    1.52 -                       test( 8,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src1);
    1.53 -                       test(10,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src2);
    1.54 -                       test( 8,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src4);
    1.55 -                       test(10,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src6);
    1.56 -                       test( 0,  8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
    1.57 -                       test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src2);
    1.58 -                       test( 0,  8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src4);
    1.59 -                       test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src6);
    1.60 +                       test( 8,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
    1.61 +                       test(10,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src2);
    1.62 +                       test( 6,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src3);
    1.63 +                       test(10,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src5);
    1.64 +                       test( 0,  8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
    1.65 +                       test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src2);
    1.66 +                       test( 0,  6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src3);
    1.67 +                       test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
    1.68                         break;
    1.69                     case "CONSTRUCTOR":
    1.70                     case "FIELD":
    1.71 -                       test( 8,  0, 4, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src1);
    1.72 -                       test( 6,  0, 3, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src5);
    1.73 -                       test( 9,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src7);
    1.74 -                       test( 0,  8, 0, 4, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
    1.75 -                       test( 0,  6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, src5);
    1.76 -                       test( 0,  9, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src7);
    1.77 +                       test( 8,  0, 4, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
    1.78 +                       test( 6,  0, 3, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src4);
    1.79 +                       test( 9,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src6);
    1.80 +                       test( 0,  8, 0, 4, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
    1.81 +                       test( 0,  6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
    1.82 +                       test( 0,  9, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src6);
    1.83                         break;
    1.84                     default:/*TYPE,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE*/
    1.85 -                       test( 8,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src1);
    1.86 -                       test( 6,  0, 3, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src5);
    1.87 -                       test( 0,  8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
    1.88 -                       test( 0,  6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, src5);
    1.89 +                       test( 8,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
    1.90 +                       test( 6,  0, 3, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src4);
    1.91 +                       test( 0,  8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
    1.92 +                       test( 0,  6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
    1.93                 }
    1.94              }
    1.95          }
    1.96 @@ -94,7 +107,7 @@
    1.97  
    1.98      public void test(int tinv, int tvis, int inv, int vis, Boolean Arepeats,
    1.99                       Boolean BDrepeats, Boolean ABmix, String rtn, String et2,
   1.100 -                     Integer N, int source) throws Exception {
   1.101 +                     Integer N, srce source) throws Exception {
   1.102          ++testcount;
   1.103          expected_tvisibles = tvis;
   1.104          expected_tinvisibles = tinv;
   1.105 @@ -125,7 +138,8 @@
   1.106          //if sourcString() set hasInnerClass it also set innerClassname.
   1.107          if(hasInnerClass) {
   1.108              StringBuffer sb = new StringBuffer(classFile.getAbsolutePath());
   1.109 -            classFile=new File(sb.insert(sb.lastIndexOf(".class"),innerClassname).toString());
   1.110 +            classFile=new File(sb.insert(sb.lastIndexOf(".class"),
   1.111 +                                         innerClassname).toString());
   1.112          }
   1.113          ClassFile cf = ClassFile.read(classFile);
   1.114  
   1.115 @@ -152,7 +166,7 @@
   1.116      //
   1.117      String sourceString(String testname, String retentn, String annot2,
   1.118                          Boolean Arepeats, Boolean BDrepeats, Boolean ABmix,
   1.119 -                        int src) {
   1.120 +                        srce src) {
   1.121  
   1.122          String As = "@A", Bs = "@B", Ds = "@D";
   1.123          if(Arepeats) As = "@A @A";
   1.124 @@ -201,11 +215,11 @@
   1.125  
   1.126              "@Retention("+retentn+")\n" +
   1.127              "@Target({TYPE_USE,TYPE_PARAMETER,_OTHER_})\n" +
   1.128 -            "@interface DC { D[] value(); }\n\n");
   1.129 +            "@interface DC { D[] value(); }\n");
   1.130  
   1.131          // Test case sources with sample generated source.
   1.132          switch(src) {
   1.133 -            case 1: // repeating type annotations at class level
   1.134 +            case src1: // repeating type annotations at class level
   1.135                      /*
   1.136                       * @A @B class Test1 {
   1.137                       * @A @B Test1(){}
   1.138 @@ -218,21 +232,21 @@
   1.139                       * }}
   1.140                       */
   1.141                  source = new String(
   1.142 -                "// (repeating) type annotations at class level. \n" +
   1.143 -                "_As_ _Bs_ class " + testname + " {\n" +
   1.144 -                "_As_ _Bs_ " + testname +"(){} \n" +
   1.145 -                "_As_ _Bs_ Integer i1 = 0; \n" +
   1.146 -                "String _As_ _Bs_ [] _As_ _Bs_ [] sa = null; \n" +
   1.147 -                "// type usage in method body \n" +
   1.148 -                "String test("+testname+" this, " +
   1.149 -                   "String param, String ... vararg) { \n" +
   1.150 -                "    Object o = new  String  [3]; \n" +
   1.151 -                "    return (String) null; \n" +
   1.152 -                "} \n" +
   1.153 -                "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
   1.154 -                "\n\n";
   1.155 +                    "// " + src.description + "\n" +
   1.156 +                    "_As_ _Bs_ class " + testname + " {\n" +
   1.157 +                    "_As_ _Bs_ " + testname +"(){} \n" +
   1.158 +                    "_As_ _Bs_ Integer i1 = 0; \n" +
   1.159 +                    "String _As_ _Bs_ [] _As_ _Bs_ [] sa = null; \n" +
   1.160 +                    "// type usage in method body \n" +
   1.161 +                    "String test("+testname+" this, " +
   1.162 +                       "String param, String ... vararg) { \n" +
   1.163 +                    "    Object o = new  String  [3]; \n" +
   1.164 +                    "    return (String) null; \n" +
   1.165 +                    "}\n" +
   1.166 +                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
   1.167 +                    "\n";
   1.168                  break;
   1.169 -            case 2: // (repeating) type annotations on method.
   1.170 +            case src2: // (repeating) type annotations on method.
   1.171                      /*
   1.172                       * class Test12 {
   1.173                       * Test12(){}
   1.174 @@ -243,26 +257,26 @@
   1.175                       * }}
   1.176                       */
   1.177                  source = new String(
   1.178 -                "// (repeating) type annotations on method. \n" +
   1.179 -                "class " + testname + " {\n" +
   1.180 -                testname +"(){} \n" +
   1.181 -                "// type usage on method \n" +
   1.182 -                "_As_ _Bs_ String test(_As_ _Bs_  "+testname+" this, " +
   1.183 -                   "_As_ _Bs_  String param, _As_ _Bs_  String _As_ _Bs_  ... vararg) { \n" +
   1.184 -                "    Object o = new String [3]; \n" +
   1.185 -                "    return (String) null; \n" +
   1.186 -                "} \n" +
   1.187 -                "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
   1.188 -                "\n\n";
   1.189 +                    "// " + src.description + "\n" +
   1.190 +                    "class " + testname + " {\n" +
   1.191 +                    testname +"(){} \n" +
   1.192 +                    "// type usage on method \n" +
   1.193 +                    "_As_ _Bs_ String test(_As_ _Bs_  "+testname+" this, " +
   1.194 +                       "_As_ _Bs_  String param, _As_ _Bs_  String _As_ _Bs_  ... vararg) { \n" +
   1.195 +                    "    Object o = new String [3]; \n" +
   1.196 +                    "    return (String) null; \n" +
   1.197 +                    "}\n" +
   1.198 +                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
   1.199 +                    "\n";
   1.200                  break;
   1.201 -            case 4: //(repeating) annotations on wildcard, type arguments in anonymous class.
   1.202 +            case src3: //(repeating) annotations on wildcard, type arguments in anonymous class.
   1.203                      /*
   1.204                       * class Test13<T extends Object> {
   1.205                       *     public T data = null;
   1.206                       *     T getData() { return data;}
   1.207                       *     String mtest( Test13<String> t){ return t.getData(); }
   1.208                       *     public void test() {
   1.209 -                     *         mtest( new Test13<@A @B String>() {
   1.210 +                     *         mtest( new Test13<String>() {
   1.211                       *                  void m1(List<@A @B ? extends @A @B  Object> lst) {}
   1.212                       *                  void m2() throws@A @B Exception { }
   1.213                       *                });
   1.214 @@ -270,22 +284,23 @@
   1.215                       * }
   1.216                       */
   1.217                  source = new String( source +
   1.218 -                "// (repeating) annotations on wildcard, type arguments in anonymous class. \n" +
   1.219 -                "class " + testname + "<T extends Object> {\n" +
   1.220 -                "    public T data = null;\n" +
   1.221 -                "    T getData() { return data;}\n" +
   1.222 -                "    String mtest( " + testname + "<String> t){ return t.getData(); }\n" +
   1.223 -                "    public void test() {\n" +
   1.224 -                "        mtest( new " + testname + "<_As_ _Bs_ String>() {\n" +
   1.225 -                "                 void m1(List<_As_ _Bs_ ? extends _As_ _Bs_  Object> lst) {}\n" +
   1.226 -                "                 void m2() throws_As_ _Bs_ Exception { }\n" +
   1.227 -                "               });\n" +
   1.228 -                "    }\n" +
   1.229 -                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + "\n\n";
   1.230 -                hasInnerClass=true;
   1.231 -                innerClassname="$1";
   1.232 +                    "// " + src.description + "\n" +
   1.233 +                    "class " + testname + "<T extends Object> {\n" +
   1.234 +                    "    public T data = null;\n" +
   1.235 +                    "    T getData() { return data;}\n" +
   1.236 +                    "    String mtest( " + testname + "<String> t){ return t.getData(); }\n" +
   1.237 +                    "    public void test() {\n" +
   1.238 +                    "        mtest( new " + testname + "<String>() {\n" +
   1.239 +                    "                 void m1(List<_As_ _Bs_ ? extends _As_ _Bs_  Object> lst) {}\n" +
   1.240 +                    "                 void m2() throws_As_ _Bs_ Exception { }\n" +
   1.241 +                    "               });\n" +
   1.242 +                    "    }\n" +
   1.243 +                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
   1.244 +                    "\n";
   1.245 +                    hasInnerClass=true;
   1.246 +                    innerClassname="$1";
   1.247              break;
   1.248 -            case 5: // (repeating)annotations on type parameters, bounds and  type arguments on class decl.
   1.249 +            case src4: // (repeating)annotations on type parameters, bounds and  type arguments on class decl.
   1.250                      /*
   1.251                       * @A @B @D
   1.252                       * class Test2<@A @B @C @D T extends @A @B Object> {
   1.253 @@ -297,18 +312,18 @@
   1.254                       * }
   1.255                       */
   1.256                  source = new String( source +
   1.257 -                "// (repeating)annotations on type parameters, bounds and  type arguments on class decl. \n" +
   1.258 -                "_As_ _Bs_ _Ds_\n" +  //8004829: A and B on type parameter below.
   1.259 -                "class " + testname + "<_As_ _Bs_ @C _Ds_ T extends _As_ _Bs_ Object> {\n" +
   1.260 -                "    Map<List<String>, Integer> map =\n" +
   1.261 -                "        new HashMap<List< String>, Integer>();\n" +
   1.262 -                "    Map<List<String>,Integer> map2 = new HashMap<>();\n" +
   1.263 -                "    String test(" + testname + "<T> this) { return null;}\n" +
   1.264 -                "    <T> String genericMethod(T t) { return null; }\n" +
   1.265 -                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
   1.266 -                "\n\n";
   1.267 -            break;
   1.268 -            case 6: // (repeating) annotations on type parameters, bounds and  type arguments on method.
   1.269 +                    "// " + src.description + "\n" +
   1.270 +                    "_As_ _Bs_ _Ds_\n" +  //8004829: A and B on type parameter below.
   1.271 +                    "class " + testname + "<_As_ _Bs_ @C _Ds_ T extends _As_ _Bs_ Object> {\n" +
   1.272 +                    "    Map<List<String>, Integer> map =\n" +
   1.273 +                    "        new HashMap<List< String>, Integer>();\n" +
   1.274 +                    "    Map<List<String>,Integer> map2 = new HashMap<>();\n" +
   1.275 +                    "    String test(" + testname + "<T> this) { return null;}\n" +
   1.276 +                    "    <T> String genericMethod(T t) { return null; }\n" +
   1.277 +                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
   1.278 +                    "\n";
   1.279 +                break;
   1.280 +            case src5: // (repeating) annotations on type parameters, bounds and  type arguments on method.
   1.281                      /*
   1.282                       * class Test14<T extends Object> {
   1.283                       *     Map<List<String>, Integer> map =
   1.284 @@ -319,17 +334,17 @@
   1.285                       * }
   1.286                       */
   1.287                  source = new String( source +
   1.288 -                "// (repeating) annotations on type parameters, bounds and  type arguments on method. \n" +
   1.289 -                "class " + testname + "<T extends Object> {\n" +
   1.290 -                "    Map<List<String>, Integer> map =\n" +
   1.291 -                "        new HashMap<List<String>, Integer>();\n" +
   1.292 -                "    Map<List<String>, Integer> map2 = new HashMap<>();\n" +
   1.293 -                "    String test(_As_ _Bs_ " + testname + "<_Ds_ T> this) { return null;}\n" +
   1.294 -                "    <@C _Ds_ T> _As_ _Bs_ String genericMethod(_As_ _Bs_ _Ds_ T t) { return null; }\n" +
   1.295 -                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
   1.296 -                "\n\n";
   1.297 -            break;
   1.298 -            case 7: // repeating annotations on type parameters, bounds and  type arguments in method.
   1.299 +                    "// " + src.description + "\n" +
   1.300 +                    "class " + testname + "<T extends Object> {\n" +
   1.301 +                    "    Map<List<String>, Integer> map =\n" +
   1.302 +                    "        new HashMap<List<String>, Integer>();\n" +
   1.303 +                    "    Map<List<String>, Integer> map2 = new HashMap<>();\n" +
   1.304 +                    "    String test(_As_ _Bs_ " + testname + "<_Ds_ T> this) { return null;}\n" +
   1.305 +                    "    <@C _Ds_ T> _As_ _Bs_ String genericMethod(_As_ _Bs_ _Ds_ T t) { return null; }\n" +
   1.306 +                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
   1.307 +                    "\n";
   1.308 +                break;
   1.309 +            case src6: // repeating annotations on type parameters, bounds and  type arguments in method.
   1.310                      /*
   1.311                       * class Test7{
   1.312                       *     <E extends Comparable> Map<List<E>, E > foo(E e) {
   1.313 @@ -344,22 +359,22 @@
   1.314                       * }
   1.315                       */
   1.316                  source = new String( source +
   1.317 -                "// (repeating)annotations on type parameters of class, method return value in method. \n" +
   1.318 -                "class "+ testname + "{\n" +
   1.319 -                "    <E extends Comparable> Map<List<E>, E > foo(E e) {\n" +
   1.320 -                "        class maptest <_As_ _Bs_ _Ds_ E> {\n" +                  // inner class $1maptest
   1.321 -                "            Map<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E> getMap() { \n" +
   1.322 -                "                return new HashMap<List<E>,E>();\n" +
   1.323 -                "            }\n" +
   1.324 -                "        }\n" +
   1.325 -                "        return new maptest<E>().getMap();\n" +
   1.326 -                "   }\n" +
   1.327 -                "   Map<List<String>,String> shm = foo(new String(\"hello\"));\n" +
   1.328 -                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
   1.329 -                "\n\n";
   1.330 -                hasInnerClass=true;
   1.331 -                innerClassname="$1maptest";
   1.332 -            break;
   1.333 +                    "// " + src.description + "\n" +
   1.334 +                    "class "+ testname + "{\n" +
   1.335 +                    "    <E extends Comparable> Map<List<E>, E > foo(E e) {\n" +
   1.336 +                    "        class maptest <_As_ _Bs_ _Ds_ E> {\n" +                  // inner class $1maptest
   1.337 +                    "            Map<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E> getMap() { \n" +
   1.338 +                    "                return new HashMap<List<E>,E>();\n" +
   1.339 +                    "            }\n" +
   1.340 +                    "        }\n" +
   1.341 +                    "        return new maptest<E>().getMap();\n" +
   1.342 +                    "   }\n" +
   1.343 +                    "   Map<List<String>,String> shm = foo(new String(\"hello\"));\n" +
   1.344 +                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
   1.345 +                    "\n";
   1.346 +                    hasInnerClass=true;
   1.347 +                    innerClassname="$1maptest";
   1.348 +                break;
   1.349          }
   1.350          return imports + source;
   1.351      }

mercurial