當前位置: 首頁>>代碼示例>>Java>>正文


Java JavacTask.call方法代碼示例

本文整理匯總了Java中com.sun.source.util.JavacTask.call方法的典型用法代碼示例。如果您正苦於以下問題:Java JavacTask.call方法的具體用法?Java JavacTask.call怎麽用?Java JavacTask.call使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.source.util.JavacTask的用法示例。


在下文中一共展示了JavacTask.call方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: check

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
protected void check() throws Exception {

        JavacTask ct = (JavacTask) comp.getTask(null, fm, null, Arrays.asList("-g"),
                                                null, Arrays.asList(jfo));
        System.err.println("compiling code " + jfo);
        ct.setProcessors(Collections.singleton(new AliveRangeFinder()));
        if (!ct.call()) {
            throw new AssertionError("Error during compilation");
        }


        File javaFile = new File(jfo.getName());
        File classFile = new File(javaFile.getName().replace(".java", ".class"));
        checkClassFile(classFile);

        //check all candidates have been used up
        for (Map.Entry<ElementKey, AliveRanges> entry : aliveRangeMap.entrySet()) {
            if (!seenAliveRanges.contains(entry.getKey())) {
                error("Redundant @AliveRanges annotation on method " +
                        entry.getKey().elem + " with key " + entry.getKey());
            }
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:LVTHarness.java

示例2: run

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void run() throws Exception {
    JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
    File classesDir = new File(System.getProperty("user.dir"), "classes");
    classesDir.mkdirs();
    JavaSource[] sources = new JavaSource[]{
        new JavaSource("TestOneIgnorableChar", "AA\\u0000BB"),
        new JavaSource("TestMultipleIgnorableChar", "AA\\u0000\\u0000\\u0000BB")};
    JavacTask ct = (JavacTask)comp.getTask(null, null, null,
            Arrays.asList("-d", classesDir.getPath()),
            null, Arrays.asList(sources));
    try {
        if (!ct.call()) {
            throw new AssertionError("Error thrown when compiling test cases");
        }
    } catch (Throwable ex) {
        throw new AssertionError("Error thrown when compiling test cases");
    }
    check(classesDir,
            "TestOneIgnorableChar.class",
            "TestOneIgnorableChar$AABB.class",
            "TestMultipleIgnorableChar.class",
            "TestMultipleIgnorableChar$AABB.class");
    if (errors > 0)
        throw new AssertionError("There are some errors in the test check the error output");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:IgnoreIgnorableCharactersInInput.java

示例3: run

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
public void run() throws IOException {
    File srcDir = new File(System.getProperty("test.src"));
    File thisFile = new File(srcDir, getClass().getName() + ".java");

    JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {

        List<String> opts = Arrays.asList("-proc:only", "-doe");
        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
        JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files);
        t.setProcessors(Collections.singleton(this));
        boolean ok = t.call();
        if (!ok)
            throw new Error("compilation failed");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:TestGetScope.java

示例4: run

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void run(String resourceSpecification, boolean expected) throws IOException {
    String template = "public class Test implements AutoCloseable {\n" +
                      "    void t() {\n" +
                      "        try (Test resource = RESOURCE) { }\n" +
                      "    }\n" +
                      "    public void close() { }\n" +
                      "}\n";
    String code = template.replace("RESOURCE", resourceSpecification);
    Context ctx = new Context();
    DumpLower.preRegister(ctx);
    Iterable<ToolBox.JavaSource> files = Arrays.asList(new ToolBox.JavaSource(code));
    JavacTask task = JavacTool.create().getTask(null, null, null, null, null, files, ctx);
    task.call();

    boolean hasNullCheck = ((DumpLower) DumpLower.instance(ctx)).hasNullCheck;

    if (hasNullCheck != expected) {
        throw new IllegalStateException("expected: " + expected +
                                        "; actual: " + hasNullCheck +
                                        "; code: " + code);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:TwrAvoidNullCheck.java

示例5: run

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void run(String trySpec, boolean expected) throws IOException {
    String template = "public class Test implements AutoCloseable {\n" +
                      "    void t(int i) {\n" +
                      "        TRY\n" +
                      "    }\n" +
                      "    public void close() { }\n" +
                      "}\n";
    String code = template.replace("TRY", trySpec);
    Context ctx = new Context();
    DumpLower.preRegister(ctx);
    Iterable<ToolBox.JavaSource> files = Arrays.asList(new ToolBox.JavaSource(code));
    JavacTask task = JavacTool.create().getTask(null, null, null, null, null, files, ctx);
    task.call();
    boolean actual = ((DumpLower) DumpLower.instance(ctx)).closeSeen;

    if (expected != actual) {
        throw new IllegalStateException("expected: " + expected + "; actual: " + actual + "; code:\n" + code);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:TwrShareCloseCode.java

示例6: generateFilesNeeded

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void generateFilesNeeded() throws Exception {

        StringJavaFileObject[] CSource = new StringJavaFileObject[] {
            new StringJavaFileObject("C.java",
                "class C {C(String s) {}}"),
        };

        List<StringJavaFileObject> AandBSource = Arrays.asList(
                new StringJavaFileObject("A.java",
                    "class A {void test() {new B(null);new C(null);}}"),
                new StringJavaFileObject("B.java",
                    "class B {B(String s) {}}")
        );

        final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
        JavacTask compileC = (JavacTask)tool.getTask(null, null, null, null, null,
                Arrays.asList(CSource));
        if (!compileC.call()) {
            throw new AssertionError("Compilation error while compiling C.java sources");
        }
        JavacTask compileAB = (JavacTask)tool.getTask(null, null, null,
                Arrays.asList("-cp", "."), null, AandBSource);
        if (!compileAB.call()) {
            throw new AssertionError("Compilation error while compiling A and B sources");
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:DuplicateConstantPoolEntry.java

示例7: compile

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
private void compile(JavaCompiler comp) {
    JavacTask ct = (JavacTask)comp.getTask(null, null, null, null, null, Arrays.asList(source));
    try {
        if (!ct.call()) {
            throw new AssertionError("Error thrown when compiling the following source:\n" + source.getCharContent(true));
        }
    } catch (Throwable ex) {
        throw new AssertionError("Error thrown when compiling the following source:\n" + source.getCharContent(true));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:T7190862.java

示例8: testInit

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void testInit(boolean expectOK, String[] args, List<? extends JavaFileObject> files) {
    JavacTool javac = JavacTool.create();
    JavacTask task = javac.getTask(null, null, null, null, null, files);
    try {
        DocLint dl = new DocLint();
        dl.init(task, args, true);
        if (!expectOK)
            error("expected IllegalArgumentException not thrown");
        task.call();
    } catch (IllegalArgumentException e) {
        System.err.println(e);
        if (expectOK)
            error("unexpected IllegalArgumentException caught");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:RunTest.java

示例9: testAnnoProcessor

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void testAnnoProcessor(JavacTool javac, StandardJavaFileManager fm,
        Iterable<? extends JavaFileObject> files, PrintWriter out,
        int expectedDocComments) {
    out.println("Test annotation processor");
    JavacTask task = javac.getTask(out, fm, null, null, null, files);
    AnnoProc ap = new AnnoProc(DocTrees.instance(task));
    task.setProcessors(Arrays.asList(ap));
    task.call();
    ap.checker.checkDocComments(expectedDocComments);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:Test.java

示例10: main

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
public static void main(String... args) throws IOException {
    class MyFileObject extends SimpleJavaFileObject {
        MyFileObject() {
            super(URI.create("myfo:///Test.java"), SOURCE);
        }
        @Override
        public String getCharContent(boolean ignoreEncodingErrors) {
            //      0         1         2         3
            //      012345678901234567890123456789012345
            return "class Test { String s = 1234; }";
        }
    }
    JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
    List<JavaFileObject> compilationUnits =
            Collections.<JavaFileObject>singletonList(new MyFileObject());
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
    List<String> options = Arrays.asList("-processor", EndPositions.class.getCanonicalName());
    JavacTask task = (JavacTask)javac.getTask(null, null, diagnostics, options, null, compilationUnits);
    boolean valid = task.call();
    if (valid)
        throw new AssertionError("Expected one error, but found none.");

    List<Diagnostic<? extends JavaFileObject>> errors = diagnostics.getDiagnostics();
    if (errors.size() != 1)
        throw new AssertionError("Expected one error only, but found " + errors.size() + "; errors: " + errors);

    Diagnostic<?> error = errors.get(0);
    if (error.getStartPosition() >= error.getEndPosition())
        throw new AssertionError("Expected start to be less than end position: start [" +
                error.getStartPosition() + "], end [" + error.getEndPosition() +"]" +
                "; diagnostics code: " + error.getCode());

    System.out.println("All is good!");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:EndPositions.java

示例11: compile

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
private void compile(JavaCompiler comp) {
    JavacTask ct = (JavacTask)comp.getTask(null, null, null, null, null,
            Arrays.asList(source));
    try {
        if (!ct.call()) {
            throw new AssertionError(CompilationErrorMessage +
                    source.getCharContent(true));
        }
    } catch (Throwable ex) {
        throw new AssertionError(CompilationErrorMessage +
                source.getCharContent(true));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:CheckACC_STRICTFlagOnPkgAccessClassTest.java

示例12: test

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) {
    System.err.println("test: " + opts);
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    try {
        JavacTask t = (JavacTask) javac.getTask(pw, fm, null, opts, null, files);
        boolean ok = t.call();
        pw.close();
        String out = sw.toString().replaceAll("[\r\n]+", "\n");
        if (!out.isEmpty())
            System.err.println(out);
        if (ok && expectResult != Main.Result.OK) {
            error("Compilation succeeded unexpectedly");
        } else if (!ok && expectResult != Main.Result.ERROR) {
            error("Compilation failed unexpectedly");
        } else
            check(out, expectMessages);
    } catch (IllegalArgumentException e) {
        System.err.println(e);
        String expectOut = expectMessages.iterator().next().text;
        if (expectResult != Main.Result.CMDERR)
            error("unexpected exception caught");
        else if (!e.getMessage().equals(expectOut)) {
            error("unexpected exception message: "
                    + e.getMessage()
                    + " expected: " + expectOut);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:IncludePackagesTest.java

示例13: test

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) {
        System.err.println("test: " + opts);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        List<JavaFileObject> files = Arrays.asList(file);
        try {
            JavacTask t = (JavacTask) javac.getTask(pw, fm, null, opts, null, files);
            boolean ok = t.call();
            pw.close();
            String out = sw.toString().replaceAll("[\r\n]+", "\n");
            if (!out.isEmpty())
                System.err.println(out);
            if (ok && expectResult != Main.Result.OK) {
                error("Compilation succeeded unexpectedly");
            } else if (!ok && expectResult != Main.Result.ERROR) {
                error("Compilation failed unexpectedly");
            } else
                check(out, expectMessages);
        } catch (IllegalArgumentException e) {
            System.err.println(e);
            String expectOut = expectMessages.iterator().next().text;
            if (expectResult != Main.Result.CMDERR)
                error("unexpected exception caught");
            else if (!e.getMessage().equals(expectOut)) {
                error("unexpected exception message: "
                        + e.getMessage()
                        + " expected: " + expectOut);
            }
        }

//        if (errors > 0)
//            throw new Error("stop");
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:DocLintTest.java

示例14: test

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
/**
 * The worker method for each test case.
 * Compile the files and verify that exactly the expected set of header files
 * is generated.
 */
void test(RunKind rk, GenKind gk, List<File> files, Set<String> expect) throws Exception {
    List<String> args = new ArrayList<String>();
    if (gk == GenKind.FULL)
        args.add("-XDjavah:full");

    switch (rk) {
        case CMD:
            args.add("-d");
            args.add(classesDir.getPath());
            args.add("-h");
            args.add(headersDir.getPath());
            for (File f: files)
                args.add(f.getPath());
            int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]));
            if (rc != 0)
                throw new Exception("compilation failed, rc=" + rc);
            break;

        case API:
            fm.setLocation(StandardLocation.SOURCE_PATH, Arrays.asList(srcDir));
            fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(classesDir));
            fm.setLocation(StandardLocation.NATIVE_HEADER_OUTPUT, Arrays.asList(headersDir));
            JavacTask task = javac.getTask(null, fm, null, args, null,
                    fm.getJavaFileObjectsFromFiles(files));
            if (!task.call())
                throw new Exception("compilation failed");
            break;
    }

    Set<String> found = createSet(headersDir.list());
    checkEqual("header files", expect, found);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:38,代碼來源:NativeHeaderTest.java

示例15: compileOne

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
private File compileOne(Type type) {
    if (this.flags.contains(Flags.USECACHE)) {
        File dir = cache.get(type.getName());
        if (dir != null) {
            return dir;
        }
    }
    List<JavaFileObject> files = new ArrayList<>();
    SourceProcessor accum = (name, src) -> files.add(new SourceFile(name, src));

    for (Type dep : type.typeDependencies()) {
        dep.generateAsDependency(accum, type.methodDependencies());
    }

    type.generate(accum);

    JavacTask ct = (JavacTask)this.systemJavaCompiler.getTask(
        null, this.fm, null, null, null, files);
    File destDir = null;
    do {
        int value = counter.incrementAndGet();
        destDir = new File(root, Integer.toString(value));
    } while (destDir.exists());

    if (this.flags.contains(Flags.VERBOSE)) {
        System.out.println("Compilation unit for " + type.getName() +
            " : compiled into " + destDir);
        for (JavaFileObject jfo : files) {
            System.out.println(jfo.toString());
        }
    }

    try {
        destDir.mkdirs();
        this.fm.setLocation(
            StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
    } catch (IOException e) {
        throw new RuntimeException(
            "IOException encountered during compilation");
    }
    Boolean result = ct.call();
    if (result == Boolean.FALSE) {
        throw new RuntimeException(
            "Compilation failure in " + type.getName() + " unit");
    }
    if (this.flags.contains(Flags.USECACHE)) {
        File existing = cache.putIfAbsent(type.getName(), destDir);
        if (existing != null) {
            deleteDir(destDir);
            return existing;
        }
    } else {
    this.tempDirs.add(destDir);
    }
    return destDir;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:57,代碼來源:Compiler.java


注:本文中的com.sun.source.util.JavacTask.call方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。