示例#1
0
 public JCTree visitOther(Tree node, P p) {
   JCTree tree = (JCTree) node;
   switch (tree.getTag()) {
     case JCTree.LETEXPR:
       {
         LetExpr t = (LetExpr) node;
         List<JCVariableDecl> defs = copy(t.defs, p);
         JCTree expr = copy(t.expr, p);
         return M.at(t.pos).LetExpr(defs, expr);
       }
     default:
       throw new AssertionError("unknown tree tag: " + tree.getTag());
   }
 }
  /**
   * Translate the given abstract syntax trees to elements.
   *
   * @param trees a list of abstract syntax trees.
   * @throws java.io.IOException TODO
   * @return a list of elements corresponding to the top level classes in the abstract syntax trees
   */
  public Iterable<? extends TypeElement> enter(Iterable<? extends CompilationUnitTree> trees)
      throws IOException {
    prepareCompiler();

    ListBuffer<JCCompilationUnit> roots = null;

    if (trees == null) {
      // If there are still files which were specified to be compiled
      // (i.e. in fileObjects) but which have not yet been entered,
      // then we make sure they have been parsed and add them to the
      // list to be entered.
      if (notYetEntered.size() > 0) {
        if (!parsed) parse(); // TODO would be nice to specify files needed to be parsed
        for (JavaFileObject file : fileObjects) {
          JCCompilationUnit unit = notYetEntered.remove(file);
          if (unit != null) {
            if (roots == null) roots = new ListBuffer<JCCompilationUnit>();
            roots.append(unit);
          }
        }
        notYetEntered.clear();
      }
    } else {
      for (CompilationUnitTree cu : trees) {
        if (cu instanceof JCCompilationUnit) {
          if (roots == null) roots = new ListBuffer<JCCompilationUnit>();
          roots.append((JCCompilationUnit) cu);
          notYetEntered.remove(cu.getSourceFile());
        } else throw new IllegalArgumentException(cu.toString());
      }
    }

    if (roots == null) return List.nil();

    try {
      List<JCCompilationUnit> units = compiler.enterTrees(roots.toList());

      if (notYetEntered.isEmpty()) compiler = compiler.processAnnotations(units);

      ListBuffer<TypeElement> elements = new ListBuffer<TypeElement>();
      for (JCCompilationUnit unit : units) {
        for (JCTree node : unit.defs) {
          if (node.getTag() == JCTree.CLASSDEF) {
            JCClassDecl cdef = (JCClassDecl) node;
            if (cdef.sym != null) // maybe null if errors in anno processing
            elements.append(cdef.sym);
          }
        }
      }
      return elements.toList();
    } finally {
      compiler.log.flush();
    }
  }
 private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
   List<ClassSymbol> classes = List.nil();
   for (JCCompilationUnit unit : units) {
     for (JCTree node : unit.defs) {
       if (node.getTag() == JCTree.CLASSDEF) {
         ClassSymbol sym = ((JCClassDecl) node).sym;
         Assert.checkNonNull(sym);
         classes = classes.prepend(sym);
       }
     }
   }
   return classes.reverse();
 }
示例#4
0
 /** Is the given tree an enumerator definition? */
 boolean isEnumerator(JCTree t) {
   return t.getTag() == JCTree.VARDEF && (((JCVariableDecl) t).mods.flags & ENUM) != 0;
 }