langtools/test/tools/javac/generics/rawOverride/7062745/GenericOverrideTest.java
changeset 18008 6d75e3886bac
parent 15384 5a8d00abf076
child 30730 d3ce7619db2c
equal deleted inserted replaced
18007:0afa95bd8bc3 18008:6d75e3886bac
    44 
    44 
    45 public class GenericOverrideTest
    45 public class GenericOverrideTest
    46     extends JavacTestingAbstractThreadedTest
    46     extends JavacTestingAbstractThreadedTest
    47     implements Runnable {
    47     implements Runnable {
    48 
    48 
       
    49     enum SourceLevel {
       
    50         SOURCE_7("-source", "7"),
       
    51         SOURCE_DEFAULT();
       
    52 
       
    53         String[] opts;
       
    54 
       
    55         SourceLevel(String... opts) {
       
    56             this.opts = opts;
       
    57         }
       
    58     }
       
    59 
    49     enum SignatureKind {
    60     enum SignatureKind {
    50         NON_GENERIC(""),
    61         NON_GENERIC(""),
    51         GENERIC("<X>");
    62         GENERIC("<X>");
    52 
    63 
    53         String paramStr;
    64         String paramStr;
   110                     return that == this || that == NONE || that == UNBOUND;
   121                     return that == this || that == NONE || that == UNBOUND;
   111                 default: throw new AssertionError("Unexpected typearg kind: " + this);
   122                 default: throw new AssertionError("Unexpected typearg kind: " + this);
   112             }
   123             }
   113         }
   124         }
   114 
   125 
   115         boolean assignableTo(TypeArgumentKind that, SignatureKind sig) {
   126         boolean assignableTo(TypeArgumentKind that, SignatureKind sig, SourceLevel level) {
   116             switch (this) {
   127             switch (this) {
   117                 case NONE:
   128                 case NONE:
   118                     //this case needs to workaround to javac's impl of 15.12.2.8 being too strict
   129                     //this case needs to workaround to javac's impl of 15.12.2.8 being too strict
   119                     //ideally should be just 'return true' (see 7067746)
   130                     //ideally should be just 'return true' (see 7067746/8015505)
   120                     return sig == SignatureKind.NON_GENERIC || that == NONE;
   131                     return level == SourceLevel.SOURCE_DEFAULT ||
       
   132                             sig == SignatureKind.NON_GENERIC || that == NONE;
   121                 case UNBOUND:
   133                 case UNBOUND:
   122                     return that == this || that == NONE;
   134                     return that == this || that == NONE;
   123                 case INTEGER:
   135                 case INTEGER:
   124                 case NUMBER:
   136                 case NUMBER:
   125                     return that == this || that == NONE || that == UNBOUND;
   137                     return that == this || that == NONE || that == UNBOUND;
   141                                 if (!ta2.compatibleWith(sig2)) continue;
   153                                 if (!ta2.compatibleWith(sig2)) continue;
   142                                 for (ReturnTypeKind rt3 : ReturnTypeKind.values()) {
   154                                 for (ReturnTypeKind rt3 : ReturnTypeKind.values()) {
   143                                     for (TypeArgumentKind ta3 : TypeArgumentKind.values()) {
   155                                     for (TypeArgumentKind ta3 : TypeArgumentKind.values()) {
   144                                         if (!ta3.compatibleWith(SignatureKind.NON_GENERIC))
   156                                         if (!ta3.compatibleWith(SignatureKind.NON_GENERIC))
   145                                             continue;
   157                                             continue;
   146                                         pool.execute(
   158                                         for (SourceLevel level : SourceLevel.values()) {
   147                                                 new GenericOverrideTest(sig1,
   159                                             pool.execute(
   148                                                 rt1, ta1, sig2, rt2,
   160                                                     new GenericOverrideTest(sig1,
   149                                                 ta2, rt3, ta3));
   161                                                     rt1, ta1, sig2, rt2,
       
   162                                                     ta2, rt3, ta3, level));
       
   163                                         }
   150                                     }
   164                                     }
   151                                 }
   165                                 }
   152                             }
   166                             }
   153                         }
   167                         }
   154                     }
   168                     }
   160     }
   174     }
   161 
   175 
   162     SignatureKind sig1, sig2;
   176     SignatureKind sig1, sig2;
   163     ReturnTypeKind rt1, rt2, rt3;
   177     ReturnTypeKind rt1, rt2, rt3;
   164     TypeArgumentKind ta1, ta2, ta3;
   178     TypeArgumentKind ta1, ta2, ta3;
       
   179     SourceLevel level;
   165     JavaSource source;
   180     JavaSource source;
   166     DiagnosticChecker diagChecker;
   181     DiagnosticChecker diagChecker;
   167 
   182 
   168     GenericOverrideTest(SignatureKind sig1, ReturnTypeKind rt1, TypeArgumentKind ta1,
   183     GenericOverrideTest(SignatureKind sig1, ReturnTypeKind rt1, TypeArgumentKind ta1,
   169             SignatureKind sig2, ReturnTypeKind rt2, TypeArgumentKind ta2,
   184             SignatureKind sig2, ReturnTypeKind rt2, TypeArgumentKind ta2,
   170             ReturnTypeKind rt3, TypeArgumentKind ta3) {
   185             ReturnTypeKind rt3, TypeArgumentKind ta3, SourceLevel level) {
   171         this.sig1 = sig1;
   186         this.sig1 = sig1;
   172         this.sig2 = sig2;
   187         this.sig2 = sig2;
   173         this.rt1 = rt1;
   188         this.rt1 = rt1;
   174         this.rt2 = rt2;
   189         this.rt2 = rt2;
   175         this.rt3 = rt3;
   190         this.rt3 = rt3;
   176         this.ta1 = ta1;
   191         this.ta1 = ta1;
   177         this.ta2 = ta2;
   192         this.ta2 = ta2;
   178         this.ta3 = ta3;
   193         this.ta3 = ta3;
       
   194         this.level = level;
   179         this.source = new JavaSource();
   195         this.source = new JavaSource();
   180         this.diagChecker = new DiagnosticChecker();
   196         this.diagChecker = new DiagnosticChecker();
   181     }
   197     }
   182 
   198 
   183     class JavaSource extends SimpleJavaFileObject {
   199     class JavaSource extends SimpleJavaFileObject {
   211     }
   227     }
   212 
   228 
   213     @Override
   229     @Override
   214     public void run() {
   230     public void run() {
   215         JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
   231         JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
   216                 null, null, Arrays.asList(source));
   232                 level.opts != null ? Arrays.asList(level.opts) : null,
       
   233                 null, Arrays.asList(source));
   217         try {
   234         try {
   218             ct.analyze();
   235             ct.analyze();
   219         } catch (Throwable ex) {
   236         } catch (Throwable ex) {
   220             throw new AssertionError("Error thrown when compiling the following code:\n" +
   237             throw new AssertionError("Error thrown when compiling the following code:\n" +
   221                     source.getCharContent(true));
   238                     source.getCharContent(true));
   269             ReturnTypeKind msrt = mostSpecific == 1 ? rt1 : rt2;
   286             ReturnTypeKind msrt = mostSpecific == 1 ? rt1 : rt2;
   270             TypeArgumentKind msta = mostSpecific == 1 ? ta1 : ta2;
   287             TypeArgumentKind msta = mostSpecific == 1 ? ta1 : ta2;
   271             SignatureKind mssig = mostSpecific == 1 ? sig1 : sig2;
   288             SignatureKind mssig = mostSpecific == 1 ? sig1 : sig2;
   272 
   289 
   273             if (!msrt.moreSpecificThan(rt3) ||
   290             if (!msrt.moreSpecificThan(rt3) ||
   274                     !msta.assignableTo(ta3, mssig)) {
   291                     !msta.assignableTo(ta3, mssig, level)) {
   275                 errorExpected = true;
   292                 errorExpected = true;
   276             }
   293             }
   277         }
   294         }
   278 
   295 
   279         if (errorExpected != diagChecker.errorFound) {
   296         if (errorExpected != diagChecker.errorFound) {