Package com.sun.tools.javac.api

Examples of com.sun.tools.javac.api.JavacTool


        if (sourcepath == null)
            throw new IllegalArgumentException("sourcepath not set");
        if (outdir == null)
            throw new IllegalArgumentException("source output dir not set");

        JavacTool tool = JavacTool.create();
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

        try {
            fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir));
            fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath));
            List<JavaFileObject> files = new ArrayList<JavaFileObject>();
            for (String c: classes) {
                JavaFileObject fo = fm.getJavaFileForInput(
                        StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE);
                if (fo == null)
                    error("class not found: " + c);
                else
                    files.add(fo);
            }

            JavacTask t = tool.getTask(null, fm, null, null, null, files);
            Iterable<? extends CompilationUnitTree> trees = t.parse();
            for (CompilationUnitTree tree: trees) {
                makeStub(fm, tree);
            }
        } catch (IOException e) {
View Full Code Here


        if (javacFiles.isEmpty()) {
            if (!needHelp)
                out.println(localize("dc.main.no.files.given"));
        }

        JavacTool tool = JavacTool.create();

        JavacFileManager fm = new JavacFileManager(new Context(), false, null);
        fm.setSymbolFileEnabled(false);
        fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, javacBootClassPath);
        fm.setLocation(StandardLocation.CLASS_PATH, javacClassPath);
        fm.setLocation(StandardLocation.SOURCE_PATH, javacSourcePath);

        JavacTask task = tool.getTask(out, fm, null, javacOpts, null,
                fm.getJavaFileObjectsFromFiles(javacFiles));
        Iterable<? extends CompilationUnitTree> units = task.parse();
        ((JavacTaskImpl) task).enter();

        env.init(task);
View Full Code Here

        args.add("-processorpath");
        args.add(System.getProperty("java.class.path"));
        args.add("-d");
        args.add(".");

        JavacTool t = JavacTool.create(); // avoid using class loader

        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, "
View Full Code Here

    static final String testClassDir = System.getProperty("test.classes");
    static final String self = T6403466.class.getName();
    static PrintWriter out = new PrintWriter(System.err, true);

    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())
View Full Code Here

        if (sourcepath == null)
            throw new IllegalArgumentException("sourcepath not set");
        if (outdir == null)
            throw new IllegalArgumentException("source output dir not set");

        JavacTool tool = JavacTool.create();
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

        try {
            fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir));
            fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath));
            List<JavaFileObject> files = new ArrayList<JavaFileObject>();
            for (String c: classes) {
                JavaFileObject fo = fm.getJavaFileForInput(
                        StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE);
                if (fo == null)
                    error("class not found: " + c);
                else
                    files.add(fo);
            }

            JavacTask t = tool.getTask(null, fm, null, null, null, files);
            Iterable<? extends CompilationUnitTree> trees = t.parse();
            for (CompilationUnitTree tree: trees) {
                makeStub(fm, tree);
            }
        } catch (IOException e) {
View Full Code Here

public abstract class T6397044 {
    public static void main(String[] args) throws Exception {
        String srcDir = System.getProperty("test.src", ".");
        String self = T6397044.class.getName();
        JavacTool tool = JavacTool.create();
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
        Iterable<? extends JavaFileObject> files
            = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcDir, self + ".java")));
        JavacTask task = tool.getTask(null, fm, null, null, null, files);
        Iterable<? extends CompilationUnitTree> trees = task.parse();
        Checker checker = new Checker();
        for (CompilationUnitTree tree: trees)
            checker.check(tree);
    }
View Full Code Here

            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);
View Full Code Here

        }

        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);
View Full Code Here

     * @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();
View Full Code Here

     * @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();
View Full Code Here

TOP

Related Classes of com.sun.tools.javac.api.JavacTool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.