use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class T6404194 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) {
// 01234567890123456 7890 123456789012345
return "@SuppressWarning(\"foo\") @Deprecated 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();
ClassTree classTree = (ClassTree) toplevel.getTypeDecls().get(0);
List<? extends Tree> annotations = classTree.getModifiers().getAnnotations();
Tree tree1 = annotations.get(0);
Tree tree2 = annotations.get(1);
long pos = trees.getSourcePositions().getStartPosition(toplevel, tree1);
if (pos != 0)
throw new AssertionError(String.format("Start pos for %s is incorrect (%s)!", tree1, pos));
pos = trees.getSourcePositions().getEndPosition(toplevel, tree1);
if (pos != 23)
throw new AssertionError(String.format("End pos for %s is incorrect (%s)!", tree1, pos));
pos = trees.getSourcePositions().getStartPosition(toplevel, tree2);
if (pos != 24)
throw new AssertionError(String.format("Start pos for %s is incorrect (%s)!", tree2, pos));
pos = trees.getSourcePositions().getEndPosition(toplevel, tree2);
if (pos != 35)
throw new AssertionError(String.format("End pos for %s is incorrect (%s)!", tree2, pos));
}
use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class TestSuppression method test.
void test(String src, WarningKind wk, int gen) throws Exception {
count++;
System.err.println("Test " + count + ": wk:" + wk + " gen:" + gen + " src:" + src);
File testDir = new File("test" + count);
File srcDir = createDir(testDir, "src");
File gensrcDir = createDir(testDir, "gensrc");
File classesDir = createDir(testDir, "classes");
File x = writeFile(new File(srcDir, "X.java"), src);
DiagListener dl = new DiagListener();
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(classesDir, new File(System.getProperty("test.classes"))));
fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir));
fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir));
List<String> args = new ArrayList<String>();
// args.add("-XprintProcessorInfo");
args.add("-XprintRounds");
args.add("-Agen=" + gen);
if (wk == WarningKind.YES)
args.add("-Xlint:serial");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavacTask task = tool.getTask(pw, fm, dl, args, null, files);
task.setProcessors(Arrays.asList(new AnnoProc()));
boolean ok = task.call();
pw.close();
System.err.println("ok:" + ok + " diags:" + dl.counts);
if (sw.toString().length() > 0) {
System.err.println("output:\n" + sw.toString());
}
for (Diagnostic.Kind dk : Diagnostic.Kind.values()) {
Integer v = dl.counts.get(dk);
int found = (v == null) ? 0 : v;
int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0;
if (found != expect) {
error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found);
}
}
System.err.println();
}
use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class ImplementationCacheTest method main.
public static void main(String[] args) throws IOException {
List<? extends JavaFileObject> files = Arrays.asList(new SourceFile());
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTask ct = (JavacTask) tool.getTask(null, null, null, null, null, files);
Context ctx = new Context();
JavacFileManager.preRegister(ctx);
checkImplementationCache(ct.analyze(), Types.instance(ctx));
}
use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class CeylonDocToolTests method compileJavaModule.
private void compileJavaModule(String pathname, String... fileNames) throws Exception {
CeyloncTool compiler = new CeyloncTool();
List<String> options = Arrays.asList("-src", pathname, "-out", "build/ceylon-cars", "-cp", CompilerTests.getClassPathAsPath());
JavacFileManager fileManager = compiler.getStandardFileManager(null, null, null);
List<String> qualifiedNames = new ArrayList<String>(fileNames.length);
for (String name : fileNames) {
qualifiedNames.add(pathname + File.separator + name);
}
Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjectsFromStrings(qualifiedNames);
JavacTask task = compiler.getTask(null, null, null, options, null, fileObjects);
Boolean ret = task.call();
Assert.assertEquals("Compilation failed", Boolean.TRUE, ret);
}
use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class CeylonDocToolTests method compile.
private void compile(String pathname, String destDir, String moduleName) throws Exception {
CeyloncTool compiler = new CeyloncTool();
List<String> options = Arrays.asList("-src", pathname, "-out", destDir, "-cp", CompilerTests.getClassPathAsPath());
JavacTask task = compiler.getTask(null, null, null, options, Arrays.asList(moduleName), null);
Boolean ret = task.call();
Assert.assertEquals("Compilation failed", Boolean.TRUE, ret);
}
Aggregations