this.context = currentContext;
roundNumber++;
printRoundInfo(xout, roundNumber, topLevelClasses, annotationsPresent, false);
if (taskListener != null)
taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
try {
discoverAndRunProcs(currentContext, annotationsPresent, topLevelClasses, packageInfoFiles);
} finally {
if (taskListener != null)
taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
}
/*
* Processors for round n have run to completion. Prepare
* for round (n+1) by checked for errors raised by
* annotation processors and then checking for syntax
* errors on any generated source files.
*/
if (messager.errorRaised()) {
errorStatus = true;
break runAround;
} else {
if (moreToDo()) {
// annotationsPresentInSource = List.nil();
annotationsPresent = new LinkedHashSet<TypeElement>();
topLevelClasses = List.nil();
packageInfoFiles = List.nil();
compiler.close(false);
currentContext = contextForNextRound(currentContext, true);
JavaFileManager fileManager = currentContext.get(JavaFileManager.class);
compiler = JavaCompiler.instance(currentContext);
List<JCCompilationUnit> parsedFiles = sourcesToParsedFiles(compiler);
roots = cleanTrees(roots).appendList(parsedFiles);
// Check for errors after parsing
if (log.unrecoverableError) {
errorStatus = true;
break runAround;
} else {
List<ClassSymbol> newClasses = enterNewClassFiles(currentContext);
compiler.enterTrees(roots);
// annotationsPresentInSource =
// collector.findAnnotations(parsedFiles);
ListBuffer<ClassSymbol> tlc = new ListBuffer<ClassSymbol>();
tlc.appendList(getTopLevelClasses(parsedFiles));
tlc.appendList(getTopLevelClassesFromClasses(newClasses));
topLevelClasses = tlc.toList();
ListBuffer<PackageSymbol> pif = new ListBuffer<PackageSymbol>();
pif.appendList(getPackageInfoFiles(parsedFiles));
pif.appendList(getPackageInfoFilesFromClasses(newClasses));
packageInfoFiles = pif.toList();
annotationsPresent = new LinkedHashSet<TypeElement>();
for (ClassSymbol classSym : topLevelClasses)
annotationComputer.scan(classSym, annotationsPresent);
for (PackageSymbol pkgSym : packageInfoFiles)
annotationComputer.scan(pkgSym, annotationsPresent);
updateProcessingState(currentContext, false);
}
} else
break runAround; // No new files
}
}
roots = runLastRound(xout, roundNumber, errorStatus, compiler, roots, taskListener);
// Set error status for any files compiled and generated in
// the last round
if (log.unrecoverableError)
errorStatus = true;
compiler.close(false);
currentContext = contextForNextRound(currentContext, true);
compiler = JavaCompiler.instance(currentContext);
filer.newRound(currentContext, 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.
*/
errorStatus = errorStatus || messager.errorRaised();
// Free resources
this.close();
if (taskListener != null)
taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
if (errorStatus) {
compiler.log.nerrors += messager.errorCount();
if (compiler.errorCount() == 0)
compiler.log.nerrors++;