use of javax.tools.StandardJavaFileManager in project ceylon-compiler by ceylon.
the class JarFromManifestFailure method compile.
static void compile(File classOutDir, Iterable<File> classPath, File... files) {
System.err.println("compile...");
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjectsFromFiles(Arrays.asList(files));
List<String> options = new ArrayList<String>();
if (classOutDir != null) {
options.add("-d");
options.add(classOutDir.getPath());
}
if (classPath != null) {
options.add("-classpath");
options.add(join(classPath, File.pathSeparator));
}
options.add("-verbose");
JavaCompiler.CompilationTask task = compiler.getTask(null, fm, null, options, null, fileObjects);
if (!task.call())
throw new AssertionError("compilation failed");
}
use of javax.tools.StandardJavaFileManager in project ceylon-compiler by ceylon.
the class T6963934 method main.
public static void main(String[] args) throws Exception {
File testSrc = new File(System.getProperty("test.src"));
File thisSrc = new File(testSrc, T6963934.class.getSimpleName() + ".java");
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
JavacTask task = (JavacTask) compiler.getTask(null, fileManager, null, null, null, fileManager.getJavaFileObjects(thisSrc));
CompilationUnitTree tree = task.parse().iterator().next();
int count = 0;
for (ImportTree importTree : tree.getImports()) {
System.out.println(importTree);
count++;
}
int expected = 7;
if (count != expected)
throw new Exception("unexpected number of imports found: " + count + ", expected: " + expected);
}
use of javax.tools.StandardJavaFileManager 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.StandardJavaFileManager 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.StandardJavaFileManager 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));
}
}
Aggregations