Java Code Examples for com.sun.tools.javac.util.List#appendList()

The following examples show how to use com.sun.tools.javac.util.List#appendList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeAnnotations.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Create a copy of the {@code Type type} with the help of the Tree for a type
 * {@code JCTree typetree} inserting all type annotations in {@code annotations} to the
 * innermost array component type.
 *
 * SIDE EFFECT: Update position for the annotations to be {@code pos}.
 */
private Type rewriteArrayType(ArrayType type, List<TypeCompound> annotations, TypeAnnotationPosition pos) {
    ArrayType tomodify = new ArrayType(type);
    ArrayType res = tomodify;

    List<TypePathEntry> loc = List.nil();

    // peel one and update loc
    Type tmpType = type.elemtype;
    loc = loc.prepend(TypePathEntry.ARRAY);

    while (tmpType.hasTag(TypeTag.ARRAY)) {
        ArrayType arr = (ArrayType)tmpType;

        // Update last type with new element type
        ArrayType tmp = new ArrayType(arr);
        tomodify.elemtype = tmp;
        tomodify = tmp;

        tmpType = arr.elemtype;
        loc = loc.prepend(TypePathEntry.ARRAY);
    }

    // Fix innermost element type
    Type elemType;
    if (tmpType.getMetadata() != null) {
        List<TypeCompound> tcs;
        if (tmpType.getAnnotationMirrors().isEmpty()) {
            tcs = annotations;
        } else {
            // Special case, lets prepend
            tcs =  annotations.appendList(tmpType.getAnnotationMirrors());
        }
        elemType = tmpType.cloneWithMetadata(tmpType
                .getMetadata()
                .without(Kind.ANNOTATIONS)
                .combine(new TypeMetadata.Annotations(tcs)));
    } else {
        elemType = tmpType.cloneWithMetadata(new TypeMetadata(new TypeMetadata.Annotations(annotations)));
    }
    tomodify.elemtype = elemType;

    // Update positions
    for (TypeCompound tc : annotations) {
        if (tc.position == null)
            tc.position = pos;
        tc.position.location = loc;
    }

    return res;
}
 
Example 2
Source File: JavacProcessingEnvironment.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static <T> List<T> join(List<T> list1, List<T> list2) {
    return list1.appendList(list2);
}
 
Example 3
Source File: TypeAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a copy of the {@code Type type} with the help of the Tree for a type
 * {@code JCTree typetree} inserting all type annotations in {@code annotations} to the
 * innermost array component type.
 *
 * SIDE EFFECT: Update position for the annotations to be {@code pos}.
 */
private Type rewriteArrayType(ArrayType type, List<TypeCompound> annotations, TypeAnnotationPosition pos) {
    ArrayType tomodify = new ArrayType(type);
    ArrayType res = tomodify;

    List<TypePathEntry> loc = List.nil();

    // peel one and update loc
    Type tmpType = type.elemtype;
    loc = loc.prepend(TypePathEntry.ARRAY);

    while (tmpType.hasTag(TypeTag.ARRAY)) {
        ArrayType arr = (ArrayType)tmpType;

        // Update last type with new element type
        ArrayType tmp = new ArrayType(arr);
        tomodify.elemtype = tmp;
        tomodify = tmp;

        tmpType = arr.elemtype;
        loc = loc.prepend(TypePathEntry.ARRAY);
    }

    // Fix innermost element type
    Type elemType;
    if (tmpType.getMetadata() != null) {
        List<TypeCompound> tcs;
        if (tmpType.getAnnotationMirrors().isEmpty()) {
            tcs = annotations;
        } else {
            // Special case, lets prepend
            tcs =  annotations.appendList(tmpType.getAnnotationMirrors());
        }
        elemType = tmpType.cloneWithMetadata(tmpType
                .getMetadata()
                .without(Kind.ANNOTATIONS)
                .combine(new TypeMetadata.Annotations(tcs)));
    } else {
        elemType = tmpType.cloneWithMetadata(new TypeMetadata(new TypeMetadata.Annotations(annotations)));
    }
    tomodify.elemtype = elemType;

    // Update positions
    for (TypeCompound tc : annotations) {
        if (tc.position == null)
            tc.position = pos;
        tc.position.location = loc;
    }

    return res;
}
 
Example 4
Source File: JavacProcessingEnvironment.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static <T> List<T> join(List<T> list1, List<T> list2) {
    return list1.appendList(list2);
}
 
Example 5
Source File: JavacProcessingEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public boolean doProcessing(List<JCCompilationUnit> roots,
                            List<ClassSymbol> classSymbols,
                            Iterable<? extends PackageSymbol> pckSymbols,
                            Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    final Set<JCCompilationUnit> treesToClean =
            Collections.newSetFromMap(new IdentityHashMap<JCCompilationUnit, Boolean>());

    //fill already attributed implicit trees:
    for (Env<AttrContext> env : enter.getEnvs()) {
        treesToClean.add(env.toplevel);
    }

    Set<PackageSymbol> specifiedPackages = new LinkedHashSet<>();
    for (PackageSymbol psym : pckSymbols)
        specifiedPackages.add(psym);
    this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages);

    Round round = new Round(roots, classSymbols, treesToClean, deferredDiagnosticHandler);

    boolean errorStatus;
    boolean moreToDo;
    do {
        // Run processors for round n
        round.run(false, false);

        // Processors for round n have run to completion.
        // Check for errors and whether there is more work to do.
        errorStatus = round.unrecoverableError();
        moreToDo = moreToDo();

        round.showDiagnostics(errorStatus || showResolveErrors);

        // Set up next round.
        // Copy mutable collections returned from filer.
        round = round.next(
                new LinkedHashSet<>(filer.getGeneratedSourceFileObjects()),
                new LinkedHashMap<>(filer.getGeneratedClasses()));

         // Check for errors during setup.
        if (round.unrecoverableError())
            errorStatus = true;

    } while (moreToDo && !errorStatus);

    // run last round
    round.run(true, errorStatus);
    round.showDiagnostics(true);

    filer.warnIfUnclosedFiles();
    warnIfUnmatchedOptions();

    /*
     * If an annotation processor raises an error in a round,
     * that round runs to completion and one last round occurs.
     * The last round may also occur because no more source or
     * class files have been generated.  Therefore, if an error
     * was raised on either of the last *two* rounds, the compile
     * should exit with a nonzero exit code.  The current value of
     * errorStatus holds whether or not an error was raised on the
     * second to last round; errorRaised() gives the error status
     * of the last round.
     */
    if (messager.errorRaised()
            || werror && round.warningCount() > 0 && round.errorCount() > 0)
        errorStatus = true;

    Set<JavaFileObject> newSourceFiles =
            new LinkedHashSet<>(filer.getGeneratedSourceFileObjects());
    roots = round.roots;

    errorStatus = errorStatus || (compiler.errorCount() > 0);

    round.finalCompiler();

    if (newSourceFiles.size() > 0)
        roots = roots.appendList(compiler.parseFiles(newSourceFiles));

    errorStatus = errorStatus || (compiler.errorCount() > 0);

    // Free resources
    this.close();

    if (errorStatus && compiler.errorCount() == 0) {
        compiler.log.nerrors++;
    }

    compiler.enterTreesIfNeeded(roots);

    if (!taskListener.isEmpty())
        taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));

    return true;
}
 
Example 6
Source File: JavacProcessingEnvironment.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private static <T> List<T> join(List<T> list1, List<T> list2) {
    return list1.appendList(list2);
}
 
Example 7
Source File: JavacProcessingEnvironment.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public JavaCompiler doProcessing(Context context,
                                 List<JCCompilationUnit> roots,
                                 List<ClassSymbol> classSymbols,
                                 Iterable<? extends PackageSymbol> pckSymbols) {

    TaskListener taskListener = context.get(TaskListener.class);
    log = Log.instance(context);

    Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>();
    for (PackageSymbol psym : pckSymbols)
        specifiedPackages.add(psym);
    this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages);

    Round round = new Round(context, roots, classSymbols);

    boolean errorStatus;
    boolean moreToDo;
    do {
        // Run processors for round n
        round.run(false, false);

        // Processors for round n have run to completion.
        // Check for errors and whether there is more work to do.
        errorStatus = round.unrecoverableError();
        moreToDo = moreToDo();

        round.showDiagnostics(errorStatus || showResolveErrors);

        // Set up next round.
        // Copy mutable collections returned from filer.
        round = round.next(
                new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects()),
                new LinkedHashMap<String,JavaFileObject>(filer.getGeneratedClasses()));

         // Check for errors during setup.
        if (round.unrecoverableError())
            errorStatus = true;

    } while (moreToDo && !errorStatus);

    // run last round
    round.run(true, errorStatus);
    round.showDiagnostics(true);

    filer.warnIfUnclosedFiles();
    warnIfUnmatchedOptions();

    /*
     * If an annotation processor raises an error in a round,
     * that round runs to completion and one last round occurs.
     * The last round may also occur because no more source or
     * class files have been generated.  Therefore, if an error
     * was raised on either of the last *two* rounds, the compile
     * should exit with a nonzero exit code.  The current value of
     * errorStatus holds whether or not an error was raised on the
     * second to last round; errorRaised() gives the error status
     * of the last round.
     */
    if (messager.errorRaised()
            || werror && round.warningCount() > 0 && round.errorCount() > 0)
        errorStatus = true;

    Set<JavaFileObject> newSourceFiles =
            new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects());
    roots = cleanTrees(round.roots);

    JavaCompiler compiler = round.finalCompiler(errorStatus);

    if (newSourceFiles.size() > 0)
        roots = roots.appendList(compiler.parseFiles(newSourceFiles));

    errorStatus = errorStatus || (compiler.errorCount() > 0);

    // Free resources
    this.close();

    if (taskListener != null)
        taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));

    if (errorStatus) {
        if (compiler.errorCount() == 0)
            compiler.log.nerrors++;
        return compiler;
    }

    if (procOnly && !foundTypeProcessors) {
        compiler.todo.clear();
    } else {
        if (procOnly && foundTypeProcessors)
            compiler.shouldStopPolicy = CompileState.FLOW;

        compiler.enterTrees(roots);
    }

    return compiler;
}
 
Example 8
Source File: JavacProcessingEnvironment.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private static <T> List<T> join(List<T> list1, List<T> list2) {
    return list1.appendList(list2);
}
 
Example 9
Source File: JavacProcessingEnvironment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public JavaCompiler doProcessing(Context context,
                                 List<JCCompilationUnit> roots,
                                 List<ClassSymbol> classSymbols,
                                 Iterable<? extends PackageSymbol> pckSymbols,
                                 Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    log = Log.instance(context);

    Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>();
    for (PackageSymbol psym : pckSymbols)
        specifiedPackages.add(psym);
    this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages);

    Round round = new Round(context, roots, classSymbols, deferredDiagnosticHandler);

    boolean errorStatus;
    boolean moreToDo;
    do {
        // Run processors for round n
        round.run(false, false);

        // Processors for round n have run to completion.
        // Check for errors and whether there is more work to do.
        errorStatus = round.unrecoverableError();
        moreToDo = moreToDo();

        round.showDiagnostics(errorStatus || showResolveErrors);

        // Set up next round.
        // Copy mutable collections returned from filer.
        round = round.next(
                new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects()),
                new LinkedHashMap<String,JavaFileObject>(filer.getGeneratedClasses()));

         // Check for errors during setup.
        if (round.unrecoverableError())
            errorStatus = true;

    } while (moreToDo && !errorStatus);

    // run last round
    round.run(true, errorStatus);
    round.showDiagnostics(true);

    filer.warnIfUnclosedFiles();
    warnIfUnmatchedOptions();

    /*
     * If an annotation processor raises an error in a round,
     * that round runs to completion and one last round occurs.
     * The last round may also occur because no more source or
     * class files have been generated.  Therefore, if an error
     * was raised on either of the last *two* rounds, the compile
     * should exit with a nonzero exit code.  The current value of
     * errorStatus holds whether or not an error was raised on the
     * second to last round; errorRaised() gives the error status
     * of the last round.
     */
    if (messager.errorRaised()
            || werror && round.warningCount() > 0 && round.errorCount() > 0)
        errorStatus = true;

    Set<JavaFileObject> newSourceFiles =
            new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects());
    roots = cleanTrees(round.roots);

    JavaCompiler compiler = round.finalCompiler();

    if (newSourceFiles.size() > 0)
        roots = roots.appendList(compiler.parseFiles(newSourceFiles));

    errorStatus = errorStatus || (compiler.errorCount() > 0);

    // Free resources
    this.close();

    if (!taskListener.isEmpty())
        taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));

    if (errorStatus) {
        if (compiler.errorCount() == 0)
            compiler.log.nerrors++;
        return compiler;
    }

    compiler.enterTreesIfNeeded(roots);

    return compiler;
}
 
Example 10
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Generate an indy method call to the meta factory
 */
private JCExpression makeMetafactoryIndyCall(TranslationContext<?> context,
        int refKind, Symbol refSym, List<JCExpression> indy_args) {
    JCFunctionalExpression tree = context.tree;
    //determine the static bsm args
    MethodSymbol samSym = (MethodSymbol) types.findDescriptorSymbol(tree.type.tsym);
    List<Object> staticArgs = List.of(
            typeToMethodType(samSym.type),
            new Pool.MethodHandle(refKind, refSym, types),
            typeToMethodType(tree.getDescriptorType(types)));

    //computed indy arg types
    ListBuffer<Type> indy_args_types = new ListBuffer<>();
    for (JCExpression arg : indy_args) {
        indy_args_types.append(arg.type);
    }

    //finally, compute the type of the indy call
    MethodType indyType = new MethodType(indy_args_types.toList(),
            tree.type,
            List.nil(),
            syms.methodClass);

    Name metafactoryName = context.needsAltMetafactory() ?
            names.altMetafactory : names.metafactory;

    if (context.needsAltMetafactory()) {
        ListBuffer<Object> markers = new ListBuffer<>();
        for (Type t : tree.targets.tail) {
            if (t.tsym != syms.serializableType.tsym) {
                markers.append(t.tsym);
            }
        }
        int flags = context.isSerializable() ? FLAG_SERIALIZABLE : 0;
        boolean hasMarkers = markers.nonEmpty();
        boolean hasBridges = context.bridges.nonEmpty();
        if (hasMarkers) {
            flags |= FLAG_MARKERS;
        }
        if (hasBridges) {
            flags |= FLAG_BRIDGES;
        }
        staticArgs = staticArgs.append(flags);
        if (hasMarkers) {
            staticArgs = staticArgs.append(markers.length());
            staticArgs = staticArgs.appendList(markers.toList());
        }
        if (hasBridges) {
            staticArgs = staticArgs.append(context.bridges.length() - 1);
            for (Symbol s : context.bridges) {
                Type s_erasure = s.erasure(types);
                if (!types.isSameType(s_erasure, samSym.erasure(types))) {
                    staticArgs = staticArgs.append(s.erasure(types));
                }
            }
        }
        if (context.isSerializable()) {
            int prevPos = make.pos;
            try {
                make.at(kInfo.clazz);
                addDeserializationCase(refKind, refSym, tree.type, samSym,
                        tree, staticArgs, indyType);
            } finally {
                make.at(prevPos);
            }
        }
    }

    return makeIndyCall(tree, syms.lambdaMetafactory, metafactoryName, staticArgs, indyType, indy_args, samSym.name);
}
 
Example 11
Source File: JavacProcessingEnvironment.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public JavaCompiler doProcessing(Context context,
                                 List<JCCompilationUnit> roots,
                                 List<ClassSymbol> classSymbols,
                                 Iterable<? extends PackageSymbol> pckSymbols,
                                 Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    log = Log.instance(context);

    Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>();
    for (PackageSymbol psym : pckSymbols)
        specifiedPackages.add(psym);
    this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages);

    Round round = new Round(context, roots, classSymbols, deferredDiagnosticHandler);

    boolean errorStatus;
    boolean moreToDo;
    do {
        // Run processors for round n
        round.run(false, false);

        // Processors for round n have run to completion.
        // Check for errors and whether there is more work to do.
        errorStatus = round.unrecoverableError();
        moreToDo = moreToDo();

        round.showDiagnostics(errorStatus || showResolveErrors);

        // Set up next round.
        // Copy mutable collections returned from filer.
        round = round.next(
                new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects()),
                new LinkedHashMap<String,JavaFileObject>(filer.getGeneratedClasses()));

         // Check for errors during setup.
        if (round.unrecoverableError())
            errorStatus = true;

    } while (moreToDo && !errorStatus);

    // run last round
    round.run(true, errorStatus);
    round.showDiagnostics(true);

    filer.warnIfUnclosedFiles();
    warnIfUnmatchedOptions();

    /*
     * If an annotation processor raises an error in a round,
     * that round runs to completion and one last round occurs.
     * The last round may also occur because no more source or
     * class files have been generated.  Therefore, if an error
     * was raised on either of the last *two* rounds, the compile
     * should exit with a nonzero exit code.  The current value of
     * errorStatus holds whether or not an error was raised on the
     * second to last round; errorRaised() gives the error status
     * of the last round.
     */
    if (messager.errorRaised()
            || werror && round.warningCount() > 0 && round.errorCount() > 0)
        errorStatus = true;

    Set<JavaFileObject> newSourceFiles =
            new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects());
    roots = cleanTrees(round.roots);

    JavaCompiler compiler = round.finalCompiler();

    if (newSourceFiles.size() > 0)
        roots = roots.appendList(compiler.parseFiles(newSourceFiles));

    errorStatus = errorStatus || (compiler.errorCount() > 0);

    // Free resources
    this.close();

    if (!taskListener.isEmpty())
        taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));

    if (errorStatus) {
        if (compiler.errorCount() == 0)
            compiler.log.nerrors++;
        return compiler;
    }

    compiler.enterTreesIfNeeded(roots);

    return compiler;
}
 
Example 12
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static <T> List<T> join(List<T> list1, List<T> list2) {
    return list1.appendList(list2);
}
 
Example 13
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public boolean doProcessing(List<JCCompilationUnit> roots,
                            List<ClassSymbol> classSymbols,
                            Iterable<? extends PackageSymbol> pckSymbols,
                            Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    final Set<JCCompilationUnit> treesToClean =
            Collections.newSetFromMap(new IdentityHashMap<JCCompilationUnit, Boolean>());

    //fill already attributed implicit trees:
    for (Env<AttrContext> env : enter.getEnvs()) {
        treesToClean.add(env.toplevel);
    }

    Set<PackageSymbol> specifiedPackages = new LinkedHashSet<>();
    for (PackageSymbol psym : pckSymbols)
        specifiedPackages.add(psym);
    this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages);

    Round round = new Round(roots, classSymbols, treesToClean, deferredDiagnosticHandler);

    boolean errorStatus;
    boolean moreToDo;
    do {
        // Run processors for round n
        round.run(false, false);

        // Processors for round n have run to completion.
        // Check for errors and whether there is more work to do.
        errorStatus = round.unrecoverableError();
        moreToDo = moreToDo();

        round.showDiagnostics(errorStatus || showResolveErrors);

        // Set up next round.
        // Copy mutable collections returned from filer.
        round = round.next(
                new LinkedHashSet<>(filer.getGeneratedSourceFileObjects()),
                new LinkedHashMap<>(filer.getGeneratedClasses()));

         // Check for errors during setup.
        if (round.unrecoverableError())
            errorStatus = true;

    } while (moreToDo && !errorStatus);

    // run last round
    round.run(true, errorStatus);
    round.showDiagnostics(true);

    filer.warnIfUnclosedFiles();
    warnIfUnmatchedOptions();

    /*
     * If an annotation processor raises an error in a round,
     * that round runs to completion and one last round occurs.
     * The last round may also occur because no more source or
     * class files have been generated.  Therefore, if an error
     * was raised on either of the last *two* rounds, the compile
     * should exit with a nonzero exit code.  The current value of
     * errorStatus holds whether or not an error was raised on the
     * second to last round; errorRaised() gives the error status
     * of the last round.
     */
    if (messager.errorRaised()
            || werror && round.warningCount() > 0 && round.errorCount() > 0)
        errorStatus = true;

    Set<JavaFileObject> newSourceFiles =
            new LinkedHashSet<>(filer.getGeneratedSourceFileObjects());
    roots = round.roots;

    errorStatus = errorStatus || (compiler.errorCount() > 0);

    round.finalCompiler();

    if (newSourceFiles.size() > 0)
        roots = roots.appendList(compiler.parseFiles(newSourceFiles));

    errorStatus = errorStatus || (compiler.errorCount() > 0);

    // Free resources
    this.close();

    if (errorStatus && compiler.errorCount() == 0) {
        compiler.log.nerrors++;
    }

    compiler.enterTreesIfNeeded(roots);

    if (!taskListener.isEmpty())
        taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));

    return true;
}
 
Example 14
Source File: JavacProcessingEnvironment.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static <T> List<T> join(List<T> list1, List<T> list2) {
    return list1.appendList(list2);
}
 
Example 15
Source File: JavacProcessingEnvironment.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public JavaCompiler doProcessing(Context context,
                                 List<JCCompilationUnit> roots,
                                 List<ClassSymbol> classSymbols,
                                 Iterable<? extends PackageSymbol> pckSymbols,
                                 Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    log = Log.instance(context);

    Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>();
    for (PackageSymbol psym : pckSymbols)
        specifiedPackages.add(psym);
    this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages);

    Round round = new Round(context, roots, classSymbols, deferredDiagnosticHandler);

    boolean errorStatus;
    boolean moreToDo;
    do {
        // Run processors for round n
        round.run(false, false);

        // Processors for round n have run to completion.
        // Check for errors and whether there is more work to do.
        errorStatus = round.unrecoverableError();
        moreToDo = moreToDo();

        round.showDiagnostics(errorStatus || showResolveErrors);

        // Set up next round.
        // Copy mutable collections returned from filer.
        round = round.next(
                new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects()),
                new LinkedHashMap<String,JavaFileObject>(filer.getGeneratedClasses()));

         // Check for errors during setup.
        if (round.unrecoverableError())
            errorStatus = true;

    } while (moreToDo && !errorStatus);

    // run last round
    round.run(true, errorStatus);
    round.showDiagnostics(true);

    filer.warnIfUnclosedFiles();
    warnIfUnmatchedOptions();

    /*
     * If an annotation processor raises an error in a round,
     * that round runs to completion and one last round occurs.
     * The last round may also occur because no more source or
     * class files have been generated.  Therefore, if an error
     * was raised on either of the last *two* rounds, the compile
     * should exit with a nonzero exit code.  The current value of
     * errorStatus holds whether or not an error was raised on the
     * second to last round; errorRaised() gives the error status
     * of the last round.
     */
    if (messager.errorRaised()
            || werror && round.warningCount() > 0 && round.errorCount() > 0)
        errorStatus = true;

    Set<JavaFileObject> newSourceFiles =
            new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects());
    roots = cleanTrees(round.roots);

    JavaCompiler compiler = round.finalCompiler();

    if (newSourceFiles.size() > 0)
        roots = roots.appendList(compiler.parseFiles(newSourceFiles));

    errorStatus = errorStatus || (compiler.errorCount() > 0);

    // Free resources
    this.close();

    if (!taskListener.isEmpty())
        taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));

    if (errorStatus) {
        if (compiler.errorCount() == 0)
            compiler.log.nerrors++;
        return compiler;
    }

    compiler.enterTreesIfNeeded(roots);

    return compiler;
}
 
Example 16
Source File: JavacProcessingEnvironment.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
private static <T> List<T> join(List<T> list1, List<T> list2) {
    return list1.appendList(list2);
}
 
Example 17
Source File: JavacProcessingEnvironment.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public JavaCompiler doProcessing(Context context,
                                 List<JCCompilationUnit> roots,
                                 List<ClassSymbol> classSymbols,
                                 Iterable<? extends PackageSymbol> pckSymbols,
                                 Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    log = Log.instance(context);

    Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>();
    for (PackageSymbol psym : pckSymbols)
        specifiedPackages.add(psym);
    this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages);

    Round round = new Round(context, roots, classSymbols, deferredDiagnosticHandler);

    boolean errorStatus;
    boolean moreToDo;
    do {
        // Run processors for round n
        round.run(false, false);

        // Processors for round n have run to completion.
        // Check for errors and whether there is more work to do.
        errorStatus = round.unrecoverableError();
        moreToDo = moreToDo();

        round.showDiagnostics(errorStatus || showResolveErrors);

        // Set up next round.
        // Copy mutable collections returned from filer.
        round = round.next(
                new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects()),
                new LinkedHashMap<String,JavaFileObject>(filer.getGeneratedClasses()));

         // Check for errors during setup.
        if (round.unrecoverableError())
            errorStatus = true;

    } while (moreToDo && !errorStatus);

    // run last round
    round.run(true, errorStatus);
    round.showDiagnostics(true);

    filer.warnIfUnclosedFiles();
    warnIfUnmatchedOptions();

    /*
     * If an annotation processor raises an error in a round,
     * that round runs to completion and one last round occurs.
     * The last round may also occur because no more source or
     * class files have been generated.  Therefore, if an error
     * was raised on either of the last *two* rounds, the compile
     * should exit with a nonzero exit code.  The current value of
     * errorStatus holds whether or not an error was raised on the
     * second to last round; errorRaised() gives the error status
     * of the last round.
     */
    if (messager.errorRaised()
            || werror && round.warningCount() > 0 && round.errorCount() > 0)
        errorStatus = true;

    Set<JavaFileObject> newSourceFiles =
            new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects());
    roots = cleanTrees(round.roots);

    JavaCompiler compiler = round.finalCompiler();

    if (newSourceFiles.size() > 0)
        roots = roots.appendList(compiler.parseFiles(newSourceFiles));

    errorStatus = errorStatus || (compiler.errorCount() > 0);

    // Free resources
    this.close();

    if (!taskListener.isEmpty())
        taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));

    if (errorStatus) {
        if (compiler.errorCount() == 0)
            compiler.log.nerrors++;
        return compiler;
    }

    compiler.enterTreesIfNeeded(roots);

    return compiler;
}
 
Example 18
Source File: JavacProcessingEnvironment.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static <T> List<T> join(List<T> list1, List<T> list2) {
    return list1.appendList(list2);
}
 
Example 19
Source File: JavacProcessingEnvironment.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public JavaCompiler doProcessing(Context context,
                                 List<JCCompilationUnit> roots,
                                 List<ClassSymbol> classSymbols,
                                 Iterable<? extends PackageSymbol> pckSymbols,
                                 Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    log = Log.instance(context);

    Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>();
    for (PackageSymbol psym : pckSymbols)
        specifiedPackages.add(psym);
    this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages);

    Round round = new Round(context, roots, classSymbols, deferredDiagnosticHandler);

    boolean errorStatus;
    boolean moreToDo;
    do {
        // Run processors for round n
        round.run(false, false);

        // Processors for round n have run to completion.
        // Check for errors and whether there is more work to do.
        errorStatus = round.unrecoverableError();
        moreToDo = moreToDo();

        round.showDiagnostics(errorStatus || showResolveErrors);

        // Set up next round.
        // Copy mutable collections returned from filer.
        round = round.next(
                new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects()),
                new LinkedHashMap<String,JavaFileObject>(filer.getGeneratedClasses()));

         // Check for errors during setup.
        if (round.unrecoverableError())
            errorStatus = true;

    } while (moreToDo && !errorStatus);

    // run last round
    round.run(true, errorStatus);
    round.showDiagnostics(true);

    filer.warnIfUnclosedFiles();
    warnIfUnmatchedOptions();

    /*
     * If an annotation processor raises an error in a round,
     * that round runs to completion and one last round occurs.
     * The last round may also occur because no more source or
     * class files have been generated.  Therefore, if an error
     * was raised on either of the last *two* rounds, the compile
     * should exit with a nonzero exit code.  The current value of
     * errorStatus holds whether or not an error was raised on the
     * second to last round; errorRaised() gives the error status
     * of the last round.
     */
    if (messager.errorRaised()
            || werror && round.warningCount() > 0 && round.errorCount() > 0)
        errorStatus = true;

    Set<JavaFileObject> newSourceFiles =
            new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects());
    roots = cleanTrees(round.roots);

    JavaCompiler compiler = round.finalCompiler();

    if (newSourceFiles.size() > 0)
        roots = roots.appendList(compiler.parseFiles(newSourceFiles));

    errorStatus = errorStatus || (compiler.errorCount() > 0);

    // Free resources
    this.close();

    if (!taskListener.isEmpty())
        taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));

    if (errorStatus) {
        if (compiler.errorCount() == 0)
            compiler.log.nerrors++;
        return compiler;
    }

    compiler.enterTreesIfNeeded(roots);

    return compiler;
}
 
Example 20
Source File: JavacProcessingEnvironment.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static <T> List<T> join(List<T> list1, List<T> list2) {
    return list1.appendList(list2);
}