test/tools/javac/lambda/mostSpecific/StructuralMostSpecificTest.java

changeset 1482
954541f13717
parent 1415
01c9d4161882
child 1520
5c956be64b9e
     1.1 --- a/test/tools/javac/lambda/mostSpecific/StructuralMostSpecificTest.java	Tue Jan 08 10:17:29 2013 +0100
     1.2 +++ b/test/tools/javac/lambda/mostSpecific/StructuralMostSpecificTest.java	Tue Jan 08 13:47:57 2013 +0000
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2012, 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 @@ -26,24 +26,23 @@
    1.11   * @bug 8003280
    1.12   * @summary Add lambda tests
    1.13   *  Automatic test for checking correctness of structural most specific test routine
    1.14 - * @run main/timeout=360 StructuralMostSpecificTest
    1.15 + * @library ../../lib
    1.16 + * @build JavacTestingAbstractThreadedTest
    1.17 + * @run main/timeout=600 StructuralMostSpecificTest
    1.18   */
    1.19  
    1.20 +import java.net.URI;
    1.21 +import java.util.Arrays;
    1.22 +import javax.tools.Diagnostic;
    1.23 +import javax.tools.JavaFileObject;
    1.24 +import javax.tools.SimpleJavaFileObject;
    1.25  import com.sun.source.util.JavacTask;
    1.26  import com.sun.tools.javac.api.ClientCodeWrapper;
    1.27  import com.sun.tools.javac.util.JCDiagnostic;
    1.28 -import java.net.URI;
    1.29 -import java.util.Arrays;
    1.30 -import javax.tools.Diagnostic;
    1.31 -import javax.tools.JavaCompiler;
    1.32 -import javax.tools.JavaFileObject;
    1.33 -import javax.tools.SimpleJavaFileObject;
    1.34 -import javax.tools.StandardJavaFileManager;
    1.35 -import javax.tools.ToolProvider;
    1.36  
    1.37 -public class StructuralMostSpecificTest {
    1.38 -
    1.39 -    static int checkCount = 0;
    1.40 +public class StructuralMostSpecificTest
    1.41 +    extends JavacTestingAbstractThreadedTest
    1.42 +    implements Runnable {
    1.43  
    1.44      enum RetTypeKind {
    1.45          SHORT("short"),
    1.46 @@ -105,7 +104,7 @@
    1.47          VOID("return;"),
    1.48          SHORT("return (short)0;"),
    1.49          INT("return 0;"),
    1.50 -        INTEGER("return (Integer)null"),
    1.51 +        INTEGER("return (Integer)null;"),
    1.52          NULL("return null;");
    1.53  
    1.54          String retStr;
    1.55 @@ -142,11 +141,6 @@
    1.56      }
    1.57  
    1.58      public static void main(String... args) throws Exception {
    1.59 -
    1.60 -        //create default shared JavaCompiler - reused across multiple compilations
    1.61 -        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
    1.62 -        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
    1.63 -
    1.64          for (LambdaReturnKind lrk : LambdaReturnKind.values()) {
    1.65              for (RetTypeKind rk1 : RetTypeKind.values()) {
    1.66                  for (RetTypeKind rk2 : RetTypeKind.values()) {
    1.67 @@ -154,7 +148,9 @@
    1.68                          for (ExceptionKind ek2 : ExceptionKind.values()) {
    1.69                              for (ArgTypeKind ak11 : ArgTypeKind.values()) {
    1.70                                  for (ArgTypeKind ak12 : ArgTypeKind.values()) {
    1.71 -                                    new StructuralMostSpecificTest(lrk, rk1, rk2, ek1, ek2, ak11, ak12).run(comp, fm);
    1.72 +                                    pool.execute(
    1.73 +                                        new StructuralMostSpecificTest(lrk, rk1,
    1.74 +                                            rk2, ek1, ek2, ak11, ak12));
    1.75                                  }
    1.76                              }
    1.77                          }
    1.78 @@ -162,7 +158,8 @@
    1.79                  }
    1.80              }
    1.81          }
    1.82 -        System.out.println("Total check executed: " + checkCount);
    1.83 +
    1.84 +        checkAfterExec();
    1.85      }
    1.86  
    1.87      LambdaReturnKind lrk;
    1.88 @@ -218,20 +215,22 @@
    1.89          }
    1.90      }
    1.91  
    1.92 -    void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
    1.93 -        JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
    1.94 +    public void run() {
    1.95 +        JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
    1.96                  Arrays.asList("-XDverboseResolution=all,-predef,-internal,-object-init"),
    1.97                  null, Arrays.asList(source));
    1.98          try {
    1.99              ct.analyze();
   1.100          } catch (Throwable ex) {
   1.101 -            throw new AssertionError("Error thron when analyzing the following source:\n" + source.getCharContent(true));
   1.102 +            throw new
   1.103 +                AssertionError("Error thron when analyzing the following source:\n" +
   1.104 +                    source.getCharContent(true));
   1.105          }
   1.106          check();
   1.107      }
   1.108  
   1.109      void check() {
   1.110 -        checkCount++;
   1.111 +        checkCount.incrementAndGet();
   1.112  
   1.113          if (!lrk.compatibleWith(rt1) || !lrk.compatibleWith(rt2))
   1.114              return;
   1.115 @@ -265,8 +264,8 @@
   1.116          }
   1.117      }
   1.118  
   1.119 -    boolean moreSpecific(RetTypeKind rk1, RetTypeKind rk2, ExceptionKind ek1, ExceptionKind ek2,
   1.120 -            ArgTypeKind ak1, ArgTypeKind ak2) {
   1.121 +    boolean moreSpecific(RetTypeKind rk1, RetTypeKind rk2, ExceptionKind ek1,
   1.122 +            ExceptionKind ek2, ArgTypeKind ak1, ArgTypeKind ak2) {
   1.123          if (!rk1.moreSpecificThan(rk2))
   1.124              return false;
   1.125  
   1.126 @@ -276,7 +275,8 @@
   1.127          return true;
   1.128      }
   1.129  
   1.130 -    static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
   1.131 +    static class DiagnosticChecker
   1.132 +        implements javax.tools.DiagnosticListener<JavaFileObject> {
   1.133  
   1.134          boolean ambiguityFound;
   1.135          String mostSpecificSig;
   1.136 @@ -287,12 +287,16 @@
   1.137                          diagnostic.getCode().equals("compiler.err.ref.ambiguous")) {
   1.138                      ambiguityFound = true;
   1.139                  } else if (diagnostic.getKind() == Diagnostic.Kind.NOTE &&
   1.140 -                        diagnostic.getCode().equals("compiler.note.verbose.resolve.multi")) {
   1.141 +                        diagnostic.getCode()
   1.142 +                        .equals("compiler.note.verbose.resolve.multi")) {
   1.143                      ClientCodeWrapper.DiagnosticSourceUnwrapper dsu =
   1.144 -                            (ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic;
   1.145 -                    JCDiagnostic.MultilineDiagnostic mdiag = (JCDiagnostic.MultilineDiagnostic)dsu.d;
   1.146 +                        (ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic;
   1.147 +                    JCDiagnostic.MultilineDiagnostic mdiag =
   1.148 +                        (JCDiagnostic.MultilineDiagnostic)dsu.d;
   1.149                      int mostSpecificIndex = (Integer)mdiag.getArgs()[2];
   1.150 -                    mostSpecificSig = ((JCDiagnostic)mdiag.getSubdiagnostics().get(mostSpecificIndex)).getArgs()[1].toString();
   1.151 +                    mostSpecificSig =
   1.152 +                        ((JCDiagnostic)mdiag.getSubdiagnostics()
   1.153 +                            .get(mostSpecificIndex)).getArgs()[1].toString();
   1.154                  }
   1.155              } catch (RuntimeException t) {
   1.156                  t.printStackTrace();
   1.157 @@ -300,4 +304,5 @@
   1.158              }
   1.159          }
   1.160      }
   1.161 +
   1.162  }

mercurial