Exemplo n.º 1
1
 /**
  * Creates a Tree of the given elements.
  *
  * @param <T> Component type of the List.
  * @param values Zero or more values.
  * @return A Tree containing the given values.
  * @throws NullPointerException if {@code values} is null
  */
 @SuppressWarnings("varargs")
 @SafeVarargs
 static <T> Tree<T> of(T... values) {
   Objects.requireNonNull(values, "values is null");
   List<T> list = List.of(values);
   return list.isEmpty() ? Empty.instance() : new Node<>(list.head(), list.tail().map(Tree::of));
 }
Exemplo n.º 2
0
 /**
  * Creates a rose tree branch of one or more children.
  *
  * @param value The value of the branch node.
  * @param child1 The first child
  * @param children More children, may be none
  * @param <T> The value type
  * @return A new rose tree branch
  */
 @SafeVarargs
 @SuppressWarnings("varargs")
 static <T> Branch<T> branch(T value, NonNil<T> child1, NonNil<T>... children) {
   Objects.requireNonNull(child1, "child1 is null");
   Objects.requireNonNull(children, "children is null");
   final List<NonNil<T>> list = List.of(children).prepend(child1);
   return new Branch<>(value, list);
 }
Exemplo n.º 3
0
 /**
  * Creates either a rose tree branch or a leaf, depending on the child count. By definition, a
  * node with no children is a leaf.
  *
  * @param value The value of the node.
  * @param children The tree node's non-nil children, i.e. leafs and branches.
  * @param <T> The value type
  * @return A new, non-nil rose tree
  */
 @SafeVarargs
 @SuppressWarnings("varargs")
 static <T> NonNil<T> of(T value, NonNil<T>... children) {
   Objects.requireNonNull(children, "children is null");
   if (children.length == 0) {
     return new Leaf<>(value);
   } else {
     final List<NonNil<T>> list = List.of(children);
     return new Branch<>(value, list);
   }
 }
Exemplo n.º 4
0
 /**
  * Returns a new Node containing the given value and having the given children.
  *
  * @param value A value
  * @param children The child nodes, possibly empty
  * @param <T> Value type
  * @return A new Node instance.
  */
 @SuppressWarnings("varargs")
 @SafeVarargs
 static <T> Node<T> of(T value, Node<T>... children) {
   Objects.requireNonNull(children, "children is null");
   return new Node<>(value, List.of(children));
 }
  /**
   * Main method: compile a list of files, return all compiled classes
   *
   * @param filenames The names of all files to be compiled.
   */
  public List<ClassSymbol> compile(
      List<String> filenames,
      Map<String, String> origOptions,
      ClassLoader aptCL,
      AnnotationProcessorFactory providedFactory,
      java.util.Set<Class<? extends AnnotationProcessorFactory>> productiveFactories,
      java.util.Set<java.io.File> aggregateGenFiles)
      throws Throwable {
    // as a JavaCompiler can only be used once, throw an exception if
    // it has been used before.
    assert !hasBeenUsed : "attempt to reuse JavaCompiler";
    hasBeenUsed = true;

    this.aggregateGenFiles = aggregateGenFiles;

    long msec = System.currentTimeMillis();

    ListBuffer<ClassSymbol> classes = new ListBuffer<ClassSymbol>();
    try {
      JavacFileManager fm = (JavacFileManager) fileManager;
      // parse all files
      ListBuffer<JCCompilationUnit> trees = new ListBuffer<JCCompilationUnit>();
      for (List<String> l = filenames; l.nonEmpty(); l = l.tail) {
        if (classesAsDecls) {
          if (!l.head.endsWith(".java")) { // process as class file
            ClassSymbol cs = reader.enterClass(names.fromString(l.head));
            try {
              cs.complete();
            } catch (Symbol.CompletionFailure cf) {
              bark.aptError("CantFindClass", l);
              continue;
            }

            classes.append(cs); // add to list of classes
            continue;
          }
        }
        JavaFileObject fo = fm.getJavaFileObjectsFromStrings(List.of(l.head)).iterator().next();
        trees.append(parse(fo));
      }

      // enter symbols for all files
      List<JCCompilationUnit> roots = trees.toList();

      if (errorCount() == 0) {
        boolean prev = bark.setDiagnosticsIgnored(true);
        try {
          enter.main(roots);
        } finally {
          bark.setDiagnosticsIgnored(prev);
        }
      }

      if (errorCount() == 0) {
        apt.main(roots, classes, origOptions, aptCL, providedFactory, productiveFactories);
        genSourceFileNames.addAll(apt.getSourceFileNames());
        genClassFileNames.addAll(apt.getClassFileNames());
      }

    } catch (Abort ex) {
    }

    if (verbose) log.printVerbose("total", Long.toString(System.currentTimeMillis() - msec));

    chk.reportDeferredDiagnostics();

    printCount("error", errorCount());
    printCount("warn", warningCount());

    return classes.toList();
  }