use of javax.tools.StandardJavaFileManager in project ceylon by eclipse.
the class T6458823 method main.
public static void main(String[] args) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) {
throw new RuntimeException("can't get javax.tools.JavaCompiler!");
}
DiagnosticCollector<JavaFileObject> diagColl = new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
List<String> options = new ArrayList<String>();
options.add("-processor");
options.add("MyProcessor");
options.add("-proc:only");
List<File> files = new ArrayList<File>();
files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
final CompilationTask task = compiler.getTask(null, fm, diagColl, options, null, fm.getJavaFileObjectsFromFiles(files));
task.call();
int diagCount = 0;
for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
if (diag.getKind() != Diagnostic.Kind.WARNING) {
throw new AssertionError("Only warnings expected");
}
System.out.println(diag);
if (diag.getPosition() == Diagnostic.NOPOS) {
throw new AssertionError("No position info in message");
}
if (diag.getSource() == null) {
throw new AssertionError("No source info in message");
}
diagCount++;
}
if (diagCount != 2) {
throw new AssertionError("unexpected number of warnings: " + diagCount + ", expected: 2");
}
}
use of javax.tools.StandardJavaFileManager in project ceylon by eclipse.
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 by eclipse.
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.StandardJavaFileManager in project ceylon by eclipse.
the class GenericConstructorAndDiamondTest 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 (BoundKind boundKind : BoundKind.values()) {
for (ConstructorKind constructorKind : ConstructorKind.values()) {
for (TypeArgumentKind declArgKind : TypeArgumentKind.values()) {
for (TypeArgArity arity : TypeArgArity.values()) {
for (TypeArgumentKind useArgKind : TypeArgumentKind.values()) {
for (TypeArgumentKind diamondArgKind : TypeArgumentKind.values()) {
for (ArgumentKind argKind : ArgumentKind.values()) {
new GenericConstructorAndDiamondTest(boundKind, constructorKind, declArgKind, arity, useArgKind, diamondArgKind, argKind).run(comp, fm);
}
}
}
}
}
}
}
}
use of javax.tools.StandardJavaFileManager in project ceylon by eclipse.
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);
}
Aggregations