Java Code Examples for com.sun.tools.javac.util.Log#DeferredDiagnosticHandler

The following examples show how to use com.sun.tools.javac.util.Log#DeferredDiagnosticHandler . 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: JavacProcessingEnvironment.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Create a round (common code). */
private Round(Context context, int number, int priorErrors, int priorWarnings,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this.context = context;
    this.number = number;

    compiler = JavaCompiler.instance(context);
    log = Log.instance(context);
    log.nerrors = priorErrors;
    log.nwarnings = priorWarnings;
    if (number == 1) {
        Assert.checkNonNull(deferredDiagnosticHandler);
        this.deferredDiagnosticHandler = deferredDiagnosticHandler;
    } else {
        this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
    }

    // the following is for the benefit of JavacProcessingEnvironment.getContext()
    JavacProcessingEnvironment.this.context = context;

    // the following will be populated as needed
    topLevelClasses  = List.nil();
    packageInfoFiles = List.nil();
}
 
Example 2
Source File: JavacProcessingEnvironment.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/** Create the first round. */
Round(Context context, List<JCCompilationUnit> roots, List<ClassSymbol> classSymbols,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this(context, 1, 0, 0, deferredDiagnosticHandler);
    this.roots = roots;
    genClassFiles = new HashMap<String,JavaFileObject>();

    compiler.todo.clear(); // free the compiler's resources

    // The reverse() in the following line is to maintain behavioural
    // compatibility with the previous revision of the code. Strictly speaking,
    // it should not be necessary, but a javah golden file test fails without it.
    topLevelClasses =
        getTopLevelClasses(roots).prependList(classSymbols.reverse());

    packageInfoFiles = getPackageInfoFiles(roots);

    findAnnotationsPresent();
}
 
Example 3
Source File: JavacProcessingEnvironment.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/** Create the first round. */
Round(Context context, List<JCCompilationUnit> roots, List<ClassSymbol> classSymbols,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this(context, 1, 0, 0, deferredDiagnosticHandler);
    this.roots = roots;
    genClassFiles = new HashMap<String,JavaFileObject>();

    compiler.todo.clear(); // free the compiler's resources

    // The reverse() in the following line is to maintain behavioural
    // compatibility with the previous revision of the code. Strictly speaking,
    // it should not be necessary, but a javah golden file test fails without it.
    topLevelClasses =
        getTopLevelClasses(roots).prependList(classSymbols.reverse());

    packageInfoFiles = getPackageInfoFiles(roots);

    findAnnotationsPresent();
}
 
Example 4
Source File: JavacProcessingEnvironment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/** Create a round (common code). */
private Round(Context context, int number, int priorErrors, int priorWarnings,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this.context = context;
    this.number = number;

    compiler = JavaCompiler.instance(context);
    log = Log.instance(context);
    log.nerrors = priorErrors;
    log.nwarnings = priorWarnings;
    if (number == 1) {
        Assert.checkNonNull(deferredDiagnosticHandler);
        this.deferredDiagnosticHandler = deferredDiagnosticHandler;
    } else {
        this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
    }

    // the following is for the benefit of JavacProcessingEnvironment.getContext()
    JavacProcessingEnvironment.this.context = context;

    // the following will be populated as needed
    topLevelClasses  = List.nil();
    packageInfoFiles = List.nil();
}
 
Example 5
Source File: JavacProcessingEnvironment.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** Create a round (common code). */
private Round(Context context, int number, int priorErrors, int priorWarnings,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this.context = context;
    this.number = number;

    compiler = JavaCompiler.instance(context);
    log = Log.instance(context);
    log.nerrors = priorErrors;
    log.nwarnings = priorWarnings;
    if (number == 1) {
        Assert.checkNonNull(deferredDiagnosticHandler);
        this.deferredDiagnosticHandler = deferredDiagnosticHandler;
    } else {
        this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
    }

    // the following is for the benefit of JavacProcessingEnvironment.getContext()
    JavacProcessingEnvironment.this.context = context;

    // the following will be populated as needed
    topLevelClasses  = List.nil();
    packageInfoFiles = List.nil();
}
 
Example 6
Source File: JavacProcessingEnvironment.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** Create the first round. */
Round(Context context, List<JCCompilationUnit> roots, List<ClassSymbol> classSymbols,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this(context, 1, 0, 0, deferredDiagnosticHandler);
    this.roots = roots;
    genClassFiles = new HashMap<String,JavaFileObject>();

    compiler.todo.clear(); // free the compiler's resources

    // The reverse() in the following line is to maintain behavioural
    // compatibility with the previous revision of the code. Strictly speaking,
    // it should not be necessary, but a javah golden file test fails without it.
    topLevelClasses =
        getTopLevelClasses(roots).prependList(classSymbols.reverse());

    packageInfoFiles = getPackageInfoFiles(roots);

    findAnnotationsPresent();
}
 
Example 7
Source File: DeferredAttr.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
<Z> JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo, TreeCopier<Z> deferredCopier,
                             Function<JCTree, DeferredDiagnosticHandler> diagHandlerCreator,
                             LocalCacheContext localCache) {
    final JCTree newTree = deferredCopier.copy(tree);
    Env<AttrContext> speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared(env.info.scope.owner)));
    speculativeEnv.info.isSpeculative = true;
    Log.DeferredDiagnosticHandler deferredDiagnosticHandler = diagHandlerCreator.apply(newTree);
    try {
        attr.attribTree(newTree, speculativeEnv, resultInfo);
        return newTree;
    } finally {
        new UnenterScanner(env.toplevel.modle).scan(newTree);
        log.popDiagnosticHandler(deferredDiagnosticHandler);
        if (localCache != null) {
            localCache.leave();
        }
    }
}
 
Example 8
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Create a round (common code). */
private Round(int number, Set<JCCompilationUnit> treesToClean,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this.number = number;

    if (number == 1) {
        Assert.checkNonNull(deferredDiagnosticHandler);
        this.deferredDiagnosticHandler = deferredDiagnosticHandler;
    } else {
        this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
        compiler.setDeferredDiagnosticHandler(this.deferredDiagnosticHandler);
    }

    // the following will be populated as needed
    topLevelClasses  = List.nil();
    packageInfoFiles = List.nil();
    moduleInfoFiles = List.nil();
    this.treesToClean = treesToClean;
}
 
Example 9
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Create the first round. */
Round(List<JCCompilationUnit> roots,
      List<ClassSymbol> classSymbols,
      Set<JCCompilationUnit> treesToClean,
      Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this(1, treesToClean, deferredDiagnosticHandler);
    this.roots = roots;
    genClassFiles = new HashMap<>();

    // The reverse() in the following line is to maintain behavioural
    // compatibility with the previous revision of the code. Strictly speaking,
    // it should not be necessary, but a javah golden file test fails without it.
    topLevelClasses =
        getTopLevelClasses(roots).prependList(classSymbols.reverse());

    packageInfoFiles = getPackageInfoFiles(roots);

    moduleInfoFiles = getModuleInfoFiles(roots);

    findAnnotationsPresent();
}
 
Example 10
Source File: JavacProcessingEnvironment.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Create the first round. */
Round(Context context, List<JCCompilationUnit> roots, List<ClassSymbol> classSymbols,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this(context, 1, 0, 0, deferredDiagnosticHandler);
    this.roots = roots;
    genClassFiles = new HashMap<String,JavaFileObject>();

    compiler.todo.clear(); // free the compiler's resources

    // The reverse() in the following line is to maintain behavioural
    // compatibility with the previous revision of the code. Strictly speaking,
    // it should not be necessary, but a javah golden file test fails without it.
    topLevelClasses =
        getTopLevelClasses(roots).prependList(classSymbols.reverse());

    packageInfoFiles = getPackageInfoFiles(roots);

    findAnnotationsPresent();
}
 
Example 11
Source File: JavacProcessingEnvironment.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/** Create the first round. */
Round(Context context, List<JCCompilationUnit> roots, List<ClassSymbol> classSymbols,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this(context, 1, 0, 0, deferredDiagnosticHandler);
    this.roots = roots;
    genClassFiles = new HashMap<String,JavaFileObject>();

    compiler.todo.clear(); // free the compiler's resources

    // The reverse() in the following line is to maintain behavioural
    // compatibility with the previous revision of the code. Strictly speaking,
    // it should not be necessary, but a javah golden file test fails without it.
    topLevelClasses =
        getTopLevelClasses(roots).prependList(classSymbols.reverse());

    packageInfoFiles = getPackageInfoFiles(roots);

    findAnnotationsPresent();
}
 
Example 12
Source File: Analyzer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Simple deferred diagnostic handler which filters out all messages and keep track of errors.
 */
Log.DeferredDiagnosticHandler diagHandler() {
    return new Log.DeferredDiagnosticHandler(log, d -> {
        if (d.getType() == DiagnosticType.ERROR) {
            erroneous = true;
        }
        return true;
    });
}
 
Example 13
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 14
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 15
Source File: JavaCompiler.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setDeferredDiagnosticHandler(Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this.deferredDiagnosticHandler = deferredDiagnosticHandler;
}
 
Example 16
Source File: ReferenceParser.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Parse a reference to an API element as may be found in doc comment.
 * @param sig the signature to be parsed
 * @return a {@code Reference} object containing the result of parsing the signature
 * @throws ParseException if there is an error while parsing the signature
 */
public Reference parse(String sig) throws ParseException {

    // Break sig apart into qualifiedExpr member paramTypes.
    JCTree qualExpr;
    Name member;
    List<JCTree> paramTypes;

    Log.DeferredDiagnosticHandler deferredDiagnosticHandler
            = new Log.DeferredDiagnosticHandler(fac.log);

    try {
        int hash = sig.indexOf("#");
        int lparen = sig.indexOf("(", hash + 1);
        if (hash == -1) {
            if (lparen == -1) {
                qualExpr = parseType(sig);
                member = null;
            } else {
                qualExpr = null;
                member = parseMember(sig.substring(0, lparen));
            }
        } else {
            qualExpr = (hash == 0) ? null : parseType(sig.substring(0, hash));
            if (lparen == -1)
                member = parseMember(sig.substring(hash + 1));
            else
                member = parseMember(sig.substring(hash + 1, lparen));
        }

        if (lparen < 0) {
            paramTypes = null;
        } else {
            int rparen = sig.indexOf(")", lparen);
            if (rparen != sig.length() - 1)
                throw new ParseException("dc.ref.bad.parens");
            paramTypes = parseParams(sig.substring(lparen + 1, rparen));
        }

        if (!deferredDiagnosticHandler.getDiagnostics().isEmpty())
            throw new ParseException("dc.ref.syntax.error");

    } finally {
        fac.log.popDiagnosticHandler(deferredDiagnosticHandler);
    }

    return new Reference(qualExpr, member, paramTypes);
}
 
Example 17
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 18
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 19
Source File: JavacProcessingEnvironment.java    From hottub 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 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;
}