コード例 #1
0
ファイル: Enter.java プロジェクト: loverdos/javac-openjdk7
 /** Visitor method: enter classes of a list of trees, returning a list of types. */
 <T extends JCTree> List<Type> classEnter(List<T> trees, Env<AttrContext> env) {
   ListBuffer<Type> ts = new ListBuffer<Type>();
   for (List<T> l = trees; l.nonEmpty(); l = l.tail) {
     Type t = classEnter(l.head, env);
     if (t != null) ts.append(t);
   }
   return ts.toList();
 }
コード例 #2
0
  /**
   * 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();
    }
  }
コード例 #3
0
 JavacTaskImpl(
     Main compilerMain,
     String[] args,
     String[] classNames,
     Context context,
     List<JavaFileObject> fileObjects) {
   this.ccw = ClientCodeWrapper.instance(context);
   this.compilerMain = compilerMain;
   this.args = args;
   this.classNames = classNames;
   this.context = context;
   this.fileObjects = fileObjects;
   setLocale(Locale.getDefault());
   // null checks
   compilerMain.getClass();
   args.getClass();
   fileObjects.getClass();
 }
コード例 #4
0
 private static List<JavaFileObject> toList(Iterable<? extends JavaFileObject> fileObjects) {
   if (fileObjects == null) return List.nil();
   ListBuffer<JavaFileObject> result = new ListBuffer<JavaFileObject>();
   for (JavaFileObject fo : fileObjects) result.append(fo);
   return result.toList();
 }
コード例 #5
0
 public List<Attribute> getValue() {
   return List.from(values);
 }
コード例 #6
0
 static Type makeClassType(Types types, Type type) {
   Type arg = type.isPrimitive() ? types.boxedClass(type).type : types.erasure(type);
   return new Type.ClassType(
       types.syms.classType.getEnclosingType(), List.of(arg), types.syms.classType.tsym);
 }