< prev index next >

test/langtools/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest2.java

Print this page




  28  * @modules jdk.jdeps/com.sun.tools.classfile
  29  */
  30 
  31 import com.sun.tools.classfile.*;
  32 import java.io.File;
  33 
  34 public class CombinationsTargetTest2 extends ClassfileTestHelper {
  35 
  36     // Test count helps identify test case in event of failure.
  37     int testcount = 0;
  38 
  39     // Base test case template descriptions;true==annotations in code attribute.
  40     enum srce  {
  41         src1("(repeating) type annotations on on field in method body",true),
  42         src2("(repeating) type annotations on type parameters, bounds and  type arguments", true),
  43         src3("(repeating) type annotations on type parameters of class, method return value in method", true),
  44         src4("(repeating) type annotations on field in anonymous class", false),
  45         src5("(repeating) type annotations on field in anonymous class", false),
  46         src6("(repeating) type annotations on void method declaration", false),
  47         src7("(repeating) type annotations in use of instanceof", true),
  48         src8("(repeating) type annotations in use of instanceof in method", true);


  49 
  50         String description;
  51         Boolean local;
  52 
  53         srce(String desc, Boolean b) {
  54             this.description = this + ": " +desc;
  55             this.local = b;
  56         }
  57     }
  58 
  59 
  60     String[] ETypes={"TYPE", "FIELD", "METHOD", "PARAMETER", "CONSTRUCTOR",
  61                      "LOCAL_VARIABLE", "ANNOTATION_TYPE", "PACKAGE"};
  62 
  63     // local class tests will have an inner class.
  64     Boolean hasInnerClass=false;
  65     String innerClassname="";
  66 
  67     public static void main(String[] args) throws Exception {
  68         new CombinationsTargetTest2().run();


  75         Boolean [][] bRepeat = new Boolean[][]{{false,false,false},//no repeats
  76                                                {true,false,false}, //repeat @A
  77                                                {false,true,false}, //repeat @B
  78                                                {true,true,false},  //repeat both
  79                                                {false,false,true}  //repeat mix
  80         };
  81 
  82         for(Boolean[] bCombo : bRepeat) {
  83             As=bCombo[0]; BDs=bCombo[1]; ABMix=bCombo[2];
  84             for(String et : ETypes) {
  85                switch(et) {
  86                    case "METHOD":
  87                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
  88                        test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
  89                        test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src5);
  90                        test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
  91                        test( 0, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src6);
  92                        test( 0, 0, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src6);
  93                        test( 2, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src7);
  94                        test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src7);


  95                        test( 4, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src8);
  96                        test( 0, 4, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src8);


  97                        break;
  98                    case "FIELD":
  99                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
 100                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src2);
 101                        test( 6, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src3);
 102                        test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src4);
 103                        test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
 104                        test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src2);
 105                        test( 0, 6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src3);
 106                        test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
 107                        break;
 108                    default:/*TYPE,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE*/
 109                        test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
 110                        test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
 111                        break;
 112                }
 113             }
 114         }
 115     }
 116 


 368                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
 369                     "\n\n";
 370                     hasInnerClass=false;
 371                 break;
 372             case src7: // (repeating) type annotations in use of instanceof
 373                     /*
 374                      *   class Test10{
 375                      *       String data = "test";
 376                      *       boolean dataIsString = ( data instanceof @A @B @A @B String);
 377                      *   }
 378                      */
 379                 source = new String( source +
 380                     "// " + src.description + "\n" +
 381                     "class "+ testname + "{\n" +
 382                     "    String data = \"test\";\n" +
 383                     "    boolean dataIsString = ( data instanceof _As_ _Bs_ String);\n" +
 384                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
 385                     "\n\n";
 386                     hasInnerClass=false;
 387                 break;
















 388             case src8: // (repeating) type annotations in use of instanceof
 389                     /*
 390                      *   class Test20{
 391                      *       String data = "test";
 392                      *       Boolean isString() {
 393                      *           if( data instanceof @A @B @A @B String )
 394                      *               return true;
 395                      *           else
 396                      *               return( data instanceof @A @B @A @B String );
 397                      *       }
 398                      *   }
 399                      */
 400                 source = new String( source +
 401                     "// " + src.description + "\n" +
 402                     "class "+ testname + "{\n" +
 403                     "    String data = \"test\";\n" +
 404                     "    Boolean isString() { \n" +
 405                     "        if( data instanceof _As_ _Bs_ String )\n" +
 406                     "            return true;\n" +
 407                     "        else\n" +
 408                     "            return( data instanceof _As_ _Bs_ String );\n" +


























 409                     "    }\n" +
 410                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
 411                     "\n\n";
 412                     hasInnerClass=false;
 413                 break;
 414 
 415         }
 416         return imports + source;
 417     }
 418 }


  28  * @modules jdk.jdeps/com.sun.tools.classfile
  29  */
  30 
  31 import com.sun.tools.classfile.*;
  32 import java.io.File;
  33 
  34 public class CombinationsTargetTest2 extends ClassfileTestHelper {
  35 
  36     // Test count helps identify test case in event of failure.
  37     int testcount = 0;
  38 
  39     // Base test case template descriptions;true==annotations in code attribute.
  40     enum srce  {
  41         src1("(repeating) type annotations on on field in method body",true),
  42         src2("(repeating) type annotations on type parameters, bounds and  type arguments", true),
  43         src3("(repeating) type annotations on type parameters of class, method return value in method", true),
  44         src4("(repeating) type annotations on field in anonymous class", false),
  45         src5("(repeating) type annotations on field in anonymous class", false),
  46         src6("(repeating) type annotations on void method declaration", false),
  47         src7("(repeating) type annotations in use of instanceof", true),
  48         src7p("(repeating) type annotations in use of instanceof with type test pattern", true),
  49         src8("(repeating) type annotations in use of instanceof in method", true),
  50         src8p("(repeating) type annotations in use of instanceof with type test pattern in method", true);
  51 
  52         String description;
  53         Boolean local;
  54 
  55         srce(String desc, Boolean b) {
  56             this.description = this + ": " +desc;
  57             this.local = b;
  58         }
  59     }
  60 
  61 
  62     String[] ETypes={"TYPE", "FIELD", "METHOD", "PARAMETER", "CONSTRUCTOR",
  63                      "LOCAL_VARIABLE", "ANNOTATION_TYPE", "PACKAGE"};
  64 
  65     // local class tests will have an inner class.
  66     Boolean hasInnerClass=false;
  67     String innerClassname="";
  68 
  69     public static void main(String[] args) throws Exception {
  70         new CombinationsTargetTest2().run();


  77         Boolean [][] bRepeat = new Boolean[][]{{false,false,false},//no repeats
  78                                                {true,false,false}, //repeat @A
  79                                                {false,true,false}, //repeat @B
  80                                                {true,true,false},  //repeat both
  81                                                {false,false,true}  //repeat mix
  82         };
  83 
  84         for(Boolean[] bCombo : bRepeat) {
  85             As=bCombo[0]; BDs=bCombo[1]; ABMix=bCombo[2];
  86             for(String et : ETypes) {
  87                switch(et) {
  88                    case "METHOD":
  89                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
  90                        test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
  91                        test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src5);
  92                        test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
  93                        test( 0, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src6);
  94                        test( 0, 0, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src6);
  95                        test( 2, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src7);
  96                        test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src7);
  97                        test( 2, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src7p);
  98                        test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src7p);
  99                        test( 4, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src8);
 100                        test( 0, 4, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src8);
 101                        test( 4, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src8p);
 102                        test( 0, 4, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src8p);
 103                        break;
 104                    case "FIELD":
 105                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
 106                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src2);
 107                        test( 6, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src3);
 108                        test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src4);
 109                        test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
 110                        test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src2);
 111                        test( 0, 6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src3);
 112                        test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
 113                        break;
 114                    default:/*TYPE,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE*/
 115                        test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
 116                        test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
 117                        break;
 118                }
 119             }
 120         }
 121     }
 122 


 374                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
 375                     "\n\n";
 376                     hasInnerClass=false;
 377                 break;
 378             case src7: // (repeating) type annotations in use of instanceof
 379                     /*
 380                      *   class Test10{
 381                      *       String data = "test";
 382                      *       boolean dataIsString = ( data instanceof @A @B @A @B String);
 383                      *   }
 384                      */
 385                 source = new String( source +
 386                     "// " + src.description + "\n" +
 387                     "class "+ testname + "{\n" +
 388                     "    String data = \"test\";\n" +
 389                     "    boolean dataIsString = ( data instanceof _As_ _Bs_ String);\n" +
 390                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
 391                     "\n\n";
 392                     hasInnerClass=false;
 393                 break;
 394             case src7p: // (repeating) type annotations in use of instanceof with type test pattern
 395                     /*
 396                      *   class Test10{
 397                      *       String data = "test";
 398                      *       boolean dataIsString = ( data instanceof @A @B @A @B String str);
 399                      *   }
 400                      */
 401                 source = new String( source +
 402                     "// " + src.description + "\n" +
 403                     "class "+ testname + "{\n" +
 404                     "    String data = \"test\";\n" +
 405                     "    boolean dataIsString = ( data instanceof _As_ _Bs_ String str && str.isEmpty());\n" +
 406                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
 407                     "\n\n";
 408                     hasInnerClass=false;
 409                 break;
 410             case src8: // (repeating) type annotations in use of instanceof
 411                     /*
 412                      *   class Test20{
 413                      *       String data = "test";
 414                      *       Boolean isString() {
 415                      *           if( data instanceof @A @B @A @B String )
 416                      *               return true;
 417                      *           else
 418                      *               return( data instanceof @A @B @A @B String );
 419                      *       }
 420                      *   }
 421                      */
 422                 source = new String( source +
 423                     "// " + src.description + "\n" +
 424                     "class "+ testname + "{\n" +
 425                     "    String data = \"test\";\n" +
 426                     "    Boolean isString() { \n" +
 427                     "        if( data instanceof _As_ _Bs_ String )\n" +
 428                     "            return true;\n" +
 429                     "        else\n" +
 430                     "            return( data instanceof _As_ _Bs_ String );\n" +
 431                     "    }\n" +
 432                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
 433                     "\n\n";
 434                     hasInnerClass=false;
 435                 break;
 436             case src8p: // (repeating) type annotations in use of instanceof with type test pattern
 437                    /*
 438                      *   class Test20{
 439                      *       String data = "test";
 440                      *       Boolean isString() {
 441                      *           if( data instanceof @A @B @A @B String )
 442                      *               return true;
 443                      *           else
 444                      *               return( data instanceof @A @B @A @B String );
 445                      *       }
 446                      *   }
 447                      */
 448                 source = new String( source +
 449                     "// " + src.description + "\n" +
 450                     "class "+ testname + "{\n" +
 451                     "    String data = \"test\";\n" +
 452                     "    Boolean isString() { \n" +
 453                     "        if( data instanceof _As_ _Bs_ String str)\n" +
 454                     "            return true;\n" +
 455                     "        else\n" +
 456                     "            return( data instanceof _As_ _Bs_ String str && str.isEmpty());\n" +
 457                     "    }\n" +
 458                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
 459                     "\n\n";
 460                     hasInnerClass=false;
 461                 break;
 462 
 463         }
 464         return imports + source;
 465     }
 466 }
< prev index next >