27 * @summary Project Coin: Annotation to reduce varargs warnings |
27 * @summary Project Coin: Annotation to reduce varargs warnings |
28 * @author mcimadamore |
28 * @author mcimadamore |
29 * @run main Warn5 |
29 * @run main Warn5 |
30 */ |
30 */ |
31 import com.sun.source.util.JavacTask; |
31 import com.sun.source.util.JavacTask; |
|
32 import com.sun.tools.javac.api.JavacTool; |
32 import java.net.URI; |
33 import java.net.URI; |
33 import java.util.ArrayList; |
34 import java.util.ArrayList; |
34 import java.util.Arrays; |
35 import java.util.Arrays; |
35 import javax.tools.Diagnostic; |
36 import javax.tools.Diagnostic; |
36 import javax.tools.JavaCompiler; |
37 import javax.tools.JavaCompiler; |
37 import javax.tools.JavaFileObject; |
38 import javax.tools.JavaFileObject; |
38 import javax.tools.SimpleJavaFileObject; |
39 import javax.tools.SimpleJavaFileObject; |
|
40 import javax.tools.StandardJavaFileManager; |
39 import javax.tools.ToolProvider; |
41 import javax.tools.ToolProvider; |
40 |
42 |
41 public class Warn5 { |
43 public class Warn5 { |
42 |
44 |
43 enum XlintOption { |
45 enum XlintOption { |
205 } |
207 } |
206 } |
208 } |
207 } |
209 } |
208 } |
210 } |
209 |
211 |
|
212 // Create a single file manager and reuse it for each compile to save time. |
|
213 static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); |
|
214 |
210 static void test(SourceLevel sourceLevel, XlintOption xlint, TrustMe trustMe, SuppressLevel suppressLevel, |
215 static void test(SourceLevel sourceLevel, XlintOption xlint, TrustMe trustMe, SuppressLevel suppressLevel, |
211 ModifierKind modKind, MethodKind methKind, SignatureKind sig, BodyKind body) throws Exception { |
216 ModifierKind modKind, MethodKind methKind, SignatureKind sig, BodyKind body) throws Exception { |
212 final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
217 final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
213 JavaSource source = new JavaSource(trustMe, suppressLevel, modKind, methKind, sig, body); |
218 JavaSource source = new JavaSource(trustMe, suppressLevel, modKind, methKind, sig, body); |
214 DiagnosticChecker dc = new DiagnosticChecker(); |
219 DiagnosticChecker dc = new DiagnosticChecker(); |
215 JavacTask ct = (JavacTask)tool.getTask(null, null, dc, |
220 JavacTask ct = (JavacTask)tool.getTask(null, fm, dc, |
216 Arrays.asList(xlint.getXlintOption(), "-source", sourceLevel.sourceKey), null, Arrays.asList(source)); |
221 Arrays.asList(xlint.getXlintOption(), "-source", sourceLevel.sourceKey), null, Arrays.asList(source)); |
217 ct.analyze(); |
222 ct.analyze(); |
218 check(sourceLevel, dc, source, xlint, trustMe, |
223 check(sourceLevel, dc, source, xlint, trustMe, |
219 suppressLevel, modKind, methKind, sig, body); |
224 suppressLevel, modKind, methKind, sig, body); |
220 } |
225 } |