use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class T6733837 method exec.
public void exec() {
JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"), Kind.SOURCE) {
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return "\tclass ErroneousWithTab";
}
};
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw);
List<? extends JavaFileObject> files = Arrays.asList(sfo);
task = tool.getTask(sw, fm, null, null, null, files);
try {
((JavacTask) task).analyze();
} catch (Throwable t) {
throw new Error("Compiler threw an exception");
}
System.err.println(sw.toString());
if (!sw.toString().contains("/Test.java"))
throw new Error("Bad source name in diagnostic");
}
use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class T6852595 method main.
public static void main(String[] args) throws IOException {
JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"), Kind.SOURCE) {
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return "class BadName { Object o = j; }";
}
};
List<? extends JavaFileObject> files = Arrays.asList(sfo);
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTask ct = (JavacTask) tool.getTask(null, null, null, null, null, files);
Iterable<? extends CompilationUnitTree> compUnits = ct.parse();
CompilationUnitTree cu = compUnits.iterator().next();
ClassTree cdef = (ClassTree) cu.getTypeDecls().get(0);
JCVariableDecl vdef = (JCVariableDecl) cdef.getMembers().get(0);
TreePath path = TreePath.getPath(cu, vdef.init);
Trees.instance(ct).getScope(path);
}
use of com.sun.source.util.JavacTask 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.source.util.JavacTask in project ceylon-compiler by ceylon.
the class TestCircularClassfile method check.
static void check(String destPath, ClassName clazz, ClassName sup) throws Exception {
File destDir = new File(workDir, destPath);
destDir.mkdir();
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTask ct = (JavacTask) tool.getTask(null, null, null, Arrays.asList("-d", destPath), null, Arrays.asList(initialSources));
ct.generate();
File fileToRemove = new File(destPath, clazz.name + ".class");
fileToRemove.delete();
JavaSource newSource = new JavaSource(clazz, sup);
DiagnosticChecker checker = new DiagnosticChecker();
ct = (JavacTask) tool.getTask(null, null, checker, Arrays.asList("-cp", destPath), null, Arrays.asList(newSource));
ct.analyze();
if (!checker.errorFound) {
throw new AssertionError(newSource.source);
}
}
use of com.sun.source.util.JavacTask 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");
}
Aggregations