test/tools/javac/generics/diamond/7046778/DiamondAndInnerClassTest.java

changeset 1482
954541f13717
parent 1169
116f68a5e677
child 1520
5c956be64b9e
     1.1 --- a/test/tools/javac/generics/diamond/7046778/DiamondAndInnerClassTest.java	Tue Jan 08 10:17:29 2013 +0100
     1.2 +++ b/test/tools/javac/generics/diamond/7046778/DiamondAndInnerClassTest.java	Tue Jan 08 13:47:57 2013 +0000
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -25,21 +25,21 @@
    1.11   * @test
    1.12   * @bug 7046778
    1.13   * @summary Project Coin: problem with diamond and member inner classes
    1.14 + * @library ../../../lib
    1.15 + * @build JavacTestingAbstractThreadedTest
    1.16 + * @run main DiamondAndInnerClassTest
    1.17   */
    1.18  
    1.19  import com.sun.source.util.JavacTask;
    1.20  import java.net.URI;
    1.21  import java.util.Arrays;
    1.22  import javax.tools.Diagnostic;
    1.23 -import javax.tools.JavaCompiler;
    1.24  import javax.tools.JavaFileObject;
    1.25  import javax.tools.SimpleJavaFileObject;
    1.26 -import javax.tools.StandardJavaFileManager;
    1.27 -import javax.tools.ToolProvider;
    1.28  
    1.29 -public class DiamondAndInnerClassTest {
    1.30 -
    1.31 -    static int checkCount = 0;
    1.32 +public class DiamondAndInnerClassTest
    1.33 +    extends JavacTestingAbstractThreadedTest
    1.34 +    implements Runnable {
    1.35  
    1.36      enum TypeArgumentKind {
    1.37          NONE(""),
    1.38 @@ -151,11 +151,6 @@
    1.39      }
    1.40  
    1.41      public static void main(String... args) throws Exception {
    1.42 -
    1.43 -        //create default shared JavaCompiler - reused across multiple compilations
    1.44 -        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
    1.45 -        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
    1.46 -
    1.47          for (InnerClassDeclArity innerClassDeclArity : InnerClassDeclArity.values()) {
    1.48              for (TypeQualifierArity declType : TypeQualifierArity.values()) {
    1.49                  if (!declType.matches(innerClassDeclArity)) continue;
    1.50 @@ -168,53 +163,79 @@
    1.51                              //no diamond on decl site
    1.52                              if (taDecl1 == TypeArgumentKind.DIAMOND) continue;
    1.53                              for (TypeArgumentKind taSite1 : TypeArgumentKind.values()) {
    1.54 -                                boolean isSiteRaw = taSite1 == TypeArgumentKind.NONE;
    1.55 +                                boolean isSiteRaw =
    1.56 +                                        taSite1 == TypeArgumentKind.NONE;
    1.57                                  //diamond only allowed on the last type qualifier
    1.58                                  if (taSite1 == TypeArgumentKind.DIAMOND &&
    1.59 -                                        innerClassDeclArity != InnerClassDeclArity.ONE) continue;
    1.60 +                                        innerClassDeclArity !=
    1.61 +                                        InnerClassDeclArity.ONE)
    1.62 +                                    continue;
    1.63                                  for (ArgumentKind arg1 : ArgumentKind.values()) {
    1.64                                      if (innerClassDeclArity == innerClassDeclArity.ONE) {
    1.65 -                                        new DiamondAndInnerClassTest(innerClassDeclArity, declType, newClassType,
    1.66 -                                                argList, new TypeArgumentKind[] {taDecl1},
    1.67 -                                                new TypeArgumentKind[] {taSite1}, new ArgumentKind[] {arg1}).run(comp, fm);
    1.68 +                                        pool.execute(
    1.69 +                                                new DiamondAndInnerClassTest(
    1.70 +                                                innerClassDeclArity, declType,
    1.71 +                                                newClassType, argList,
    1.72 +                                                new TypeArgumentKind[] {taDecl1},
    1.73 +                                                new TypeArgumentKind[] {taSite1},
    1.74 +                                                new ArgumentKind[] {arg1}));
    1.75                                          continue;
    1.76                                      }
    1.77                                      for (TypeArgumentKind taDecl2 : TypeArgumentKind.values()) {
    1.78                                          //no rare types
    1.79 -                                        if (isDeclRaw != (taDecl2 == TypeArgumentKind.NONE)) continue;
    1.80 +                                        if (isDeclRaw != (taDecl2 == TypeArgumentKind.NONE))
    1.81 +                                            continue;
    1.82                                          //no diamond on decl site
    1.83 -                                        if (taDecl2 == TypeArgumentKind.DIAMOND) continue;
    1.84 +                                        if (taDecl2 == TypeArgumentKind.DIAMOND)
    1.85 +                                            continue;
    1.86                                          for (TypeArgumentKind taSite2 : TypeArgumentKind.values()) {
    1.87                                              //no rare types
    1.88 -                                            if (isSiteRaw != (taSite2 == TypeArgumentKind.NONE)) continue;
    1.89 +                                            if (isSiteRaw != (taSite2 == TypeArgumentKind.NONE))
    1.90 +                                                continue;
    1.91                                              //diamond only allowed on the last type qualifier
    1.92                                              if (taSite2 == TypeArgumentKind.DIAMOND &&
    1.93 -                                                    innerClassDeclArity != InnerClassDeclArity.TWO) continue;
    1.94 +                                                    innerClassDeclArity != InnerClassDeclArity.TWO)
    1.95 +                                                continue;
    1.96                                              for (ArgumentKind arg2 : ArgumentKind.values()) {
    1.97                                                  if (innerClassDeclArity == innerClassDeclArity.TWO) {
    1.98 -                                                    new DiamondAndInnerClassTest(innerClassDeclArity, declType, newClassType,
    1.99 -                                                            argList, new TypeArgumentKind[] {taDecl1, taDecl2},
   1.100 +                                                    pool.execute(
   1.101 +                                                            new DiamondAndInnerClassTest(
   1.102 +                                                            innerClassDeclArity,
   1.103 +                                                            declType,
   1.104 +                                                            newClassType,
   1.105 +                                                            argList,
   1.106 +                                                            new TypeArgumentKind[] {taDecl1, taDecl2},
   1.107                                                              new TypeArgumentKind[] {taSite1, taSite2},
   1.108 -                                                            new ArgumentKind[] {arg1, arg2}).run(comp, fm);
   1.109 +                                                            new ArgumentKind[] {arg1, arg2}));
   1.110                                                      continue;
   1.111                                                  }
   1.112                                                  for (TypeArgumentKind taDecl3 : TypeArgumentKind.values()) {
   1.113                                                      //no rare types
   1.114 -                                                    if (isDeclRaw != (taDecl3 == TypeArgumentKind.NONE)) continue;
   1.115 +                                                    if (isDeclRaw != (taDecl3 == TypeArgumentKind.NONE))
   1.116 +                                                        continue;
   1.117                                                      //no diamond on decl site
   1.118 -                                                    if (taDecl3 == TypeArgumentKind.DIAMOND) continue;
   1.119 +                                                    if (taDecl3 == TypeArgumentKind.DIAMOND)
   1.120 +                                                        continue;
   1.121                                                      for (TypeArgumentKind taSite3 : TypeArgumentKind.values()) {
   1.122                                                          //no rare types
   1.123 -                                                        if (isSiteRaw != (taSite3 == TypeArgumentKind.NONE)) continue;
   1.124 +                                                        if (isSiteRaw != (taSite3 == TypeArgumentKind.NONE))
   1.125 +                                                            continue;
   1.126                                                          //diamond only allowed on the last type qualifier
   1.127                                                          if (taSite3 == TypeArgumentKind.DIAMOND &&
   1.128 -                                                                innerClassDeclArity != InnerClassDeclArity.THREE) continue;
   1.129 +                                                            innerClassDeclArity != InnerClassDeclArity.THREE)
   1.130 +                                                            continue;
   1.131                                                          for (ArgumentKind arg3 : ArgumentKind.values()) {
   1.132 -                                                            if (innerClassDeclArity == innerClassDeclArity.THREE) {
   1.133 -                                                                new DiamondAndInnerClassTest(innerClassDeclArity, declType, newClassType,
   1.134 -                                                                        argList, new TypeArgumentKind[] {taDecl1, taDecl2, taDecl3},
   1.135 +                                                            if (innerClassDeclArity ==
   1.136 +                                                                    innerClassDeclArity.THREE) {
   1.137 +                                                                pool.execute(
   1.138 +                                                                        new DiamondAndInnerClassTest(
   1.139 +                                                                        innerClassDeclArity,
   1.140 +                                                                        declType,
   1.141 +                                                                        newClassType,
   1.142 +                                                                        argList,
   1.143 +                                                                        new TypeArgumentKind[] {taDecl1, taDecl2, taDecl3},
   1.144                                                                          new TypeArgumentKind[] {taSite1, taSite2, taSite3},
   1.145 -                                                                        new ArgumentKind[] {arg1, arg2, arg3}).run(comp, fm);
   1.146 +                                                                        new ArgumentKind[] {arg1, arg2, arg3}));
   1.147                                                                  continue;
   1.148                                                              }
   1.149                                                          }
   1.150 @@ -230,7 +251,8 @@
   1.151                  }
   1.152              }
   1.153          }
   1.154 -        System.out.println("Total check executed: " + checkCount);
   1.155 +
   1.156 +        checkAfterExec();
   1.157      }
   1.158  
   1.159      InnerClassDeclArity innerClassDeclArity;
   1.160 @@ -244,9 +266,9 @@
   1.161      DiagnosticChecker diagChecker;
   1.162  
   1.163      DiamondAndInnerClassTest(InnerClassDeclArity innerClassDeclArity,
   1.164 -            TypeQualifierArity declType, TypeQualifierArity siteType, ArgumentListArity argList,
   1.165 -            TypeArgumentKind[] declTypeArgumentKinds, TypeArgumentKind[] siteTypeArgumentKinds,
   1.166 -            ArgumentKind[] argumentKinds) {
   1.167 +            TypeQualifierArity declType, TypeQualifierArity siteType,
   1.168 +            ArgumentListArity argList, TypeArgumentKind[] declTypeArgumentKinds,
   1.169 +            TypeArgumentKind[] siteTypeArgumentKinds, ArgumentKind[] argumentKinds) {
   1.170          this.innerClassDeclArity = innerClassDeclArity;
   1.171          this.declType = declType;
   1.172          this.siteType = siteType;
   1.173 @@ -267,9 +289,9 @@
   1.174          public JavaSource() {
   1.175              super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
   1.176              source = innerClassDeclArity.classDeclStr.replace("#B", bodyTemplate)
   1.177 -                             .replace("#D", declType.getType(declTypeArgumentKinds))
   1.178 -                             .replace("#S", siteType.getType(siteTypeArgumentKinds))
   1.179 -                             .replace("#AL", argList.getArgs(argumentKinds));
   1.180 +                    .replace("#D", declType.getType(declTypeArgumentKinds))
   1.181 +                    .replace("#S", siteType.getType(siteTypeArgumentKinds))
   1.182 +                    .replace("#AL", argList.getArgs(argumentKinds));
   1.183          }
   1.184  
   1.185          @Override
   1.186 @@ -278,36 +300,39 @@
   1.187          }
   1.188      }
   1.189  
   1.190 -    void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
   1.191 -        JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
   1.192 +    @Override
   1.193 +    public void run() {
   1.194 +        JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
   1.195                  null, null, Arrays.asList(source));
   1.196          try {
   1.197              ct.analyze();
   1.198          } catch (Throwable ex) {
   1.199 -            throw new AssertionError("Error thrown when compiling the following code:\n" + source.getCharContent(true));
   1.200 +            throw new AssertionError("Error thrown when compiling the following code:\n" +
   1.201 +                    source.getCharContent(true));
   1.202          }
   1.203          check();
   1.204      }
   1.205  
   1.206      void check() {
   1.207 -        checkCount++;
   1.208 +        checkCount.incrementAndGet();
   1.209  
   1.210          boolean errorExpected = false;
   1.211  
   1.212 -        TypeArgumentKind[] expectedArgKinds = new TypeArgumentKind[innerClassDeclArity.n];
   1.213 +        TypeArgumentKind[] expectedArgKinds =
   1.214 +                new TypeArgumentKind[innerClassDeclArity.n];
   1.215  
   1.216          for (int i = 0 ; i < innerClassDeclArity.n ; i++) {
   1.217              if (!declTypeArgumentKinds[i].compatible(siteTypeArgumentKinds[i])) {
   1.218                  errorExpected = true;
   1.219                  break;
   1.220              }
   1.221 -            expectedArgKinds[i] = siteTypeArgumentKinds[i] == TypeArgumentKind.DIAMOND ?
   1.222 +            expectedArgKinds[i] = siteTypeArgumentKinds[i] ==
   1.223 +                    TypeArgumentKind.DIAMOND ?
   1.224                  declTypeArgumentKinds[i] : siteTypeArgumentKinds[i];
   1.225          }
   1.226  
   1.227          if (!errorExpected) {
   1.228              for (int i = 0 ; i < innerClassDeclArity.n ; i++) {
   1.229 -                //System.out.println("check " + expectedArgKinds[i] + " against " + argumentKinds[i]);
   1.230                  if (!expectedArgKinds[i].compatible(argumentKinds[i])) {
   1.231                      errorExpected = true;
   1.232                      break;
   1.233 @@ -323,7 +348,8 @@
   1.234          }
   1.235      }
   1.236  
   1.237 -    static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
   1.238 +    static class DiagnosticChecker
   1.239 +        implements javax.tools.DiagnosticListener<JavaFileObject> {
   1.240  
   1.241          boolean errorFound;
   1.242  
   1.243 @@ -333,4 +359,5 @@
   1.244              }
   1.245          }
   1.246      }
   1.247 +
   1.248  }

mercurial