Search in sources :

Example 31 with JavacTask

use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.

the class T6665791 method main.

public static void main(String[] args) throws Exception {
    write(test_java, test);
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager manager = compiler.getStandardFileManager(null, null, null);
    Iterable<? extends JavaFileObject> units = manager.getJavaFileObjects(test_java);
    final StringWriter sw = new StringWriter();
    JavacTask task = (JavacTask) compiler.getTask(sw, manager, null, null, null, units);
    new TreeScanner<Boolean, Void>() {

        @Override
        public Boolean visitClass(ClassTree arg0, Void arg1) {
            sw.write(arg0.toString());
            return super.visitClass(arg0, arg1);
        }
    }.scan(task.parse(), null);
    System.out.println("output:");
    System.out.println(sw.toString());
    String found = sw.toString().replaceAll("\\s+", " ").trim();
    String expect = test.replaceAll("\\s+", " ").trim();
    if (!expect.equals(found)) {
        System.out.println("expect: " + expect);
        System.out.println("found:  " + found);
        throw new Exception("unexpected output");
    }
}
Also used : StringWriter(java.io.StringWriter) ClassTree(com.sun.source.tree.ClassTree) JavaCompiler(javax.tools.JavaCompiler) StandardJavaFileManager(javax.tools.StandardJavaFileManager) JavacTask(com.sun.source.util.JavacTask) IOException(java.io.IOException)

Example 32 with JavacTask

use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.

the class T6345974 method main.

public static void main(String[] args) throws Exception {
    PrintWriter out = new PrintWriter(System.out, true);
    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    File testSrc = new File(System.getProperty("test.src"));
    Iterable<? extends JavaFileObject> f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "T6345974.java")));
    JavacTask task = tool.getTask(out, fm, null, null, null, f);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    out.flush();
    Scanner s = new Scanner();
    for (CompilationUnitTree t : trees) s.scan(t, null);
}
Also used : TreeScanner(com.sun.source.util.TreeScanner) CompilationUnitTree(com.sun.source.tree.CompilationUnitTree) JavacTool(com.sun.tools.javac.api.JavacTool) StandardJavaFileManager(javax.tools.StandardJavaFileManager) JavacTask(com.sun.source.util.JavacTask) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 33 with JavacTask

use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.

the class InterruptedExceptionTest method run.

void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
    JavacTask ct = (JavacTask) tool.getTask(null, fm, diagChecker, Arrays.asList(xlint.getXlintOption()), null, Arrays.asList(source));
    ct.analyze();
    check();
}
Also used : JavacTask(com.sun.source.util.JavacTask)

Example 34 with JavacTask

use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.

the class UnusedResourcesTest method test.

static void test(XlintOption xlint, SuppressLevel suppressLevel, ResourceUsage usage1, ResourceUsage usage2, ResourceUsage usage3) throws Exception {
    final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavaSource source = new JavaSource(suppressLevel, usage1, usage2, usage3);
    DiagnosticChecker dc = new DiagnosticChecker();
    JavacTask ct = (JavacTask) tool.getTask(null, fm, dc, Arrays.asList(xlint.getXlintOption()), null, Arrays.asList(source));
    ct.analyze();
    check(source, xlint, suppressLevel, usage1, usage2, usage3, dc);
}
Also used : JavaCompiler(javax.tools.JavaCompiler) JavacTask(com.sun.source.util.JavacTask)

Example 35 with JavacTask

use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.

the class T6430241 method testTaskAPI.

void testTaskAPI(boolean expectWarnings, Iterable<? extends File> pcp) throws Exception {
    System.err.println("test task API: " + pcp);
    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    if (pcp != null)
        fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);
    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    JavacTask task = tool.getTask(pw, fm, null, null, null, files);
    boolean ok = task.call();
    String out = showOutput(sw.toString());
    checkCompilationOK(ok);
    checkOutput(out, expectWarnings);
}
Also used : JavacTool(com.sun.tools.javac.api.JavacTool) JavacTask(com.sun.source.util.JavacTask)

Aggregations

JavacTask (com.sun.source.util.JavacTask)46 JavaCompiler (javax.tools.JavaCompiler)20 JavacTool (com.sun.tools.javac.api.JavacTool)12 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)10 JavaFileObject (javax.tools.JavaFileObject)9 StandardJavaFileManager (javax.tools.StandardJavaFileManager)7 SimpleJavaFileObject (javax.tools.SimpleJavaFileObject)6 Context (com.sun.tools.javac.util.Context)5 File (java.io.File)5 IOException (java.io.IOException)5 PrintWriter (java.io.PrintWriter)5 StringWriter (java.io.StringWriter)5 JavacFileManager (com.sun.tools.javac.file.JavacFileManager)4 ClassTree (com.sun.source.tree.ClassTree)3 Trees (com.sun.source.util.Trees)3 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 CeyloncTool (com.redhat.ceylon.compiler.java.tools.CeyloncTool)2 Tree (com.sun.source.tree.Tree)2