Search in sources :

Example 56 with CompilationUnitTree

use of com.sun.source.tree.CompilationUnitTree 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);
}
Also used : CompilationUnitTree(com.sun.source.tree.CompilationUnitTree) JavaCompiler(javax.tools.JavaCompiler) StandardJavaFileManager(javax.tools.StandardJavaFileManager) JavacTask(com.sun.source.util.JavacTask) File(java.io.File) ImportTree(com.sun.source.tree.ImportTree)

Aggregations

CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)56 JavacTask (com.sun.source.util.JavacTask)24 JavaCompiler (javax.tools.JavaCompiler)21 JavaFileObject (javax.tools.JavaFileObject)16 Tree (com.sun.source.tree.Tree)15 ClassTree (com.sun.source.tree.ClassTree)14 VariableTree (com.sun.source.tree.VariableTree)10 JavacTool (com.sun.tools.javac.api.JavacTool)9 JCTree (com.sun.tools.javac.tree.JCTree)9 IOException (java.io.IOException)9 MethodTree (com.sun.source.tree.MethodTree)8 ArrayList (java.util.ArrayList)8 Trees (com.sun.source.util.Trees)7 JavacTaskImpl (com.sun.tools.javac.api.JavacTaskImpl)6 SimpleJavaFileObject (javax.tools.SimpleJavaFileObject)6 StandardJavaFileManager (javax.tools.StandardJavaFileManager)6 BinaryTree (com.sun.source.tree.BinaryTree)5 ExpressionTree (com.sun.source.tree.ExpressionTree)5 IdentifierTree (com.sun.source.tree.IdentifierTree)5 TreePath (com.sun.source.util.TreePath)5