60 import com.sun.tools.javac.comp.Enter; |
60 import com.sun.tools.javac.comp.Enter; |
61 import com.sun.tools.javac.comp.Env; |
61 import com.sun.tools.javac.comp.Env; |
62 import com.sun.tools.javac.comp.Modules; |
62 import com.sun.tools.javac.comp.Modules; |
63 import com.sun.tools.javac.file.JavacFileManager; |
63 import com.sun.tools.javac.file.JavacFileManager; |
64 import com.sun.tools.javac.main.JavaCompiler; |
64 import com.sun.tools.javac.main.JavaCompiler; |
|
65 import com.sun.tools.javac.main.Option; |
65 import com.sun.tools.javac.model.JavacElements; |
66 import com.sun.tools.javac.model.JavacElements; |
66 import com.sun.tools.javac.model.JavacTypes; |
67 import com.sun.tools.javac.model.JavacTypes; |
67 import com.sun.tools.javac.platform.PlatformDescription; |
68 import com.sun.tools.javac.platform.PlatformDescription; |
68 import com.sun.tools.javac.platform.PlatformDescription.PluginInfo; |
69 import com.sun.tools.javac.platform.PlatformDescription.PluginInfo; |
69 import com.sun.tools.javac.resources.CompilerProperties.Errors; |
70 import com.sun.tools.javac.resources.CompilerProperties.Errors; |
87 import com.sun.tools.javac.util.Names; |
88 import com.sun.tools.javac.util.Names; |
88 import com.sun.tools.javac.util.Options; |
89 import com.sun.tools.javac.util.Options; |
89 |
90 |
90 import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING; |
91 import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING; |
91 import static com.sun.tools.javac.code.Kinds.Kind.*; |
92 import static com.sun.tools.javac.code.Kinds.Kind.*; |
92 import static com.sun.tools.javac.main.Option.*; |
|
93 import static com.sun.tools.javac.comp.CompileStates.CompileState; |
93 import static com.sun.tools.javac.comp.CompileStates.CompileState; |
94 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; |
94 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; |
95 |
95 |
96 /** |
96 /** |
97 * Objects of this class hold and manage the state needed to support |
97 * Objects of this class hold and manage the state needed to support |
194 context.put(JavacProcessingEnvironment.class, this); |
194 context.put(JavacProcessingEnvironment.class, this); |
195 log = Log.instance(context); |
195 log = Log.instance(context); |
196 source = Source.instance(context); |
196 source = Source.instance(context); |
197 diags = JCDiagnostic.Factory.instance(context); |
197 diags = JCDiagnostic.Factory.instance(context); |
198 options = Options.instance(context); |
198 options = Options.instance(context); |
199 printProcessorInfo = options.isSet(XPRINTPROCESSORINFO); |
199 printProcessorInfo = options.isSet(Option.XPRINTPROCESSORINFO); |
200 printRounds = options.isSet(XPRINTROUNDS); |
200 printRounds = options.isSet(Option.XPRINTROUNDS); |
201 verbose = options.isSet(VERBOSE); |
201 verbose = options.isSet(Option.VERBOSE); |
202 lint = Lint.instance(context).isEnabled(PROCESSING); |
202 lint = Lint.instance(context).isEnabled(PROCESSING); |
203 compiler = JavaCompiler.instance(context); |
203 compiler = JavaCompiler.instance(context); |
204 if (options.isSet(PROC, "only") || options.isSet(XPRINT)) { |
204 if (options.isSet(Option.PROC, "only") || options.isSet(Option.XPRINT)) { |
205 compiler.shouldStopPolicyIfNoError = CompileState.PROCESS; |
205 compiler.shouldStopPolicyIfNoError = CompileState.PROCESS; |
206 } |
206 } |
207 fatalErrors = options.isSet("fatalEnterError"); |
207 fatalErrors = options.isSet("fatalEnterError"); |
208 showResolveErrors = options.isSet("showResolveErrors"); |
208 showResolveErrors = options.isSet("showResolveErrors"); |
209 werror = options.isSet(WERROR); |
209 werror = options.isSet(Option.WERROR); |
210 fileManager = context.get(JavaFileManager.class); |
210 fileManager = context.get(JavaFileManager.class); |
211 platformAnnotations = initPlatformAnnotations(); |
211 platformAnnotations = initPlatformAnnotations(); |
212 |
212 |
213 // Initialize services before any processors are initialized |
213 // Initialize services before any processors are initialized |
214 // in case processors use them. |
214 // in case processors use them. |
277 } |
277 } |
278 |
278 |
279 private void initProcessorIterator(Iterable<? extends Processor> processors) { |
279 private void initProcessorIterator(Iterable<? extends Processor> processors) { |
280 Iterator<? extends Processor> processorIterator; |
280 Iterator<? extends Processor> processorIterator; |
281 |
281 |
282 if (options.isSet(XPRINT)) { |
282 if (options.isSet(Option.XPRINT)) { |
283 try { |
283 try { |
284 processorIterator = List.of(new PrintingProcessor()).iterator(); |
284 processorIterator = List.of(new PrintingProcessor()).iterator(); |
285 } catch (Throwable t) { |
285 } catch (Throwable t) { |
286 AssertionError assertError = |
286 AssertionError assertError = |
287 new AssertionError("Problem instantiating PrintingProcessor."); |
287 new AssertionError("Problem instantiating PrintingProcessor."); |
295 /* |
295 /* |
296 * If the "-processor" option is used, search the appropriate |
296 * If the "-processor" option is used, search the appropriate |
297 * path for the named class. Otherwise, use a service |
297 * path for the named class. Otherwise, use a service |
298 * provider mechanism to create the processor iterator. |
298 * provider mechanism to create the processor iterator. |
299 */ |
299 */ |
300 String processorNames = options.get(PROCESSOR); |
300 String processorNames = options.get(Option.PROCESSOR); |
301 if (fileManager.hasLocation(ANNOTATION_PROCESSOR_MODULE_PATH)) { |
301 if (fileManager.hasLocation(ANNOTATION_PROCESSOR_MODULE_PATH)) { |
302 processorIterator = (processorNames == null) ? |
302 processorIterator = (processorNames == null) ? |
303 new ServiceIterator(serviceLoader, log) : |
303 new ServiceIterator(serviceLoader, log) : |
304 new NameServiceIterator(serviceLoader, log, processorNames); |
304 new NameServiceIterator(serviceLoader, log, processorNames); |
305 } else if (processorNames != null) { |
305 } else if (processorNames != null) { |
361 StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager; |
361 StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager; |
362 Iterable<? extends Path> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH) |
362 Iterable<? extends Path> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH) |
363 ? standardFileManager.getLocationAsPaths(ANNOTATION_PROCESSOR_PATH) |
363 ? standardFileManager.getLocationAsPaths(ANNOTATION_PROCESSOR_PATH) |
364 : standardFileManager.getLocationAsPaths(CLASS_PATH); |
364 : standardFileManager.getLocationAsPaths(CLASS_PATH); |
365 |
365 |
366 if (needClassLoader(options.get(PROCESSOR), workingPath) ) |
366 if (needClassLoader(options.get(Option.PROCESSOR), workingPath) ) |
367 handleException(key, e); |
367 handleException(key, e); |
368 |
368 |
369 } else { |
369 } else { |
370 handleException(key, e); |
370 handleException(key, e); |
371 } |
371 } |