langtools/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest2.java
changeset 19651 b1aa46cc2198
parent 17578 46ac954e4a84
child 30730 d3ce7619db2c
equal deleted inserted replaced
19512:07dcf1232608 19651:b1aa46cc2198
    33 public class CombinationsTargetTest2 extends ClassfileTestHelper {
    33 public class CombinationsTargetTest2 extends ClassfileTestHelper {
    34 
    34 
    35     // Test count helps identify test case in event of failure.
    35     // Test count helps identify test case in event of failure.
    36     int testcount = 0;
    36     int testcount = 0;
    37 
    37 
    38     // Base test case template descriptions
    38     // Base test case template descriptions;true==annotations in code attribute.
    39     enum srce  {
    39     enum srce  {
    40         src1("(repeating) type annotations on on field in method body",true),
    40         src1("(repeating) type annotations on on field in method body",true),
    41         src2("(repeating) type annotations on type parameters, bounds and  type arguments", true),
    41         src2("(repeating) type annotations on type parameters, bounds and  type arguments", true),
    42         src3("(repeating) type annotations on type parameters of class, method return value in method", true),
    42         src3("(repeating) type annotations on type parameters of class, method return value in method", true),
    43         src4("(repeating) type annotations on field in anonymous class", false),
    43         src4("(repeating) type annotations on field in anonymous class", false),
    44         src5("(repeating) type annotations on field in anonymous class", false);
    44         src5("(repeating) type annotations on field in anonymous class", false),
       
    45         src6("(repeating) type annotations on void method declaration", false),
       
    46         src7("(repeating) type annotations in use of instanceof", true),
       
    47         src8("(repeating) type annotations in use of instanceof in method", true);
    45 
    48 
    46         String description;
    49         String description;
    47         Boolean local;
    50         Boolean local;
    48 
    51 
    49         srce(String desc, Boolean b) {
    52         srce(String desc, Boolean b) {
    82                    case "METHOD":
    85                    case "METHOD":
    83                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
    86                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
    84                        test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
    87                        test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
    85                        test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src5);
    88                        test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src5);
    86                        test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
    89                        test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
       
    90                        test( 0, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src6);
       
    91                        test( 0, 0, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src6);
       
    92                        test( 2, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src7);
       
    93                        test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src7);
       
    94                        test( 4, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src8);
       
    95                        test( 0, 4, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src8);
    87                        break;
    96                        break;
    88                    case "FIELD":
    97                    case "FIELD":
    89                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
    98                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
    90                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src2);
    99                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src2);
    91                        test( 6, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src3);
   100                        test( 6, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src3);
   119                 ", tvis=" + tvis + ", inv=" + inv + ", vis=" + vis +
   128                 ", tvis=" + tvis + ", inv=" + inv + ", vis=" + vis +
   120                 ", Arepeats=" + Arepeats + ", BDrepeats=" + BDrepeats +
   129                 ", Arepeats=" + Arepeats + ", BDrepeats=" + BDrepeats +
   121                 ", ABmix=" + ABmix + ", retention: " + rtn + ", anno2: " +
   130                 ", ABmix=" + ABmix + ", retention: " + rtn + ", anno2: " +
   122                 et2 + ", src=" + source + "\n    " + source.description;
   131                 et2 + ", src=" + source + "\n    " + source.description;
   123 
   132 
   124         if(
       
   125 // 8005681 - src1,2,3 - skip cases with repeated annotations on new, array, cast.
       
   126             (( source.equals(srce.src1) || source.equals(srce.src2) ||
       
   127               source.equals(srce.src3)) && (ABmix || (Arepeats && BDrepeats)))
       
   128  // 8008928 - src4,5 - this change cause crash with t-a on anon class)
       
   129             || (source.equals(srce.src4) || source.equals(srce.src5))
       
   130           ) {
       
   131             System.out.println(testDef +
       
   132                        "\n    8005681-skip repeated annotations on new,array,cast");
       
   133             return;
       
   134         }
       
   135 
       
   136         println(testDef);
   133         println(testDef);
   137         // Create test source and File.
   134         // Create test source and File.
   138         String sourceString = sourceString(tname, rtn, et2, Arepeats,
   135         String sourceString = sourceString(tname, rtn, et2, Arepeats,
   139                                            BDrepeats, ABmix, source);
   136                                            BDrepeats, ABmix, source);
   140         testFile = writeTestFile(tname+".java", sourceString);
   137         testFile = writeTestFile(tname+".java", sourceString);
   176             throw new Exception( errors + " errors found" );
   173             throw new Exception( errors + " errors found" );
   177         }
   174         }
   178         println("Pass");
   175         println("Pass");
   179     }
   176     }
   180 
   177 
   181     //
       
   182     // Source for test cases
   178     // Source for test cases
   183     //
       
   184     String sourceString(String testname, String retentn, String annot2,
   179     String sourceString(String testname, String retentn, String annot2,
   185                         Boolean Arepeats, Boolean BDrepeats, Boolean ABmix,
   180                         Boolean Arepeats, Boolean BDrepeats, Boolean ABmix,
   186                         srce src) {
   181                         srce src) {
   187 
   182 
   188         String As = "@A", Bs = "@B", Ds = "@D";
   183         String As = "@A", Bs = "@B", Ds = "@D";
   357                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
   352                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
   358                     "\n\n";
   353                     "\n\n";
   359                     hasInnerClass=true;
   354                     hasInnerClass=true;
   360                     innerClassname="$1";
   355                     innerClassname="$1";
   361                 break;
   356                 break;
       
   357             case src6: // (repeating)annotations on void method declaration
       
   358                     /*
       
   359                      * class Test95{
       
   360                      *     @A @A @B @B public void test() { };
       
   361                      * }
       
   362                      */
       
   363                 source = new String( source +
       
   364                     "// " + src.description + "\n" +
       
   365                     "class "+ testname + "{\n" +
       
   366                     "    _As_ _Bs_ public void test() { }\n" +
       
   367                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
       
   368                     "\n\n";
       
   369                     hasInnerClass=false;
       
   370                 break;
       
   371             case src7: // (repeating) type annotations in use of instanceof
       
   372                     /*
       
   373                      *   class Test10{
       
   374                      *       String data = "test";
       
   375                      *       boolean dataIsString = ( data instanceof @A @B @A @B String);
       
   376                      *   }
       
   377                      */
       
   378                 source = new String( source +
       
   379                     "// " + src.description + "\n" +
       
   380                     "class "+ testname + "{\n" +
       
   381                     "    String data = \"test\";\n" +
       
   382                     "    boolean dataIsString = ( data instanceof _As_ _Bs_ String);\n" +
       
   383                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
       
   384                     "\n\n";
       
   385                     hasInnerClass=false;
       
   386                 break;
       
   387             case src8: // (repeating) type annotations in use of instanceof
       
   388                     /*
       
   389                      *   class Test20{
       
   390                      *       String data = "test";
       
   391                      *       Boolean isString() {
       
   392                      *           if( data instanceof @A @B @A @B String )
       
   393                      *               return true;
       
   394                      *           else
       
   395                      *               return( data instanceof @A @B @A @B String );
       
   396                      *       }
       
   397                      *   }
       
   398                      */
       
   399                 source = new String( source +
       
   400                     "// " + src.description + "\n" +
       
   401                     "class "+ testname + "{\n" +
       
   402                     "    String data = \"test\";\n" +
       
   403                     "    Boolean isString() { \n" +
       
   404                     "        if( data instanceof _As_ _Bs_ String )\n" +
       
   405                     "            return true;\n" +
       
   406                     "        else\n" +
       
   407                     "            return( data instanceof _As_ _Bs_ String );\n" +
       
   408                     "    }\n" +
       
   409                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
       
   410                     "\n\n";
       
   411                     hasInnerClass=false;
       
   412                 break;
       
   413 
   362         }
   414         }
   363         return imports + source;
   415         return imports + source;
   364     }
   416     }
   365 }
   417 }