当前位置: 首页>>代码示例>>Java>>正文


Java JavacTool.create方法代码示例

本文整理汇总了Java中com.sun.tools.javac.api.JavacTool.create方法的典型用法代码示例。如果您正苦于以下问题:Java JavacTool.create方法的具体用法?Java JavacTool.create怎么用?Java JavacTool.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.tools.javac.api.JavacTool的用法示例。


在下文中一共展示了JavacTool.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
/**
 * method-run.
 */
void run() throws Exception {
    File testSrc = new File(System.getProperty("test.src"));
    File file = new File(testSrc, "TestDocComments.java");

    JavacTool tool = JavacTool.create();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjects(file);
        JavacTask task = tool.getTask(pw, fm, null, null, null, fileObjects);
        Iterable<? extends CompilationUnitTree> units = task.parse();
        Trees trees = Trees.instance(task);

        CommentScanner s = new CommentScanner();
        int n = s.scan(units, trees);

        if (n != 12)
            error("Unexpected number of doc comments found: " + n);

        if (errors > 0)
            throw new Exception(errors + " errors occurred");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:TestDocComments.java

示例2: testAnnotationProcessing

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
static void testAnnotationProcessing(JavacFileManager fm, List<JavaFileObject> files) throws Throwable {
    Context context = new Context();

    String[] args = {
            "-XprintRounds",
            "-processorpath", testClasses,
            "-processor", self,
            "-d", "."
    };

    JavacTool tool = JavacTool.create();
    JavacTask task = tool.getTask(null, fm, null, List.from(args), null, files, context);
    // no need in this simple case to call task.prepareCompiler(false)

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(files);
    try {
        compiler.compile(files);
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:T6358168.java

示例3: main

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    PrintWriter out = new PrintWriter(System.out, true);
    JavacTool tool = JavacTool.create();
    try (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, "ArrayCreationTree.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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ArrayCreationTree.java

示例4: main

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    PrintWriter out = new PrintWriter(System.out, true);
    JavacTool tool = JavacTool.create();
    try (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, "AnnotatedArrayOrder.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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:AnnotatedArrayOrder.java

示例5: main

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    PrintWriter out = new PrintWriter(System.out, true);
    JavacTool tool = JavacTool.create();
    try (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, "ArrayPositionConsistency.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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ArrayPositionConsistency.java

示例6: read

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
/**
 * Read a file.
 * @param file the file to be read
 * @return the tree for the content of the file
 * @throws IOException if any IO errors occur
 * @throws TreePosTest.ParseException if any errors occur while parsing the file
 */
JCCompilationUnit read(File file) throws IOException, ParseException {
    JavacTool tool = JavacTool.create();
    r.errors = 0;
    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
    JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    pw.flush();
    if (r.errors > 0)
        throw new ParseException(sw.toString());
    Iterator<? extends CompilationUnitTree> iter = trees.iterator();
    if (!iter.hasNext())
        throw new Error("no trees found");
    JCCompilationUnit t = (JCCompilationUnit) iter.next();
    if (iter.hasNext())
        throw new Error("too many trees found");
    return t;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:AbstractTreeScannerTest.java

示例7: read

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
/**
 * Read a file.
 * @param file the file to be read
 * @return the tree for the content of the file
 * @throws IOException if any IO errors occur
 * @throws TreePosTest.ParseException if any errors occur while parsing the file
 */
JCCompilationUnit read(File file) throws IOException, ParseException {
    JavacTool tool = JavacTool.create();
    r.errors = 0;
    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
    JavacTask task = tool.getTask(pw, fm, r, List.of("-proc:none"), null, files);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    pw.flush();
    if (r.errors > 0)
        throw new ParseException(sw.toString());
    Iterator<? extends CompilationUnitTree> iter = trees.iterator();
    if (!iter.hasNext())
        throw new Error("no trees found");
    JCCompilationUnit t = (JCCompilationUnit) iter.next();
    if (iter.hasNext())
        throw new Error("too many trees found");
    return t;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:TreePosTest.java

示例8: main

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    Context context = new Context();
    MyMessages.preRegister(context);
    JavacTool tool = JavacTool.create();
    JavacTask task = tool.getTask(null, null, null, null, null,
                                  List.of(new MyFileObject()),
                                  context);
    task.parse();
    for (Element e : task.analyze()) {
        if (!e.getEnclosingElement().toString().equals("compiler.misc.unnamed.package"))
            throw new AssertionError(e.getEnclosingElement());
        System.out.println("OK: " + e.getEnclosingElement());
        return;
    }
    throw new AssertionError("No top-level classes!");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:T6457284.java

示例9: main

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
    String testSrc = System.getProperty("test.src", ".");
    String testClasses = System.getProperty("test.classes", ".");
    JavacTool tool = JavacTool.create();
    MyDiagListener dl = new MyDiagListener();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(testClasses)));
        Iterable<? extends JavaFileObject> files =
            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6410706.class.getName()+".java")));
        JavacTask task = tool.getTask(null, fm, dl, null, null, files);
        task.parse();
        task.analyze();
        task.generate();

        // expect 2 notes:
        // Note: T6410706.java uses or overrides a deprecated API.
        // Note: Recompile with -Xlint:deprecation for details.

        if (dl.notes != 2)
            throw new AssertionError(dl.notes + " notes given");
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:23,代码来源:T6410706.java

示例10: main

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
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.");
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:23,代码来源:T6403466.java

示例11: run

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
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");
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:18,代码来源:T6993305.java

示例12: run

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
/** Combo test to run all test cases in all modes. */
void run() throws Exception {
    javac = JavacTool.create();
    fm = javac.getStandardFileManager(null, null, null);

    for (RunKind rk: RunKind.values()) {
        for (GenKind gk: GenKind.values()) {
            for (Method m: getClass().getDeclaredMethods()) {
                Annotation a = m.getAnnotation(Test.class);
                if (a != null) {
                    init(rk, gk, m.getName());
                    try {
                        m.invoke(this, new Object[] { rk, gk });
                    } catch (InvocationTargetException e) {
                        Throwable cause = e.getCause();
                        throw (cause instanceof Exception) ? ((Exception) cause) : e;
                    }
                    System.err.println();
                }
            }
        }
    }
    System.err.println(testCount + " tests" + ((errorCount == 0) ? "" : ", " + errorCount + " errors"));
    if (errorCount > 0)
        throw new Exception(errorCount + " errors found");
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:27,代码来源:NativeHeaderTest.java

示例13: main

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
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, "ArrayPositionConsistency.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);

}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:17,代码来源:ArrayPositionConsistency.java

示例14: main

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    PrintWriter out = new PrintWriter(System.out, true);
    JavacTool tool = JavacTool.create();
    try (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);
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:17,代码来源:T6345974.java

示例15: main

import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
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, "ArrayCreationTree.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);

}
 
开发者ID:wmdietl,项目名称:jsr308-langtools,代码行数:17,代码来源:ArrayCreationTree.java


注:本文中的com.sun.tools.javac.api.JavacTool.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。