title: Compilation unit visitor - Java compiler tree api
body: <p>I am using the compiler Tree api to parse my code into a AST, but the method visitCompilationUnit is never called, althrough the method visitClass is called, what am I doing wrong?</p>
  
  <p>Second question: is there any way to tell the compiler to truncate the compiled code (I am interrested only in the AST, not in the class file).</p>
  
  <p>Thanks.</p>
  
  <pre><code>@SupportedSourceVersion(value=SourceVersion.RELEASE_7)
  @SupportedAnnotationTypes("*")
  public class Parser extends AbstractProcessor {
  .
  .
  .
      @Override
      public boolean process(Set&lt;? extends TypeElement&gt; annotations, RoundEnvironment roundEnvironment) {
         for (Element e : roundEnvironment.getRootElements()) {
              System.out.println(e + "***");
              TreePath tp = trees.getPath(e);
              // invoke the scanner
              rootVisitor.scan(tp, trees);
          }
          return true;
      }
  }
  
  
  
  public class OdpaVisitor extends TreePathScanner&lt;Object, Trees&gt; {
  
      protected RepositoryIface repository;
  
      private String pckg;
  
      public OdpaVisitor(RepositoryIface repository) {
          this.repository = repository;
      }
  
      @Override
      public Object visitCompilationUnit(CompilationUnitTree node, Trees p) {
          repository.savePackage(node.getPackageName().toString());
          this.pckg = node.getPackageName().toString();
          return super.visitCompilationUnit(node, p);
      }    
  
      @Override
      public Object visitClass(ClassTree node, Trees p) {
          repository.saveClass(node.getSimpleName().toString(), pckg);
          return super.visitClass(node, p);
      }
  }
  </code></pre>