use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class ParserTest 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 (TypeQualifierArity arity : TypeQualifierArity.values()) {
for (TypeArgumentKind tak1 : TypeArgumentKind.values()) {
if (arity == TypeQualifierArity.ONE) {
new ParserTest(arity, tak1).run(comp, fm);
continue;
}
for (TypeArgumentKind tak2 : TypeArgumentKind.values()) {
if (arity == TypeQualifierArity.TWO) {
new ParserTest(arity, tak1, tak2).run(comp, fm);
continue;
}
for (TypeArgumentKind tak3 : TypeArgumentKind.values()) {
if (arity == TypeQualifierArity.THREE) {
new ParserTest(arity, tak1, tak2, tak3).run(comp, fm);
continue;
}
for (TypeArgumentKind tak4 : TypeArgumentKind.values()) {
new ParserTest(arity, tak1, tak2, tak3, tak4).run(comp, fm);
}
}
}
}
}
}
use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class TestTreePath method run.
public void run() throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> tests = fileManager.getJavaFileObjects(writeTestFile());
JavaCompiler.CompilationTask task = ToolProvider.getSystemJavaCompiler().getTask(null, null, null, Arrays.asList("-processor", this.getClass().getName()), null, tests);
task.call();
}
use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class T6956638 method test.
void test(File... sourceFiles) throws Exception {
System.err.println("Test " + (++count) + ": " + Arrays.asList(sourceFiles));
File classesDir = new File("classes" + count);
classesDir.mkdirs();
StringWriter compilerOutputStream = new StringWriter();
List<String> compileOptions = Arrays.asList("-d", classesDir.getPath());
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticCollector, null, null);
Iterable<? extends JavaFileObject> sourceFileObjects = fileManager.getJavaFileObjects(sourceFiles);
System.err.println("1- javac given java source JavaFileObjects " + sourceFileObjects);
JavaCompiler.CompilationTask task = compiler.getTask(compilerOutputStream, fileManager, null, compileOptions, null, sourceFileObjects);
JavacTask javacTask = (JavacTask) task;
Iterable<? extends CompilationUnitTree> parsedTrees = javacTask.parse();
Iterable<? extends Element> analyzedTrees = javacTask.analyze();
Iterable<? extends JavaFileObject> generatedFiles = javacTask.generate();
System.err.println("2- parsed:" + size(parsedTrees) + " analysed:" + size(analyzedTrees) + " generated:" + size(generatedFiles));
System.err.print("3-");
for (JavaFileObject f : generatedFiles) System.err.print(" " + f);
System.err.println("");
System.err.print("5-");
for (File f : classesDir.listFiles()) System.err.print(" " + f);
System.err.println("");
System.err.println("----");
System.err.println(compilerOutputStream.toString());
if (size(generatedFiles) != size(parsedTrees)) {
throw new Exception("wrong number of files generated: " + size(generatedFiles) + " expected: " + size(parsedTrees));
}
}
use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class T6993301 method testExceptionParameterCorrectKind.
public void testExceptionParameterCorrectKind() throws IOException {
final String bootPath = System.getProperty("sun.boot.class.path");
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
assert tool != null;
String code = "package test; public class Test { { try { } catch (NullPointerException ex) {} } }";
final JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath), null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next();
ct.analyze();
new TreePathScanner<Void, Void>() {
@Override
public Void visitVariable(VariableTree node, Void p) {
Element el = Trees.instance(ct).getElement(getCurrentPath());
assertNotNull(el);
assertEquals(ElementKind.EXCEPTION_PARAMETER, el.getKind());
return super.visitVariable(node, p);
}
}.scan(cut, null);
}
use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class T6654037 method main.
public static void main(String[] args) throws Exception {
//NOI18N
final String bootPath = System.getProperty("sun.boot.class.path");
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
assert tool != null;
String code = "package test; public class Test {private void test() {Object o = null; boolean b = o != null && o instanceof String;} private Test() {}}";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath, "-Xjcov"), null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
MethodTree method = (MethodTree) clazz.getMembers().get(0);
VariableTree condSt = (VariableTree) method.getBody().getStatements().get(1);
BinaryTree cond = (BinaryTree) condSt.getInitializer();
JCTree condJC = (JCTree) cond;
if (condJC.pos != 93)
throw new IllegalStateException("Unexpected position=" + condJC.pos);
}
Aggregations