use of com.sun.source.util.JavacTask in project ceylon by eclipse.
the class AbstractTreeScannerTest 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
*/
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;
}
use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class T6345974 method main.
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, "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);
}
use of com.sun.source.util.JavacTask 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);
}
use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class T6402077 method main.
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) {
// 0123456789012345678901234
return "class Test { Test() { } }";
}
}
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
List<JavaFileObject> compilationUnits = Collections.<JavaFileObject>singletonList(new MyFileObject());
JavacTask task = (JavacTask) javac.getTask(null, null, null, null, null, compilationUnits);
Trees trees = Trees.instance(task);
CompilationUnitTree toplevel = task.parse().iterator().next();
Tree tree = ((ClassTree) toplevel.getTypeDecls().get(0)).getMembers().get(0);
long pos = trees.getSourcePositions().getStartPosition(toplevel, tree);
if (pos != 13)
throw new AssertionError(String.format("Start pos for %s is incorrect (%s)!", tree, pos));
pos = trees.getSourcePositions().getEndPosition(toplevel, tree);
if (pos != 23)
throw new AssertionError(String.format("End pos for %s is incorrect (%s)!", tree, pos));
}
use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class DisjunctiveTypeWellFormednessTest method run.
void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
JavacTask ct = (JavacTask) tool.getTask(null, fm, diagChecker, null, null, Arrays.asList(source));
ct.analyze();
check();
}
Aggregations