use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.
the class GenStubs method run.
boolean run(String sourcepath, File outdir, List<String> classes) {
//System.err.println("run: sourcepath:" + sourcepath + " outdir:" + outdir + " classes:" + classes);
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) {
error("IO error " + e, e);
}
return (errors == 0);
}
use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.
the class T6397044 method main.
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);
}
use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.
the class Foo method main.
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();
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();
if (dl.notes != 2)
throw new AssertionError(dl.notes + " notes given");
}
use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.
the class CheckAttributedTree method read.
/**
* 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
*/
List<Pair<JCCompilationUnit, JCTree>> read(File file) throws IOException, AttributionException {
JavacTool tool = JavacTool.create();
r.errors = 0;
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
String[] opts = { "-XDshouldStopPolicy=ATTR", "-XDverboseCompilePolicy" };
JavacTask task = tool.getTask(pw, fm, r, Arrays.asList(opts), null, files);
final List<Element> analyzedElems = new ArrayList<>();
task.setTaskListener(new TaskListener() {
public void started(TaskEvent e) {
if (e.getKind() == TaskEvent.Kind.ANALYZE)
analyzedElems.add(e.getTypeElement());
}
public void finished(TaskEvent e) {
}
});
try {
Iterable<? extends CompilationUnitTree> trees = task.parse();
task.analyze();
List<Pair<JCCompilationUnit, JCTree>> res = new ArrayList<>();
//System.out.println("Try to add pairs. Elems are " + analyzedElems);
for (CompilationUnitTree t : trees) {
JCCompilationUnit cu = (JCCompilationUnit) t;
for (JCTree def : cu.defs) {
if (def.getTag() == JCTree.CLASSDEF && analyzedElems.contains(((JCTree.JCClassDecl) def).sym)) {
//System.out.println("Adding pair...");
res.add(new Pair<>(cu, def));
}
}
}
return res;
} catch (Throwable t) {
throw new AttributionException("Exception while attributing file: " + file);
}
}
use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.
the class TestDocComments method run.
/**
* 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();
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");
}
Aggregations