1.1 --- a/test/tools/javac/lambda/FunctionalInterfaceConversionTest.java Tue Jan 08 10:17:29 2013 +0100 1.2 +++ b/test/tools/javac/lambda/FunctionalInterfaceConversionTest.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 @@ -27,20 +27,24 @@ 1.11 * @summary Add lambda tests 1.12 * perform several automated checks in lambda conversion, esp. around accessibility 1.13 * @author Maurizio Cimadamore 1.14 + * @library ../lib 1.15 + * @build JavacTestingAbstractThreadedTest 1.16 * @run main FunctionalInterfaceConversionTest 1.17 */ 1.18 1.19 -import com.sun.source.util.JavacTask; 1.20 +import java.io.IOException; 1.21 import java.net.URI; 1.22 import java.util.Arrays; 1.23 import javax.tools.Diagnostic; 1.24 import javax.tools.JavaCompiler; 1.25 import javax.tools.JavaFileObject; 1.26 import javax.tools.SimpleJavaFileObject; 1.27 -import javax.tools.StandardJavaFileManager; 1.28 import javax.tools.ToolProvider; 1.29 +import com.sun.source.util.JavacTask; 1.30 1.31 -public class FunctionalInterfaceConversionTest { 1.32 +public class FunctionalInterfaceConversionTest 1.33 + extends JavacTestingAbstractThreadedTest 1.34 + implements Runnable { 1.35 1.36 enum PackageKind { 1.37 NO_PKG(""), 1.38 @@ -139,8 +143,6 @@ 1.39 } 1.40 1.41 public static void main(String[] args) throws Exception { 1.42 - final JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); 1.43 - StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); 1.44 for (PackageKind samPkg : PackageKind.values()) { 1.45 for (ModifierKind modKind : ModifierKind.values()) { 1.46 for (SamKind samKind : SamKind.values()) { 1.47 @@ -150,8 +152,11 @@ 1.48 for (TypeKind argType : TypeKind.values()) { 1.49 for (TypeKind thrownType : TypeKind.values()) { 1.50 for (ExprKind exprKind : ExprKind.values()) { 1.51 - new FunctionalInterfaceConversionTest(samPkg, modKind, samKind, 1.52 - samMeth, clientMeth, retType, argType, thrownType, exprKind).test(comp, fm); 1.53 + pool.execute( 1.54 + new FunctionalInterfaceConversionTest( 1.55 + samPkg, modKind, samKind, 1.56 + samMeth, clientMeth, retType, 1.57 + argType, thrownType, exprKind)); 1.58 } 1.59 } 1.60 } 1.61 @@ -161,6 +166,8 @@ 1.62 } 1.63 } 1.64 } 1.65 + 1.66 + checkAfterExec(false); 1.67 } 1.68 1.69 PackageKind samPkg; 1.70 @@ -175,24 +182,30 @@ 1.71 DiagnosticChecker dc; 1.72 1.73 SourceFile samSourceFile = new SourceFile("Sam.java", "#P \n #C") { 1.74 + @Override 1.75 public String toString() { 1.76 return template.replaceAll("#P", samPkg.getPkgDecl()). 1.77 - replaceAll("#C", samKind.getSam(samMeth.getMethod(retType, argType, thrownType))); 1.78 + replaceAll("#C", samKind.getSam( 1.79 + samMeth.getMethod(retType, argType, thrownType))); 1.80 } 1.81 }; 1.82 1.83 - SourceFile pkgClassSourceFile = new SourceFile("PackageClass.java", 1.84 - "#P\n #M class PackageClass extends Exception { }") { 1.85 + SourceFile pkgClassSourceFile = 1.86 + new SourceFile("PackageClass.java", 1.87 + "#P\n #M class PackageClass extends Exception { }") { 1.88 + @Override 1.89 public String toString() { 1.90 return template.replaceAll("#P", samPkg.getPkgDecl()). 1.91 replaceAll("#M", modKind.modifier_str); 1.92 } 1.93 }; 1.94 1.95 - SourceFile clientSourceFile = new SourceFile("Client.java", 1.96 - "#I\n abstract class Client { \n" + 1.97 - " Sam s = #E;\n" + 1.98 - " #M \n }") { 1.99 + SourceFile clientSourceFile = 1.100 + new SourceFile("Client.java", 1.101 + "#I\n abstract class Client { \n" + 1.102 + " Sam s = #E;\n" + 1.103 + " #M \n }") { 1.104 + @Override 1.105 public String toString() { 1.106 return template.replaceAll("#I", samPkg.getImportStat()) 1.107 .replaceAll("#E", exprKind.exprStr) 1.108 @@ -200,9 +213,10 @@ 1.109 } 1.110 }; 1.111 1.112 - FunctionalInterfaceConversionTest(PackageKind samPkg, ModifierKind modKind, SamKind samKind, 1.113 - MethodKind samMeth, MethodKind clientMeth, TypeKind retType, TypeKind argType, 1.114 - TypeKind thrownType, ExprKind exprKind) { 1.115 + FunctionalInterfaceConversionTest(PackageKind samPkg, ModifierKind modKind, 1.116 + SamKind samKind, MethodKind samMeth, MethodKind clientMeth, 1.117 + TypeKind retType, TypeKind argType, TypeKind thrownType, 1.118 + ExprKind exprKind) { 1.119 this.samPkg = samPkg; 1.120 this.modKind = modKind; 1.121 this.samKind = samKind; 1.122 @@ -215,12 +229,20 @@ 1.123 this.dc = new DiagnosticChecker(); 1.124 } 1.125 1.126 - void test(JavaCompiler comp, StandardJavaFileManager fm) throws Exception { 1.127 - JavacTask ct = (JavacTask)comp.getTask(null, fm, dc, 1.128 - null, null, Arrays.asList(samSourceFile, pkgClassSourceFile, clientSourceFile)); 1.129 - ct.analyze(); 1.130 + @Override 1.131 + public void run() { 1.132 + final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 1.133 + 1.134 + JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), dc, null, null, 1.135 + Arrays.asList(samSourceFile, pkgClassSourceFile, clientSourceFile)); 1.136 + try { 1.137 + ct.analyze(); 1.138 + } catch (IOException ex) { 1.139 + throw new AssertionError("Test failing with cause", ex.getCause()); 1.140 + } 1.141 if (dc.errorFound == checkSamConversion()) { 1.142 - throw new AssertionError(samSourceFile + "\n\n" + pkgClassSourceFile + "\n\n" + clientSourceFile); 1.143 + throw new AssertionError(samSourceFile + "\n\n" + 1.144 + pkgClassSourceFile + "\n\n" + clientSourceFile); 1.145 } 1.146 } 1.147 1.148 @@ -264,13 +286,16 @@ 1.149 return toString(); 1.150 } 1.151 1.152 + @Override 1.153 public abstract String toString(); 1.154 } 1.155 1.156 - static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 1.157 + static class DiagnosticChecker 1.158 + implements javax.tools.DiagnosticListener<JavaFileObject> { 1.159 1.160 boolean errorFound = false; 1.161 1.162 + @Override 1.163 public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 1.164 if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 1.165 errorFound = true;