src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
Print this page
@@ -872,24 +872,13 @@
compiler.close(false);
currentContext = contextForNextRound(currentContext, true);
JavaFileManager fileManager = currentContext.get(JavaFileManager.class);
- List<JavaFileObject> fileObjects = List.nil();
- for (JavaFileObject jfo : filer.getGeneratedSourceFileObjects() ) {
- fileObjects = fileObjects.prepend(jfo);
- }
-
-
compiler = JavaCompiler.instance(currentContext);
- List<JCCompilationUnit> parsedFiles = compiler.parseFiles(fileObjects);
- roots = cleanTrees(roots).reverse();
-
-
- for (JCCompilationUnit unit : parsedFiles)
- roots = roots.prepend(unit);
- roots = roots.reverse();
+ List<JCCompilationUnit> parsedFiles = sourcesToParsedFiles(compiler);
+ roots = cleanTrees(roots).appendList(parsedFiles);
// Check for errors after parsing
if (compiler.parseErrors()) {
errorStatus = true;
break runAround;
@@ -919,15 +908,20 @@
}
} else
break runAround; // No new files
}
}
- runLastRound(xout, roundNumber, errorStatus, taskListener);
+ roots = runLastRound(xout, roundNumber, errorStatus, compiler, roots, taskListener);
+ // Set error status for any files compiled and generated in
+ // the last round
+ if (compiler.parseErrors())
+ errorStatus = true;
compiler.close(false);
currentContext = contextForNextRound(currentContext, true);
compiler = JavaCompiler.instance(currentContext);
+
filer.newRound(currentContext, true);
filer.warnIfUnclosedFiles();
warnIfUnmatchedOptions();
/*
@@ -977,14 +971,26 @@
}
return compiler;
}
+ private List<JCCompilationUnit> sourcesToParsedFiles(JavaCompiler compiler)
+ throws IOException {
+ List<JavaFileObject> fileObjects = List.nil();
+ for (JavaFileObject jfo : filer.getGeneratedSourceFileObjects() ) {
+ fileObjects = fileObjects.prepend(jfo);
+ }
+
+ return compiler.parseFiles(fileObjects);
+ }
+
// Call the last round of annotation processing
- private void runLastRound(PrintWriter xout,
+ private List<JCCompilationUnit> runLastRound(PrintWriter xout,
int roundNumber,
boolean errorStatus,
+ JavaCompiler compiler,
+ List<JCCompilationUnit> roots,
TaskListener taskListener) throws IOException {
roundNumber++;
List<ClassSymbol> noTopLevelClasses = List.nil();
Set<TypeElement> noAnnotations = Collections.emptySet();
printRoundInfo(xout, roundNumber, noTopLevelClasses, noAnnotations, true);
@@ -1001,10 +1007,19 @@
discoveredProcs.iterator().runContributingProcs(renv);
} finally {
if (taskListener != null)
taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
}
+
+ // Add any sources generated during the last round to the set
+ // of files to be compiled.
+ if (moreToDo()) {
+ List<JCCompilationUnit> parsedFiles = sourcesToParsedFiles(compiler);
+ roots = cleanTrees(roots).appendList(parsedFiles);
+ }
+
+ return roots;
}
private void updateProcessingState(Context currentContext, boolean lastRound) {
filer.newRound(currentContext, lastRound);
messager.newRound(currentContext);