langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
equal
deleted
inserted
replaced
75 import com.sun.tools.javac.util.Name; |
75 import com.sun.tools.javac.util.Name; |
76 import com.sun.tools.javac.util.Names; |
76 import com.sun.tools.javac.util.Names; |
77 import com.sun.tools.javac.util.Options; |
77 import com.sun.tools.javac.util.Options; |
78 |
78 |
79 import static javax.tools.StandardLocation.*; |
79 import static javax.tools.StandardLocation.*; |
|
80 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; |
80 |
81 |
81 /** |
82 /** |
82 * Objects of this class hold and manage the state needed to support |
83 * Objects of this class hold and manage the state needed to support |
83 * annotation processing. |
84 * annotation processing. |
84 * |
85 * |
95 private final boolean verbose; |
96 private final boolean verbose; |
96 private final boolean lint; |
97 private final boolean lint; |
97 private final boolean procOnly; |
98 private final boolean procOnly; |
98 private final boolean fatalErrors; |
99 private final boolean fatalErrors; |
99 private final boolean werror; |
100 private final boolean werror; |
|
101 private final boolean showResolveErrors; |
100 private boolean foundTypeProcessors; |
102 private boolean foundTypeProcessors; |
101 |
103 |
102 private final JavacFiler filer; |
104 private final JavacFiler filer; |
103 private final JavacMessager messager; |
105 private final JavacMessager messager; |
104 private final JavacElements elementUtils; |
106 private final JavacElements elementUtils; |
162 verbose = options.get("-verbose") != null; |
164 verbose = options.get("-verbose") != null; |
163 lint = options.lint("processing"); |
165 lint = options.lint("processing"); |
164 procOnly = options.get("-proc:only") != null || |
166 procOnly = options.get("-proc:only") != null || |
165 options.get("-Xprint") != null; |
167 options.get("-Xprint") != null; |
166 fatalErrors = options.get("fatalEnterError") != null; |
168 fatalErrors = options.get("fatalEnterError") != null; |
|
169 showResolveErrors = options.get("showResolveErrors") != null; |
167 werror = options.get("-Werror") != null; |
170 werror = options.get("-Werror") != null; |
168 platformAnnotations = initPlatformAnnotations(); |
171 platformAnnotations = initPlatformAnnotations(); |
169 foundTypeProcessors = false; |
172 foundTypeProcessors = false; |
170 |
173 |
171 // Initialize services before any processors are initialzied |
174 // Initialize services before any processors are initialzied |
823 this.number = number; |
826 this.number = number; |
824 this.priorWarnings = priorWarnings; |
827 this.priorWarnings = priorWarnings; |
825 |
828 |
826 compiler = JavaCompiler.instance(context); |
829 compiler = JavaCompiler.instance(context); |
827 log = Log.instance(context); |
830 log = Log.instance(context); |
|
831 log.deferDiagnostics = true; |
828 |
832 |
829 // the following is for the benefit of JavacProcessingEnvironment.getContext() |
833 // the following is for the benefit of JavacProcessingEnvironment.getContext() |
830 JavacProcessingEnvironment.this.context = context; |
834 JavacProcessingEnvironment.this.context = context; |
831 |
835 |
832 // the following will be populated as needed |
836 // the following will be populated as needed |
922 return compiler.warningCount(); |
926 return compiler.warningCount(); |
923 } |
927 } |
924 |
928 |
925 /** Return whether or not an unrecoverable error has occurred. */ |
929 /** Return whether or not an unrecoverable error has occurred. */ |
926 boolean unrecoverableError() { |
930 boolean unrecoverableError() { |
927 return log.unrecoverableError |
931 if (messager.errorRaised()) |
928 || messager.errorRaised() |
932 return true; |
929 || (werror && log.nwarnings > 0) |
933 |
930 || (fatalErrors && log.nerrors > 0); |
934 for (JCDiagnostic d: log.deferredDiagnostics) { |
|
935 switch (d.getKind()) { |
|
936 case WARNING: |
|
937 if (werror) |
|
938 return true; |
|
939 break; |
|
940 |
|
941 case ERROR: |
|
942 if (fatalErrors || !d.isFlagSet(RESOLVE_ERROR)) |
|
943 return true; |
|
944 break; |
|
945 } |
|
946 } |
|
947 |
|
948 return false; |
931 } |
949 } |
932 |
950 |
933 /** Find the set of annotations present in the set of top level |
951 /** Find the set of annotations present in the set of top level |
934 * classes and package info files to be processed this round. */ |
952 * classes and package info files to be processed this round. */ |
935 void findAnnotationsPresent() { |
953 void findAnnotationsPresent() { |
941 for (PackageSymbol pkgSym : packageInfoFiles) |
959 for (PackageSymbol pkgSym : packageInfoFiles) |
942 annotationComputer.scan(pkgSym, annotationsPresent); |
960 annotationComputer.scan(pkgSym, annotationsPresent); |
943 } |
961 } |
944 |
962 |
945 /** Enter a set of generated class files. */ |
963 /** Enter a set of generated class files. */ |
946 List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) { |
964 private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) { |
947 ClassReader reader = ClassReader.instance(context); |
965 ClassReader reader = ClassReader.instance(context); |
948 Names names = Names.instance(context); |
966 Names names = Names.instance(context); |
949 List<ClassSymbol> list = List.nil(); |
967 List<ClassSymbol> list = List.nil(); |
950 |
968 |
951 for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) { |
969 for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) { |
968 } |
986 } |
969 return list.reverse(); |
987 return list.reverse(); |
970 } |
988 } |
971 |
989 |
972 /** Enter a set of syntax trees. */ |
990 /** Enter a set of syntax trees. */ |
973 void enterTrees(List<JCCompilationUnit> roots) { |
991 private void enterTrees(List<JCCompilationUnit> roots) { |
974 compiler.enterTrees(roots); |
992 compiler.enterTrees(roots); |
975 } |
993 } |
976 |
994 |
977 /** Run a processing round. */ |
995 /** Run a processing round. */ |
978 void run(boolean lastRound, boolean errorStatus) { |
996 void run(boolean lastRound, boolean errorStatus) { |
998 if (taskListener != null) |
1016 if (taskListener != null) |
999 taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND)); |
1017 taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND)); |
1000 } |
1018 } |
1001 } |
1019 } |
1002 |
1020 |
|
1021 void showDiagnostics(boolean showAll) { |
|
1022 Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class); |
|
1023 if (!showAll) { |
|
1024 // suppress errors, which are all presumed to be transient resolve errors |
|
1025 kinds.remove(JCDiagnostic.Kind.ERROR); |
|
1026 } |
|
1027 log.reportDeferredDiagnostics(kinds); |
|
1028 } |
|
1029 |
1003 /** Update the processing state for the current context. */ |
1030 /** Update the processing state for the current context. */ |
1004 private void updateProcessingState() { |
1031 private void updateProcessingState() { |
1005 filer.newRound(context); |
1032 filer.newRound(context); |
1006 messager.newRound(context); |
1033 messager.newRound(context); |
1007 |
1034 |
1109 // Processors for round n have run to completion. |
1136 // Processors for round n have run to completion. |
1110 // Check for errors and whether there is more work to do. |
1137 // Check for errors and whether there is more work to do. |
1111 errorStatus = round.unrecoverableError(); |
1138 errorStatus = round.unrecoverableError(); |
1112 moreToDo = moreToDo(); |
1139 moreToDo = moreToDo(); |
1113 |
1140 |
|
1141 round.showDiagnostics(errorStatus || showResolveErrors); |
|
1142 |
1114 // Set up next round. |
1143 // Set up next round. |
1115 // Copy mutable collections returned from filer. |
1144 // Copy mutable collections returned from filer. |
1116 round = round.next( |
1145 round = round.next( |
1117 new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects()), |
1146 new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects()), |
1118 new LinkedHashMap<String,JavaFileObject>(filer.getGeneratedClasses())); |
1147 new LinkedHashMap<String,JavaFileObject>(filer.getGeneratedClasses())); |
1123 |
1152 |
1124 } while (moreToDo && !errorStatus); |
1153 } while (moreToDo && !errorStatus); |
1125 |
1154 |
1126 // run last round |
1155 // run last round |
1127 round.run(true, errorStatus); |
1156 round.run(true, errorStatus); |
|
1157 round.showDiagnostics(true); |
1128 |
1158 |
1129 filer.warnIfUnclosedFiles(); |
1159 filer.warnIfUnclosedFiles(); |
1130 warnIfUnmatchedOptions(); |
1160 warnIfUnmatchedOptions(); |
1131 |
1161 |
1132 /* |
1162 /* |