use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class T6557752 method main.
public static void main(String[] args) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
task = (JavacTask) compiler.getTask(null, null, null, null, null, List.of(new MyFileObject()));
Iterable<? extends CompilationUnitTree> asts = task.parse();
task.analyze();
trees = Trees.instance(task);
MyVisitor myVisitor = new MyVisitor();
for (CompilationUnitTree ast : asts) {
myVisitor.compilationUnit = ast;
myVisitor.scan(ast, null);
}
if (!myVisitor.foundError) {
throw new AssertionError("Expected error not found!");
}
}
use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class T6550655 method main.
public static void main(String[] args) throws Exception {
String SCRATCH_DIR = System.getProperty("user.dir");
JavaCompiler javacTool = ToolProvider.getSystemJavaCompiler();
int n = 0;
for (TestKind testKind : TestKind.values()) {
for (EnumActionKind actionKind : EnumActionKind.values()) {
File testDir = new File(SCRATCH_DIR, "test" + n);
new T6550655(javacTool, testDir, testKind, actionKind).test();
n++;
}
}
if (nerrors > 0) {
throw new AssertionError("Some errors have been detected");
}
}
use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class Launcher method main.
public static void main(String... args) {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
JFileChooser fileChooser;
Preferences prefs = Preferences.userNodeForPackage(Launcher.class);
if (args.length > 0)
fileChooser = new JFileChooser(args[0]);
else {
String fileName = prefs.get("recent.file", null);
fileChooser = new JFileChooser();
if (fileName != null) {
fileChooser = new JFileChooser();
fileChooser.setSelectedFile(new File(fileName));
}
}
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
String fileName = fileChooser.getSelectedFile().getPath();
prefs.put("recent.file", fileName);
javac.run(System.in, null, null, "-d", "/tmp", fileName);
}
}
use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class JavahTask method run.
public boolean run() throws Util.Exit {
Util util = new Util(log, diagnosticListener);
if (noArgs || help) {
showHelp();
// treat noArgs as an error for purposes of exit code
return help;
}
if (version || fullVersion) {
showVersion(fullVersion);
return true;
}
util.verbose = verbose;
Gen g;
if (llni)
g = new LLNI(doubleAlign, util);
else {
// if (stubs)
// throw new BadArgs("jni.no.stubs");
g = new JNI(util);
}
if (ofile != null) {
if (!(fileManager instanceof StandardJavaFileManager)) {
diagnosticListener.report(createDiagnostic("err.cant.use.option.for.fm", "-o"));
return false;
}
Iterable<? extends JavaFileObject> iter = ((StandardJavaFileManager) fileManager).getJavaFileObjectsFromFiles(Collections.singleton(ofile));
JavaFileObject fo = iter.iterator().next();
g.setOutFile(fo);
} else {
if (odir != null) {
if (!(fileManager instanceof StandardJavaFileManager)) {
diagnosticListener.report(createDiagnostic("err.cant.use.option.for.fm", "-d"));
return false;
}
if (!odir.exists())
if (!odir.mkdirs())
util.error("cant.create.dir", odir.toString());
try {
((StandardJavaFileManager) fileManager).setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(odir));
} catch (IOException e) {
Object msg = e.getLocalizedMessage();
if (msg == null) {
msg = e;
}
diagnosticListener.report(createDiagnostic("err.ioerror", odir, msg));
return false;
}
}
g.setFileManager(fileManager);
}
/*
* Force set to false will turn off smarts about checking file
* content before writing.
*/
g.setForce(force);
if (fileManager instanceof JavahFileManager)
((JavahFileManager) fileManager).setIgnoreSymbolFile(true);
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
List<String> opts = new ArrayList<String>();
opts.add("-proc:only");
opts.addAll(javac_extras);
CompilationTask t = c.getTask(log, fileManager, diagnosticListener, opts, internalize(classes), null);
JavahProcessor p = new JavahProcessor(g);
t.setProcessors(Collections.singleton(p));
boolean ok = t.call();
if (p.exit != null)
throw new Util.Exit(p.exit);
return ok;
}
use of javax.tools.JavaCompiler 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);
}
}
Aggregations