test/langtools/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest2.java
changeset 59285 7799a51dbe30
parent 47216 71c04702a3d5
equal deleted inserted replaced
59284:88502b1cf76f 59285:7799a51dbe30
     1 /*
     1 /*
     2  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    28  * @modules jdk.jdeps/com.sun.tools.classfile
    28  * @modules jdk.jdeps/com.sun.tools.classfile
    29  */
    29  */
    30 
    30 
    31 import com.sun.tools.classfile.*;
    31 import com.sun.tools.classfile.*;
    32 import java.io.File;
    32 import java.io.File;
       
    33 import java.util.List;
    33 
    34 
    34 public class CombinationsTargetTest2 extends ClassfileTestHelper {
    35 public class CombinationsTargetTest2 extends ClassfileTestHelper {
       
    36 
       
    37     private static final String JDK_VERSION =
       
    38             Integer.toString(Runtime.getRuntime().version().feature());
    35 
    39 
    36     // Test count helps identify test case in event of failure.
    40     // Test count helps identify test case in event of failure.
    37     int testcount = 0;
    41     int testcount = 0;
    38 
    42 
    39     // Base test case template descriptions;true==annotations in code attribute.
    43     // Base test case template descriptions;true==annotations in code attribute.
    43         src3("(repeating) type annotations on type parameters of class, method return value in method", true),
    47         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),
    48         src4("(repeating) type annotations on field in anonymous class", false),
    45         src5("(repeating) type annotations on field in anonymous class", false),
    49         src5("(repeating) type annotations on field in anonymous class", false),
    46         src6("(repeating) type annotations on void method declaration", false),
    50         src6("(repeating) type annotations on void method declaration", false),
    47         src7("(repeating) type annotations in use of instanceof", true),
    51         src7("(repeating) type annotations in use of instanceof", true),
    48         src8("(repeating) type annotations in use of instanceof in method", true);
    52         src7p("(repeating) type annotations in use of instanceof with type test pattern", true),
       
    53         src8("(repeating) type annotations in use of instanceof in method", true),
       
    54         src8p("(repeating) type annotations in use of instanceof with type test pattern in method", true);
    49 
    55 
    50         String description;
    56         String description;
    51         Boolean local;
    57         Boolean local;
    52 
    58 
    53         srce(String desc, Boolean b) {
    59         srce(String desc, Boolean b) {
    90                        test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
    96                        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);
    97                        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);
    98                        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);
    99                        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);
   100                        test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src7);
       
   101                        test( 2, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src7p);
       
   102                        test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src7p);
    95                        test( 4, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src8);
   103                        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);
   104                        test( 0, 4, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src8);
       
   105                        test( 4, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src8p);
       
   106                        test( 0, 4, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src8p);
    97                        break;
   107                        break;
    98                    case "FIELD":
   108                    case "FIELD":
    99                        test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
   109                        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);
   110                        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);
   111                        test( 6, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src3);
   120         ++testcount;
   130         ++testcount;
   121         expected_tvisibles = tvis;
   131         expected_tvisibles = tvis;
   122         expected_tinvisibles = tinv;
   132         expected_tinvisibles = tinv;
   123         expected_visibles = vis;
   133         expected_visibles = vis;
   124         expected_invisibles = inv;
   134         expected_invisibles = inv;
       
   135         extraOptions = List.of();
   125         File testFile = null;
   136         File testFile = null;
   126         String tname="Test" + N.toString();
   137         String tname="Test" + N.toString();
   127         hasInnerClass=false;
   138         hasInnerClass=false;
   128         String testDef = "Test " + testcount + " parameters: tinv=" + tinv +
   139         String testDef = "Test " + testcount + " parameters: tinv=" + tinv +
   129                 ", tvis=" + tvis + ", inv=" + inv + ", vis=" + vis +
   140                 ", tvis=" + tvis + ", inv=" + inv + ", vis=" + vis +
   383                     "    boolean dataIsString = ( data instanceof _As_ _Bs_ String);\n" +
   394                     "    boolean dataIsString = ( data instanceof _As_ _Bs_ String);\n" +
   384                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
   395                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
   385                     "\n\n";
   396                     "\n\n";
   386                     hasInnerClass=false;
   397                     hasInnerClass=false;
   387                 break;
   398                 break;
       
   399             case src7p: // (repeating) type annotations in use of instanceof with type test pattern
       
   400                     /*
       
   401                      *   class Test10{
       
   402                      *       String data = "test";
       
   403                      *       boolean dataIsString = ( data instanceof @A @B @A @B String str);
       
   404                      *   }
       
   405                      */
       
   406                 source = new String( source +
       
   407                     "// " + src.description + "\n" +
       
   408                     "class "+ testname + "{\n" +
       
   409                     "    String data = \"test\";\n" +
       
   410                     "    boolean dataIsString = ( data instanceof _As_ _Bs_ String str && str.isEmpty());\n" +
       
   411                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
       
   412                     "\n\n";
       
   413                 extraOptions = List.of("--enable-preview",
       
   414                                        "-source", JDK_VERSION);
       
   415                 hasInnerClass=false;
       
   416                 break;
   388             case src8: // (repeating) type annotations in use of instanceof
   417             case src8: // (repeating) type annotations in use of instanceof
   389                     /*
   418                     /*
   390                      *   class Test20{
   419                      *   class Test20{
   391                      *       String data = "test";
   420                      *       String data = "test";
   392                      *       Boolean isString() {
   421                      *       Boolean isString() {
   409                     "    }\n" +
   438                     "    }\n" +
   410                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
   439                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
   411                     "\n\n";
   440                     "\n\n";
   412                     hasInnerClass=false;
   441                     hasInnerClass=false;
   413                 break;
   442                 break;
       
   443             case src8p: // (repeating) type annotations in use of instanceof with type test pattern
       
   444                    /*
       
   445                      *   class Test20{
       
   446                      *       String data = "test";
       
   447                      *       Boolean isString() {
       
   448                      *           if( data instanceof @A @B @A @B String )
       
   449                      *               return true;
       
   450                      *           else
       
   451                      *               return( data instanceof @A @B @A @B String );
       
   452                      *       }
       
   453                      *   }
       
   454                      */
       
   455                 source = new String( source +
       
   456                     "// " + src.description + "\n" +
       
   457                     "class "+ testname + "{\n" +
       
   458                     "    String data = \"test\";\n" +
       
   459                     "    Boolean isString() { \n" +
       
   460                     "        if( data instanceof _As_ _Bs_ String str)\n" +
       
   461                     "            return true;\n" +
       
   462                     "        else\n" +
       
   463                     "            return( data instanceof _As_ _Bs_ String str && str.isEmpty());\n" +
       
   464                     "    }\n" +
       
   465                     "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
       
   466                     "\n\n";
       
   467                 extraOptions = List.of("--enable-preview",
       
   468                                        "-source", JDK_VERSION);
       
   469                 hasInnerClass=false;
       
   470                 break;
   414 
   471 
   415         }
   472         }
   416         return imports + source;
   473         return imports + source;
   417     }
   474     }
   418 }
   475 }