use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class T6665791 method main.
public static void main(String[] args) throws Exception {
write(test_java, test);
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager manager = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> units = manager.getJavaFileObjects(test_java);
final StringWriter sw = new StringWriter();
JavacTask task = (JavacTask) compiler.getTask(sw, manager, null, null, null, units);
new TreeScanner<Boolean, Void>() {
@Override
public Boolean visitClass(ClassTree arg0, Void arg1) {
sw.write(arg0.toString());
return super.visitClass(arg0, arg1);
}
}.scan(task.parse(), null);
System.out.println("output:");
System.out.println(sw.toString());
String found = sw.toString().replaceAll("\\s+", " ").trim();
String expect = test.replaceAll("\\s+", " ").trim();
if (!expect.equals(found)) {
System.out.println("expect: " + expect);
System.out.println("found: " + found);
throw new Exception("unexpected output");
}
}
use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class InterruptedExceptionTest method main.
public static void main(String... args) throws Exception {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
for (XlintOption xlint : XlintOption.values()) {
for (SuppressLevel suppress_decl : SuppressLevel.values()) {
for (SuppressLevel suppress_use : SuppressLevel.values()) {
for (ClassKind ck : ClassKind.values()) {
for (ExceptionKind ek_decl : ExceptionKind.values()) {
for (ExceptionKind ek_use : ExceptionKind.values()) {
new InterruptedExceptionTest(xlint, suppress_decl, suppress_use, ck, ek_decl, ek_use).run(comp, fm);
}
}
}
}
}
}
}
use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class UnusedResourcesTest method test.
static void test(XlintOption xlint, SuppressLevel suppressLevel, ResourceUsage usage1, ResourceUsage usage2, ResourceUsage usage3) throws Exception {
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavaSource source = new JavaSource(suppressLevel, usage1, usage2, usage3);
DiagnosticChecker dc = new DiagnosticChecker();
JavacTask ct = (JavacTask) tool.getTask(null, fm, dc, Arrays.asList(xlint.getXlintOption()), null, Arrays.asList(source));
ct.analyze();
check(source, xlint, suppressLevel, usage1, usage2, usage3, dc);
}
use of javax.tools.JavaCompiler 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 javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class DisjunctiveTypeWellFormednessTest method main.
public static void main(String... args) throws Exception {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
for (Arity arity : Arity.values()) {
for (Alternative a1 : Alternative.values()) {
if (arity == Arity.ONE) {
new DisjunctiveTypeWellFormednessTest(a1).run(comp, fm);
continue;
}
for (Alternative a2 : Alternative.values()) {
if (arity == Arity.TWO) {
new DisjunctiveTypeWellFormednessTest(a1, a2).run(comp, fm);
continue;
}
for (Alternative a3 : Alternative.values()) {
if (arity == Arity.THREE) {
new DisjunctiveTypeWellFormednessTest(a1, a2, a3).run(comp, fm);
continue;
}
for (Alternative a4 : Alternative.values()) {
if (arity == Arity.FOUR) {
new DisjunctiveTypeWellFormednessTest(a1, a2, a3, a4).run(comp, fm);
continue;
}
for (Alternative a5 : Alternative.values()) {
new DisjunctiveTypeWellFormednessTest(a1, a2, a3, a4, a5).run(comp, fm);
}
}
}
}
}
}
}
Aggregations