779 final Context context; |
779 final Context context; |
780 /** The compiler for the round. */ |
780 /** The compiler for the round. */ |
781 final JavaCompiler compiler; |
781 final JavaCompiler compiler; |
782 /** The log for the round. */ |
782 /** The log for the round. */ |
783 final Log log; |
783 final Log log; |
|
784 /** The diagnostic handler for the round. */ |
|
785 final Log.DeferredDiagnosticHandler deferredDiagnosticHandler; |
784 |
786 |
785 /** The ASTs to be compiled. */ |
787 /** The ASTs to be compiled. */ |
786 List<JCCompilationUnit> roots; |
788 List<JCCompilationUnit> roots; |
787 /** The classes to be compiler that have were generated. */ |
789 /** The classes to be compiler that have were generated. */ |
788 Map<String, JavaFileObject> genClassFiles; |
790 Map<String, JavaFileObject> genClassFiles; |
796 |
798 |
797 /** The number of Messager errors generated in this round. */ |
799 /** The number of Messager errors generated in this round. */ |
798 int nMessagerErrors; |
800 int nMessagerErrors; |
799 |
801 |
800 /** Create a round (common code). */ |
802 /** Create a round (common code). */ |
801 private Round(Context context, int number, int priorErrors, int priorWarnings) { |
803 private Round(Context context, int number, int priorErrors, int priorWarnings, |
|
804 Log.DeferredDiagnosticHandler deferredDiagnosticHandler) { |
802 this.context = context; |
805 this.context = context; |
803 this.number = number; |
806 this.number = number; |
804 |
807 |
805 compiler = JavaCompiler.instance(context); |
808 compiler = JavaCompiler.instance(context); |
806 log = Log.instance(context); |
809 log = Log.instance(context); |
807 log.nerrors = priorErrors; |
810 log.nerrors = priorErrors; |
808 log.nwarnings += priorWarnings; |
811 log.nwarnings += priorWarnings; |
809 log.deferAll(); |
812 if (number == 1) { |
|
813 Assert.checkNonNull(deferredDiagnosticHandler); |
|
814 this.deferredDiagnosticHandler = deferredDiagnosticHandler; |
|
815 } else { |
|
816 this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log); |
|
817 } |
810 |
818 |
811 // the following is for the benefit of JavacProcessingEnvironment.getContext() |
819 // the following is for the benefit of JavacProcessingEnvironment.getContext() |
812 JavacProcessingEnvironment.this.context = context; |
820 JavacProcessingEnvironment.this.context = context; |
813 |
821 |
814 // the following will be populated as needed |
822 // the following will be populated as needed |
815 topLevelClasses = List.nil(); |
823 topLevelClasses = List.nil(); |
816 packageInfoFiles = List.nil(); |
824 packageInfoFiles = List.nil(); |
817 } |
825 } |
818 |
826 |
819 /** Create the first round. */ |
827 /** Create the first round. */ |
820 Round(Context context, List<JCCompilationUnit> roots, List<ClassSymbol> classSymbols) { |
828 Round(Context context, List<JCCompilationUnit> roots, List<ClassSymbol> classSymbols, |
821 this(context, 1, 0, 0); |
829 Log.DeferredDiagnosticHandler deferredDiagnosticHandler) { |
|
830 this(context, 1, 0, 0, deferredDiagnosticHandler); |
822 this.roots = roots; |
831 this.roots = roots; |
823 genClassFiles = new HashMap<String,JavaFileObject>(); |
832 genClassFiles = new HashMap<String,JavaFileObject>(); |
824 |
833 |
825 compiler.todo.clear(); // free the compiler's resources |
834 compiler.todo.clear(); // free the compiler's resources |
826 |
835 |
839 private Round(Round prev, |
848 private Round(Round prev, |
840 Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles) { |
849 Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles) { |
841 this(prev.nextContext(), |
850 this(prev.nextContext(), |
842 prev.number+1, |
851 prev.number+1, |
843 prev.nMessagerErrors, |
852 prev.nMessagerErrors, |
844 prev.compiler.log.nwarnings); |
853 prev.compiler.log.nwarnings, |
|
854 null); |
845 this.genClassFiles = prev.genClassFiles; |
855 this.genClassFiles = prev.genClassFiles; |
846 |
856 |
847 List<JCCompilationUnit> parsedFiles = compiler.parseFiles(newSourceFiles); |
857 List<JCCompilationUnit> parsedFiles = compiler.parseFiles(newSourceFiles); |
848 roots = cleanTrees(prev.roots).appendList(parsedFiles); |
858 roots = cleanTrees(prev.roots).appendList(parsedFiles); |
849 |
859 |
1004 Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class); |
1014 Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class); |
1005 if (!showAll) { |
1015 if (!showAll) { |
1006 // suppress errors, which are all presumed to be transient resolve errors |
1016 // suppress errors, which are all presumed to be transient resolve errors |
1007 kinds.remove(JCDiagnostic.Kind.ERROR); |
1017 kinds.remove(JCDiagnostic.Kind.ERROR); |
1008 } |
1018 } |
1009 log.reportDeferredDiagnostics(kinds); |
1019 deferredDiagnosticHandler.reportDeferredDiagnostics(kinds); |
|
1020 log.popDiagnosticHandler(deferredDiagnosticHandler); |
1010 } |
1021 } |
1011 |
1022 |
1012 /** Print info about this round. */ |
1023 /** Print info about this round. */ |
1013 private void printRoundInfo(boolean lastRound) { |
1024 private void printRoundInfo(boolean lastRound) { |
1014 if (printRounds || verbose) { |
1025 if (printRounds || verbose) { |
1110 // TODO: internal catch clauses?; catch and rethrow an annotation |
1121 // TODO: internal catch clauses?; catch and rethrow an annotation |
1111 // processing error |
1122 // processing error |
1112 public JavaCompiler doProcessing(Context context, |
1123 public JavaCompiler doProcessing(Context context, |
1113 List<JCCompilationUnit> roots, |
1124 List<JCCompilationUnit> roots, |
1114 List<ClassSymbol> classSymbols, |
1125 List<ClassSymbol> classSymbols, |
1115 Iterable<? extends PackageSymbol> pckSymbols) { |
1126 Iterable<? extends PackageSymbol> pckSymbols, |
|
1127 Log.DeferredDiagnosticHandler deferredDiagnosticHandler) { |
1116 log = Log.instance(context); |
1128 log = Log.instance(context); |
1117 |
1129 |
1118 Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>(); |
1130 Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>(); |
1119 for (PackageSymbol psym : pckSymbols) |
1131 for (PackageSymbol psym : pckSymbols) |
1120 specifiedPackages.add(psym); |
1132 specifiedPackages.add(psym); |
1121 this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages); |
1133 this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages); |
1122 |
1134 |
1123 Round round = new Round(context, roots, classSymbols); |
1135 Round round = new Round(context, roots, classSymbols, deferredDiagnosticHandler); |
1124 |
1136 |
1125 boolean errorStatus; |
1137 boolean errorStatus; |
1126 boolean moreToDo; |
1138 boolean moreToDo; |
1127 do { |
1139 do { |
1128 // Run processors for round n |
1140 // Run processors for round n |