langtools/test/tools/javac/lambda/lambdaExpression/SamConversionComboTest.java
changeset 27388 d694da45bd7a
parent 24066 1dfb66929538
child 30730 d3ce7619db2c
equal deleted inserted replaced
27387:54142fc27e8a 27388:d694da45bd7a
    33 import com.sun.source.util.JavacTask;
    33 import com.sun.source.util.JavacTask;
    34 import java.net.URI;
    34 import java.net.URI;
    35 import java.util.Arrays;
    35 import java.util.Arrays;
    36 import javax.tools.Diagnostic;
    36 import javax.tools.Diagnostic;
    37 import javax.tools.JavaCompiler;
    37 import javax.tools.JavaCompiler;
       
    38 import javax.tools.JavaFileManager;
    38 import javax.tools.JavaFileObject;
    39 import javax.tools.JavaFileObject;
    39 import javax.tools.SimpleJavaFileObject;
    40 import javax.tools.SimpleJavaFileObject;
    40 import javax.tools.ToolProvider;
    41 import javax.tools.ToolProvider;
    41 
    42 
    42 public class SamConversionComboTest {
    43 public class SamConversionComboTest {
   204         System.out.println(fInterface + ", " +  context + ", " + lambdaKind + ", " + lambdaBody + ", " + returnValue);
   205         System.out.println(fInterface + ", " +  context + ", " + lambdaKind + ", " + lambdaBody + ", " + returnValue);
   205         System.out.println(samSourceFile + "\n");
   206         System.out.println(samSourceFile + "\n");
   206         String clientFileStr = clientSourceFile.toString();
   207         String clientFileStr = clientSourceFile.toString();
   207         System.out.println(clientFileStr.substring(0, clientFileStr.indexOf("\n\n")));
   208         System.out.println(clientFileStr.substring(0, clientFileStr.indexOf("\n\n")));
   208 
   209 
   209         final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
       
   210         DiagnosticChecker dc = new DiagnosticChecker();
   210         DiagnosticChecker dc = new DiagnosticChecker();
   211         JavacTask ct = (JavacTask)tool.getTask(null, null, dc, null, null, Arrays.asList(samSourceFile, clientSourceFile));
   211         JavacTask ct = (JavacTask)comp.getTask(null, fm, dc, null, null, Arrays.asList(samSourceFile, clientSourceFile));
   212         try {
   212         try {
   213             ct.analyze();
   213             ct.analyze();
   214         } catch (Exception e) {
   214         } catch (Exception e) {
   215             throw new AssertionError("failing SAM source file \n" + samSourceFile + "\n\n" + "failing client source file \n"+ clientSourceFile);
   215             throw new AssertionError("failing SAM source file \n" + samSourceFile + "\n\n" + "failing client source file \n"+ clientSourceFile);
   216         }
   216         }
   253     LambdaBody lambdaBody;
   253     LambdaBody lambdaBody;
   254     LambdaKind lambdaKind;
   254     LambdaKind lambdaKind;
   255     ReturnValue returnValue;
   255     ReturnValue returnValue;
   256     static int count = 0;
   256     static int count = 0;
   257 
   257 
       
   258     static JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
       
   259     static JavaFileManager fm = comp.getStandardFileManager(null, null, null);
       
   260 
   258     SamConversionComboTest(FInterface f, Context c, LambdaBody lb, LambdaKind lk, ReturnValue rv) {
   261     SamConversionComboTest(FInterface f, Context c, LambdaBody lb, LambdaKind lk, ReturnValue rv) {
   259         fInterface = f;
   262         fInterface = f;
   260         context = c;
   263         context = c;
   261         lambdaKind = lk;
   264         lambdaKind = lk;
   262         lambdaBody = lb;
   265         lambdaBody = lb;
   263         returnValue = rv;
   266         returnValue = rv;
   264     }
   267     }
   265 
   268 
   266     public static void main(String[] args) throws Exception {
   269     public static void main(String[] args) throws Exception {
   267         for(Context ct : Context.values()) {
   270         try {
   268             for (FInterface fi : FInterface.values()) {
   271             for(Context ct : Context.values()) {
   269                 for (LambdaKind lk: LambdaKind.values()) {
   272                 for (FInterface fi : FInterface.values()) {
   270                     for (LambdaBody lb : LambdaBody.values()) {
   273                     for (LambdaKind lk: LambdaKind.values()) {
   271                         for(ReturnValue rv : ReturnValue.values()) {
   274                         for (LambdaBody lb : LambdaBody.values()) {
   272                             new SamConversionComboTest(fi, ct, lb, lk, rv).test();
   275                             for(ReturnValue rv : ReturnValue.values()) {
       
   276                                 new SamConversionComboTest(fi, ct, lb, lk, rv).test();
       
   277                             }
   273                         }
   278                         }
   274                     }
   279                     }
   275                 }
   280                 }
   276             }
   281             }
   277         }
       
   278         System.out.println("total tests: " + count);
   282         System.out.println("total tests: " + count);
       
   283         } finally {
       
   284             fm.close();
       
   285         }
   279     }
   286     }
   280 }
   287 }