use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.
the class TestSuppression method test.
void test(String src, WarningKind wk, int gen) throws Exception {
count++;
System.err.println("Test " + count + ": wk:" + wk + " gen:" + gen + " src:" + src);
File testDir = new File("test" + count);
File srcDir = createDir(testDir, "src");
File gensrcDir = createDir(testDir, "gensrc");
File classesDir = createDir(testDir, "classes");
File x = writeFile(new File(srcDir, "X.java"), src);
DiagListener dl = new DiagListener();
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(classesDir, new File(System.getProperty("test.classes"))));
fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir));
fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir));
List<String> args = new ArrayList<String>();
// args.add("-XprintProcessorInfo");
args.add("-XprintRounds");
args.add("-Agen=" + gen);
if (wk == WarningKind.YES)
args.add("-Xlint:serial");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavacTask task = tool.getTask(pw, fm, dl, args, null, files);
task.setProcessors(Arrays.asList(new AnnoProc()));
boolean ok = task.call();
pw.close();
System.err.println("ok:" + ok + " diags:" + dl.counts);
if (sw.toString().length() > 0) {
System.err.println("output:\n" + sw.toString());
}
for (Diagnostic.Kind dk : Diagnostic.Kind.values()) {
Integer v = dl.counts.get(dk);
int found = (v == null) ? 0 : v;
int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0;
if (found != expect) {
error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found);
}
}
System.err.println();
}
use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.
the class T6993305 method run.
void run() throws Exception {
File testSrc = new File(System.getProperty("test.src"));
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
JavacTask task = tool.getTask(null, fm, null, null, null, fos);
Iterable<? extends CompilationUnitTree> cus = task.parse();
TestScanner s = new TestScanner();
s.scan(cus, task);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
use of com.sun.tools.javac.api.JavacTool in project bazel by bazelbuild.
the class JavacTurbineTest method compileLib.
private void compileLib(Path jar, Collection<Path> classpath, Iterable<? extends JavaFileObject> units) throws IOException {
final Path outdir = temp.newFolder().toPath();
JavacFileManager fm = new JavacFileManager(new Context(), false, UTF_8);
fm.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, Collections.singleton(outdir));
fm.setLocationFromPaths(StandardLocation.CLASS_PATH, classpath);
List<String> options = Arrays.asList("-d", outdir.toString());
JavacTool tool = JavacTool.create();
JavacTask task = tool.getTask(new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)), true), fm, null, options, null, units);
assertThat(task.call()).isTrue();
try (JarOutputStream jos = new JarOutputStream(Files.newOutputStream(jar))) {
Files.walkFileTree(outdir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
JarEntry je = new JarEntry(outdir.relativize(path).toString());
jos.putNextEntry(je);
Files.copy(path, jos);
return FileVisitResult.CONTINUE;
}
});
}
}
use of com.sun.tools.javac.api.JavacTool in project error-prone by google.
the class BugCheckerRefactoringTestHelper method doCompile.
private JCCompilationUnit doCompile(final JavaFileObject input, Iterable<JavaFileObject> files, Context context) throws IOException {
JavacTool tool = JavacTool.create();
DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<>();
context.put(ErrorProneOptions.class, ErrorProneOptions.empty());
JavacTaskImpl task = (JavacTaskImpl) tool.getTask(CharStreams.nullWriter(), fileManager, diagnosticsCollector, options, /*classes=*/
null, files, context);
Iterable<? extends CompilationUnitTree> trees = task.parse();
task.analyze();
JCCompilationUnit tree = Iterables.getOnlyElement(Iterables.filter(Iterables.filter(trees, JCCompilationUnit.class), compilationUnit -> compilationUnit.getSourceFile() == input));
Iterable<Diagnostic<? extends JavaFileObject>> errorDiagnostics = Iterables.filter(diagnosticsCollector.getDiagnostics(), d -> d.getKind() == Diagnostic.Kind.ERROR);
if (!Iterables.isEmpty(errorDiagnostics)) {
fail("compilation failed unexpectedly: " + errorDiagnostics);
}
return tree;
}
use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.
the class VerifyingTaskListener method main.
public static void main(String[] args) throws IOException {
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
Iterable<String> options = Arrays.asList("-processorpath", testClassDir, "-processor", self, "-s", ".", "-d", ".");
JavacTask task = tool.getTask(out, fm, null, options, null, files);
VerifyingTaskListener vtl = new VerifyingTaskListener(new File(testSrcDir, self + ".out"));
task.setTaskListener(vtl);
if (!task.call())
throw new AssertionError("compilation failed");
if (vtl.iter.hasNext() || vtl.errors)
throw new AssertionError("comparison against golden file failed.");
}
Aggregations