use of com.sun.source.tree.CompilationUnitTree in project ceylon by eclipse.
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);
}
use of com.sun.source.tree.CompilationUnitTree 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);
}
use of com.sun.source.tree.CompilationUnitTree in project ceylon by eclipse.
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 com.sun.source.tree.CompilationUnitTree in project btrace by btraceio.
the class Verifier method verify.
// verify each BTrace class
private boolean verify(ClassTree ct, Element topElement) {
currentClass = ct;
CompilationUnitTree cut = getCompilationUnit();
String className = ct.getSimpleName().toString();
ExpressionTree pkgName = cut.getPackageName();
if (pkgName != null) {
className = pkgName + "." + className;
}
classNames.add(className);
if (hasTrustedAnnotation(ct, topElement)) {
return true;
}
Boolean value = ct.accept(new VerifierVisitor(this, topElement), null);
return value == null ? true : value;
}
use of com.sun.source.tree.CompilationUnitTree in project ceylon-compiler by ceylon.
the class T6345974 method main.
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "T6345974.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t : trees) s.scan(t, null);
}
Aggregations