use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class T6472751 method main.
public static void main(String[] args) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
JavacTask task = (JavacTask) compiler.getTask(null, null, null, null, null, List.of(new MyFileObject()));
trees = Trees.instance(task);
positions = trees.getSourcePositions();
Iterable<? extends CompilationUnitTree> asts = task.parse();
for (CompilationUnitTree ast : asts) {
new MyVisitor().scan(ast, null);
}
}
use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
the class TestContainTypes method compileAndCheck.
static void compileAndCheck(ParameterType ptA, ClassType ctA, ParameterType ptB, ClassType ctB) throws Exception {
JavaSource source = new JavaSource(ptA.instantiate(ctA), ptB.instantiate(ctB));
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTask ct = (JavacTask) tool.getTask(null, null, null, null, null, Arrays.asList(source));
ct.setProcessors(Arrays.asList(new ContainTypesTester(ParameterType.contains(ptA, ctA, ptB, ctB), source)));
System.err.println("A = " + ptA + " / " + ptA.instantiate(ctA));
System.err.println("B = " + ptB + " / " + ptB.instantiate(ctB));
System.err.println("Source = " + source.source);
ct.analyze();
}
use of javax.tools.JavaCompiler in project ceylon-compiler by ceylon.
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.JavaCompiler 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 javax.tools.JavaCompiler 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));
}
Aggregations