Search in sources :

Example 16 with JavacTool

use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.

the class T6430241 method testSimpleAPI.

void testSimpleAPI(boolean expectWarnings, String... opts) {
    System.err.println("test simple API: " + Arrays.asList(opts));
    String[] args = initArgs(opts);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    JavacTool tool = JavacTool.create();
    int rc = tool.run(null, null, ps, args);
    String out = showOutput(baos.toString());
    checkCompilationOK(rc);
    checkOutput(out, expectWarnings);
}
Also used : JavacTool(com.sun.tools.javac.api.JavacTool)

Example 17 with JavacTool

use of com.sun.tools.javac.api.JavacTool 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)

Example 18 with JavacTool

use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.

the class T6348193 method test.

public static void test(NoYes secMgr, NoGoodBad config, NoYes proc) throws IOException {
    if (verbose)
        System.err.println("secMgr:" + secMgr + " config:" + config + " proc:" + proc);
    if (secMgr == NoYes.YES && System.getSecurityManager() == null)
        System.setSecurityManager(new NoLoaderSecurityManager());
    installConfigFile(config);
    processed.delete();
    List<String> args = new ArrayList<String>();
    //args.add("-XprintRounds");
    if (proc == NoYes.YES) {
        args.add("-processor");
        args.add(myName);
    }
    args.add("-processorpath");
    args.add(System.getProperty("java.class.path"));
    args.add("-d");
    args.add(".");
    // avoid using class loader
    JavacTool t = JavacTool.create();
    MyDiagListener dl = new MyDiagListener();
    PrintWriter out = new PrintWriter(System.err, true);
    StandardJavaFileManager fm = t.getStandardFileManager(dl, null, null);
    File file = new File(System.getProperty("test.src"), myName + ".java");
    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(file));
    boolean ok = t.getTask(out, null, dl, args, null, files).call();
    if (config == NoGoodBad.GOOD || proc == NoYes.YES) {
        if (secMgr == NoYes.YES) {
            if (dl.last == null)
                throw new AssertionError("Security manager installed, and processors present, " + " but no diagnostic received");
        } else {
            if (!processed.exists())
                throw new AssertionError("No security manager installed, and processors present, " + " but no processing occurred");
        }
    } else if (config == NoGoodBad.BAD) {
    // TODO: should verify that no compiler crash occurred
    // needs revised JSR199 spec
    } else {
        if (processed.exists())
            throw new AssertionError("No processors present, but processing occurred!");
    }
    if (verbose)
        System.err.println("OK");
}
Also used : JavacTool(com.sun.tools.javac.api.JavacTool)

Aggregations

JavacTool (com.sun.tools.javac.api.JavacTool)18 JavacTask (com.sun.source.util.JavacTask)11 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)5 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)4 File (java.io.File)3 IOException (java.io.IOException)3 StandardJavaFileManager (javax.tools.StandardJavaFileManager)3 JCClassDecl (com.sun.tools.javac.tree.JCTree.JCClassDecl)2 Context (com.sun.tools.javac.util.Context)2 PrintWriter (java.io.PrintWriter)2 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 CharStreams (com.google.common.io.CharStreams)1 Truth.assertAbout (com.google.common.truth.Truth.assertAbout)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 DescriptionBasedDiff (com.google.errorprone.apply.DescriptionBasedDiff)1 SourceFile (com.google.errorprone.apply.SourceFile)1 BugChecker (com.google.errorprone.bugpatterns.BugChecker)1 Fix (com.google.errorprone.fixes.Fix)1 Description (com.google.errorprone.matchers.Description)1