Wed, 14 Dec 2011 16:16:04 -0800
7111022: javac no long prints last round of processing
7121323: Sqe tests using -Xstdout option fail with an invalid flag error message
Reviewed-by: darcy
1 /*
2 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.javac.processing;
28 import java.lang.reflect.*;
29 import java.util.*;
30 import java.util.regex.*;
32 import java.net.URL;
33 import java.io.Closeable;
34 import java.io.File;
35 import java.io.PrintWriter;
36 import java.io.IOException;
37 import java.io.StringWriter;
38 import java.net.MalformedURLException;
40 import javax.annotation.processing.*;
41 import javax.lang.model.SourceVersion;
42 import javax.lang.model.element.AnnotationMirror;
43 import javax.lang.model.element.Element;
44 import javax.lang.model.element.TypeElement;
45 import javax.lang.model.element.PackageElement;
46 import javax.lang.model.util.*;
47 import javax.tools.JavaFileManager;
48 import javax.tools.StandardJavaFileManager;
49 import javax.tools.JavaFileObject;
50 import javax.tools.DiagnosticListener;
52 import com.sun.source.util.TaskEvent;
53 import com.sun.source.util.TaskListener;
54 import com.sun.tools.javac.api.JavacTaskImpl;
55 import com.sun.tools.javac.api.JavacTrees;
56 import com.sun.tools.javac.code.*;
57 import com.sun.tools.javac.code.Symbol.*;
58 import com.sun.tools.javac.file.FSInfo;
59 import com.sun.tools.javac.file.JavacFileManager;
60 import com.sun.tools.javac.jvm.*;
61 import com.sun.tools.javac.jvm.ClassReader.BadClassFile;
62 import com.sun.tools.javac.main.JavaCompiler;
63 import com.sun.tools.javac.main.JavaCompiler.CompileState;
64 import com.sun.tools.javac.model.JavacElements;
65 import com.sun.tools.javac.model.JavacTypes;
66 import com.sun.tools.javac.parser.*;
67 import com.sun.tools.javac.tree.*;
68 import com.sun.tools.javac.tree.JCTree.*;
69 import com.sun.tools.javac.util.Abort;
70 import com.sun.tools.javac.util.Assert;
71 import com.sun.tools.javac.util.ClientCodeException;
72 import com.sun.tools.javac.util.Context;
73 import com.sun.tools.javac.util.Convert;
74 import com.sun.tools.javac.util.FatalError;
75 import com.sun.tools.javac.util.JCDiagnostic;
76 import com.sun.tools.javac.util.List;
77 import com.sun.tools.javac.util.Log;
78 import com.sun.tools.javac.util.JavacMessages;
79 import com.sun.tools.javac.util.Name;
80 import com.sun.tools.javac.util.Names;
81 import com.sun.tools.javac.util.Options;
83 import static javax.tools.StandardLocation.*;
84 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
85 import static com.sun.tools.javac.main.Option.*;
86 import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING;
88 /**
89 * Objects of this class hold and manage the state needed to support
90 * annotation processing.
91 *
92 * <p><b>This is NOT part of any supported API.
93 * If you write code that depends on this, you do so at your own risk.
94 * This code and its internal interfaces are subject to change or
95 * deletion without notice.</b>
96 */
97 public class JavacProcessingEnvironment implements ProcessingEnvironment, Closeable {
98 Options options;
100 private final boolean printProcessorInfo;
101 private final boolean printRounds;
102 private final boolean verbose;
103 private final boolean lint;
104 private final boolean procOnly;
105 private final boolean fatalErrors;
106 private final boolean werror;
107 private final boolean showResolveErrors;
108 private boolean foundTypeProcessors;
110 private final JavacFiler filer;
111 private final JavacMessager messager;
112 private final JavacElements elementUtils;
113 private final JavacTypes typeUtils;
115 /**
116 * Holds relevant state history of which processors have been
117 * used.
118 */
119 private DiscoveredProcessors discoveredProcs;
121 /**
122 * Map of processor-specific options.
123 */
124 private final Map<String, String> processorOptions;
126 /**
127 */
128 private final Set<String> unmatchedProcessorOptions;
130 /**
131 * Annotations implicitly processed and claimed by javac.
132 */
133 private final Set<String> platformAnnotations;
135 /**
136 * Set of packages given on command line.
137 */
138 private Set<PackageSymbol> specifiedPackages = Collections.emptySet();
140 /** The log to be used for error reporting.
141 */
142 Log log;
144 /** Diagnostic factory.
145 */
146 JCDiagnostic.Factory diags;
148 /**
149 * Source level of the compile.
150 */
151 Source source;
153 private ClassLoader processorClassLoader;
155 /**
156 * JavacMessages object used for localization
157 */
158 private JavacMessages messages;
160 private Context context;
162 public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) {
163 this.context = context;
164 log = Log.instance(context);
165 source = Source.instance(context);
166 diags = JCDiagnostic.Factory.instance(context);
167 options = Options.instance(context);
168 printProcessorInfo = options.isSet(XPRINTPROCESSORINFO);
169 printRounds = options.isSet(XPRINTROUNDS);
170 verbose = options.isSet(VERBOSE);
171 lint = Lint.instance(context).isEnabled(PROCESSING);
172 procOnly = options.isSet(PROC, "only") || options.isSet(XPRINT);
173 fatalErrors = options.isSet("fatalEnterError");
174 showResolveErrors = options.isSet("showResolveErrors");
175 werror = options.isSet(WERROR);
176 platformAnnotations = initPlatformAnnotations();
177 foundTypeProcessors = false;
179 // Initialize services before any processors are initialized
180 // in case processors use them.
181 filer = new JavacFiler(context);
182 messager = new JavacMessager(context, this);
183 elementUtils = JavacElements.instance(context);
184 typeUtils = JavacTypes.instance(context);
185 processorOptions = initProcessorOptions(context);
186 unmatchedProcessorOptions = initUnmatchedProcessorOptions();
187 messages = JavacMessages.instance(context);
188 initProcessorIterator(context, processors);
189 }
191 private Set<String> initPlatformAnnotations() {
192 Set<String> platformAnnotations = new HashSet<String>();
193 platformAnnotations.add("java.lang.Deprecated");
194 platformAnnotations.add("java.lang.Override");
195 platformAnnotations.add("java.lang.SuppressWarnings");
196 platformAnnotations.add("java.lang.annotation.Documented");
197 platformAnnotations.add("java.lang.annotation.Inherited");
198 platformAnnotations.add("java.lang.annotation.Retention");
199 platformAnnotations.add("java.lang.annotation.Target");
200 return Collections.unmodifiableSet(platformAnnotations);
201 }
203 private void initProcessorIterator(Context context, Iterable<? extends Processor> processors) {
204 Log log = Log.instance(context);
205 Iterator<? extends Processor> processorIterator;
207 if (options.isSet(XPRINT)) {
208 try {
209 Processor processor = PrintingProcessor.class.newInstance();
210 processorIterator = List.of(processor).iterator();
211 } catch (Throwable t) {
212 AssertionError assertError =
213 new AssertionError("Problem instantiating PrintingProcessor.");
214 assertError.initCause(t);
215 throw assertError;
216 }
217 } else if (processors != null) {
218 processorIterator = processors.iterator();
219 } else {
220 String processorNames = options.get(PROCESSOR);
221 JavaFileManager fileManager = context.get(JavaFileManager.class);
222 try {
223 // If processorpath is not explicitly set, use the classpath.
224 processorClassLoader = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
225 ? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH)
226 : fileManager.getClassLoader(CLASS_PATH);
228 if (processorClassLoader != null && processorClassLoader instanceof Closeable) {
229 JavaCompiler compiler = JavaCompiler.instance(context);
230 compiler.closeables = compiler.closeables.prepend((Closeable) processorClassLoader);
231 }
233 /*
234 * If the "-processor" option is used, search the appropriate
235 * path for the named class. Otherwise, use a service
236 * provider mechanism to create the processor iterator.
237 */
238 if (processorNames != null) {
239 processorIterator = new NameProcessIterator(processorNames, processorClassLoader, log);
240 } else {
241 processorIterator = new ServiceIterator(processorClassLoader, log);
242 }
243 } catch (SecurityException e) {
244 /*
245 * A security exception will occur if we can't create a classloader.
246 * Ignore the exception if, with hindsight, we didn't need it anyway
247 * (i.e. no processor was specified either explicitly, or implicitly,
248 * in service configuration file.) Otherwise, we cannot continue.
249 */
250 processorIterator = handleServiceLoaderUnavailability("proc.cant.create.loader", e);
251 }
252 }
253 discoveredProcs = new DiscoveredProcessors(processorIterator);
254 }
256 /**
257 * Returns an empty processor iterator if no processors are on the
258 * relevant path, otherwise if processors are present, logs an
259 * error. Called when a service loader is unavailable for some
260 * reason, either because a service loader class cannot be found
261 * or because a security policy prevents class loaders from being
262 * created.
263 *
264 * @param key The resource key to use to log an error message
265 * @param e If non-null, pass this exception to Abort
266 */
267 private Iterator<Processor> handleServiceLoaderUnavailability(String key, Exception e) {
268 JavaFileManager fileManager = context.get(JavaFileManager.class);
270 if (fileManager instanceof JavacFileManager) {
271 StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
272 Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
273 ? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
274 : standardFileManager.getLocation(CLASS_PATH);
276 if (needClassLoader(options.get(PROCESSOR), workingPath) )
277 handleException(key, e);
279 } else {
280 handleException(key, e);
281 }
283 java.util.List<Processor> pl = Collections.emptyList();
284 return pl.iterator();
285 }
287 /**
288 * Handle a security exception thrown during initializing the
289 * Processor iterator.
290 */
291 private void handleException(String key, Exception e) {
292 if (e != null) {
293 log.error(key, e.getLocalizedMessage());
294 throw new Abort(e);
295 } else {
296 log.error(key);
297 throw new Abort();
298 }
299 }
301 /**
302 * Use a service loader appropriate for the platform to provide an
303 * iterator over annotations processors; fails if a loader is
304 * needed but unavailable.
305 */
306 private class ServiceIterator implements Iterator<Processor> {
307 private Iterator<Processor> iterator;
308 private Log log;
309 private ServiceLoader<Processor> loader;
311 ServiceIterator(ClassLoader classLoader, Log log) {
312 this.log = log;
313 try {
314 try {
315 loader = ServiceLoader.load(Processor.class, classLoader);
316 this.iterator = loader.iterator();
317 } catch (Exception e) {
318 // Fail softly if a loader is not actually needed.
319 this.iterator = handleServiceLoaderUnavailability("proc.no.service", null);
320 }
321 } catch (Throwable t) {
322 log.error("proc.service.problem");
323 throw new Abort(t);
324 }
325 }
327 public boolean hasNext() {
328 try {
329 return iterator.hasNext();
330 } catch(ServiceConfigurationError sce) {
331 log.error("proc.bad.config.file", sce.getLocalizedMessage());
332 throw new Abort(sce);
333 } catch (Throwable t) {
334 throw new Abort(t);
335 }
336 }
338 public Processor next() {
339 try {
340 return iterator.next();
341 } catch (ServiceConfigurationError sce) {
342 log.error("proc.bad.config.file", sce.getLocalizedMessage());
343 throw new Abort(sce);
344 } catch (Throwable t) {
345 throw new Abort(t);
346 }
347 }
349 public void remove() {
350 throw new UnsupportedOperationException();
351 }
353 public void close() {
354 if (loader != null) {
355 try {
356 loader.reload();
357 } catch(Exception e) {
358 ; // Ignore problems during a call to reload.
359 }
360 }
361 }
362 }
365 private static class NameProcessIterator implements Iterator<Processor> {
366 Processor nextProc = null;
367 Iterator<String> names;
368 ClassLoader processorCL;
369 Log log;
371 NameProcessIterator(String names, ClassLoader processorCL, Log log) {
372 this.names = Arrays.asList(names.split(",")).iterator();
373 this.processorCL = processorCL;
374 this.log = log;
375 }
377 public boolean hasNext() {
378 if (nextProc != null)
379 return true;
380 else {
381 if (!names.hasNext())
382 return false;
383 else {
384 String processorName = names.next();
386 Processor processor;
387 try {
388 try {
389 processor =
390 (Processor) (processorCL.loadClass(processorName).newInstance());
391 } catch (ClassNotFoundException cnfe) {
392 log.error("proc.processor.not.found", processorName);
393 return false;
394 } catch (ClassCastException cce) {
395 log.error("proc.processor.wrong.type", processorName);
396 return false;
397 } catch (Exception e ) {
398 log.error("proc.processor.cant.instantiate", processorName);
399 return false;
400 }
401 } catch(ClientCodeException e) {
402 throw e;
403 } catch(Throwable t) {
404 throw new AnnotationProcessingError(t);
405 }
406 nextProc = processor;
407 return true;
408 }
410 }
411 }
413 public Processor next() {
414 if (hasNext()) {
415 Processor p = nextProc;
416 nextProc = null;
417 return p;
418 } else
419 throw new NoSuchElementException();
420 }
422 public void remove () {
423 throw new UnsupportedOperationException();
424 }
425 }
427 public boolean atLeastOneProcessor() {
428 return discoveredProcs.iterator().hasNext();
429 }
431 private Map<String, String> initProcessorOptions(Context context) {
432 Options options = Options.instance(context);
433 Set<String> keySet = options.keySet();
434 Map<String, String> tempOptions = new LinkedHashMap<String, String>();
436 for(String key : keySet) {
437 if (key.startsWith("-A") && key.length() > 2) {
438 int sepIndex = key.indexOf('=');
439 String candidateKey = null;
440 String candidateValue = null;
442 if (sepIndex == -1)
443 candidateKey = key.substring(2);
444 else if (sepIndex >= 3) {
445 candidateKey = key.substring(2, sepIndex);
446 candidateValue = (sepIndex < key.length()-1)?
447 key.substring(sepIndex+1) : null;
448 }
449 tempOptions.put(candidateKey, candidateValue);
450 }
451 }
453 return Collections.unmodifiableMap(tempOptions);
454 }
456 private Set<String> initUnmatchedProcessorOptions() {
457 Set<String> unmatchedProcessorOptions = new HashSet<String>();
458 unmatchedProcessorOptions.addAll(processorOptions.keySet());
459 return unmatchedProcessorOptions;
460 }
462 /**
463 * State about how a processor has been used by the tool. If a
464 * processor has been used on a prior round, its process method is
465 * called on all subsequent rounds, perhaps with an empty set of
466 * annotations to process. The {@code annotatedSupported} method
467 * caches the supported annotation information from the first (and
468 * only) getSupportedAnnotationTypes call to the processor.
469 */
470 static class ProcessorState {
471 public Processor processor;
472 public boolean contributed;
473 private ArrayList<Pattern> supportedAnnotationPatterns;
474 private ArrayList<String> supportedOptionNames;
476 ProcessorState(Processor p, Log log, Source source, ProcessingEnvironment env) {
477 processor = p;
478 contributed = false;
480 try {
481 processor.init(env);
483 checkSourceVersionCompatibility(source, log);
485 supportedAnnotationPatterns = new ArrayList<Pattern>();
486 for (String importString : processor.getSupportedAnnotationTypes()) {
487 supportedAnnotationPatterns.add(importStringToPattern(importString,
488 processor,
489 log));
490 }
492 supportedOptionNames = new ArrayList<String>();
493 for (String optionName : processor.getSupportedOptions() ) {
494 if (checkOptionName(optionName, log))
495 supportedOptionNames.add(optionName);
496 }
498 } catch (ClientCodeException e) {
499 throw e;
500 } catch (Throwable t) {
501 throw new AnnotationProcessingError(t);
502 }
503 }
505 /**
506 * Checks whether or not a processor's source version is
507 * compatible with the compilation source version. The
508 * processor's source version needs to be greater than or
509 * equal to the source version of the compile.
510 */
511 private void checkSourceVersionCompatibility(Source source, Log log) {
512 SourceVersion procSourceVersion = processor.getSupportedSourceVersion();
514 if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) {
515 log.warning("proc.processor.incompatible.source.version",
516 procSourceVersion,
517 processor.getClass().getName(),
518 source.name);
519 }
520 }
522 private boolean checkOptionName(String optionName, Log log) {
523 boolean valid = isValidOptionName(optionName);
524 if (!valid)
525 log.error("proc.processor.bad.option.name",
526 optionName,
527 processor.getClass().getName());
528 return valid;
529 }
531 public boolean annotationSupported(String annotationName) {
532 for(Pattern p: supportedAnnotationPatterns) {
533 if (p.matcher(annotationName).matches())
534 return true;
535 }
536 return false;
537 }
539 /**
540 * Remove options that are matched by this processor.
541 */
542 public void removeSupportedOptions(Set<String> unmatchedProcessorOptions) {
543 unmatchedProcessorOptions.removeAll(supportedOptionNames);
544 }
545 }
547 // TODO: These two classes can probably be rewritten better...
548 /**
549 * This class holds information about the processors that have
550 * been discoverd so far as well as the means to discover more, if
551 * necessary. A single iterator should be used per round of
552 * annotation processing. The iterator first visits already
553 * discovered processors then fails over to the service provider
554 * mechanism if additional queries are made.
555 */
556 class DiscoveredProcessors implements Iterable<ProcessorState> {
558 class ProcessorStateIterator implements Iterator<ProcessorState> {
559 DiscoveredProcessors psi;
560 Iterator<ProcessorState> innerIter;
561 boolean onProcInterator;
563 ProcessorStateIterator(DiscoveredProcessors psi) {
564 this.psi = psi;
565 this.innerIter = psi.procStateList.iterator();
566 this.onProcInterator = false;
567 }
569 public ProcessorState next() {
570 if (!onProcInterator) {
571 if (innerIter.hasNext())
572 return innerIter.next();
573 else
574 onProcInterator = true;
575 }
577 if (psi.processorIterator.hasNext()) {
578 ProcessorState ps = new ProcessorState(psi.processorIterator.next(),
579 log, source, JavacProcessingEnvironment.this);
580 psi.procStateList.add(ps);
581 return ps;
582 } else
583 throw new NoSuchElementException();
584 }
586 public boolean hasNext() {
587 if (onProcInterator)
588 return psi.processorIterator.hasNext();
589 else
590 return innerIter.hasNext() || psi.processorIterator.hasNext();
591 }
593 public void remove () {
594 throw new UnsupportedOperationException();
595 }
597 /**
598 * Run all remaining processors on the procStateList that
599 * have not already run this round with an empty set of
600 * annotations.
601 */
602 public void runContributingProcs(RoundEnvironment re) {
603 if (!onProcInterator) {
604 Set<TypeElement> emptyTypeElements = Collections.emptySet();
605 while(innerIter.hasNext()) {
606 ProcessorState ps = innerIter.next();
607 if (ps.contributed)
608 callProcessor(ps.processor, emptyTypeElements, re);
609 }
610 }
611 }
612 }
614 Iterator<? extends Processor> processorIterator;
615 ArrayList<ProcessorState> procStateList;
617 public ProcessorStateIterator iterator() {
618 return new ProcessorStateIterator(this);
619 }
621 DiscoveredProcessors(Iterator<? extends Processor> processorIterator) {
622 this.processorIterator = processorIterator;
623 this.procStateList = new ArrayList<ProcessorState>();
624 }
626 /**
627 * Free jar files, etc. if using a service loader.
628 */
629 public void close() {
630 if (processorIterator != null &&
631 processorIterator instanceof ServiceIterator) {
632 ((ServiceIterator) processorIterator).close();
633 }
634 }
635 }
637 private void discoverAndRunProcs(Context context,
638 Set<TypeElement> annotationsPresent,
639 List<ClassSymbol> topLevelClasses,
640 List<PackageSymbol> packageInfoFiles) {
641 Map<String, TypeElement> unmatchedAnnotations =
642 new HashMap<String, TypeElement>(annotationsPresent.size());
644 for(TypeElement a : annotationsPresent) {
645 unmatchedAnnotations.put(a.getQualifiedName().toString(),
646 a);
647 }
649 // Give "*" processors a chance to match
650 if (unmatchedAnnotations.size() == 0)
651 unmatchedAnnotations.put("", null);
653 DiscoveredProcessors.ProcessorStateIterator psi = discoveredProcs.iterator();
654 // TODO: Create proper argument values; need past round
655 // information to fill in this constructor. Note that the 1
656 // st round of processing could be the last round if there
657 // were parse errors on the initial source files; however, we
658 // are not doing processing in that case.
660 Set<Element> rootElements = new LinkedHashSet<Element>();
661 rootElements.addAll(topLevelClasses);
662 rootElements.addAll(packageInfoFiles);
663 rootElements = Collections.unmodifiableSet(rootElements);
665 RoundEnvironment renv = new JavacRoundEnvironment(false,
666 false,
667 rootElements,
668 JavacProcessingEnvironment.this);
670 while(unmatchedAnnotations.size() > 0 && psi.hasNext() ) {
671 ProcessorState ps = psi.next();
672 Set<String> matchedNames = new HashSet<String>();
673 Set<TypeElement> typeElements = new LinkedHashSet<TypeElement>();
675 for (Map.Entry<String, TypeElement> entry: unmatchedAnnotations.entrySet()) {
676 String unmatchedAnnotationName = entry.getKey();
677 if (ps.annotationSupported(unmatchedAnnotationName) ) {
678 matchedNames.add(unmatchedAnnotationName);
679 TypeElement te = entry.getValue();
680 if (te != null)
681 typeElements.add(te);
682 }
683 }
685 if (matchedNames.size() > 0 || ps.contributed) {
686 boolean processingResult = callProcessor(ps.processor, typeElements, renv);
687 ps.contributed = true;
688 ps.removeSupportedOptions(unmatchedProcessorOptions);
690 if (printProcessorInfo || verbose) {
691 log.printLines("x.print.processor.info",
692 ps.processor.getClass().getName(),
693 matchedNames.toString(),
694 processingResult);
695 }
697 if (processingResult) {
698 unmatchedAnnotations.keySet().removeAll(matchedNames);
699 }
701 }
702 }
703 unmatchedAnnotations.remove("");
705 if (lint && unmatchedAnnotations.size() > 0) {
706 // Remove annotations processed by javac
707 unmatchedAnnotations.keySet().removeAll(platformAnnotations);
708 if (unmatchedAnnotations.size() > 0) {
709 log = Log.instance(context);
710 log.warning("proc.annotations.without.processors",
711 unmatchedAnnotations.keySet());
712 }
713 }
715 // Run contributing processors that haven't run yet
716 psi.runContributingProcs(renv);
718 // Debugging
719 if (options.isSet("displayFilerState"))
720 filer.displayState();
721 }
723 /**
724 * Computes the set of annotations on the symbol in question.
725 * Leave class public for external testing purposes.
726 */
727 public static class ComputeAnnotationSet extends
728 ElementScanner8<Set<TypeElement>, Set<TypeElement>> {
729 final Elements elements;
731 public ComputeAnnotationSet(Elements elements) {
732 super();
733 this.elements = elements;
734 }
736 @Override
737 public Set<TypeElement> visitPackage(PackageElement e, Set<TypeElement> p) {
738 // Don't scan enclosed elements of a package
739 return p;
740 }
742 @Override
743 public Set<TypeElement> scan(Element e, Set<TypeElement> p) {
744 for (AnnotationMirror annotationMirror :
745 elements.getAllAnnotationMirrors(e) ) {
746 Element e2 = annotationMirror.getAnnotationType().asElement();
747 p.add((TypeElement) e2);
748 }
749 return super.scan(e, p);
750 }
751 }
753 private boolean callProcessor(Processor proc,
754 Set<? extends TypeElement> tes,
755 RoundEnvironment renv) {
756 try {
757 return proc.process(tes, renv);
758 } catch (BadClassFile ex) {
759 log.error("proc.cant.access.1", ex.sym, ex.getDetailValue());
760 return false;
761 } catch (CompletionFailure ex) {
762 StringWriter out = new StringWriter();
763 ex.printStackTrace(new PrintWriter(out));
764 log.error("proc.cant.access", ex.sym, ex.getDetailValue(), out.toString());
765 return false;
766 } catch (ClientCodeException e) {
767 throw e;
768 } catch (Throwable t) {
769 throw new AnnotationProcessingError(t);
770 }
771 }
773 /**
774 * Helper object for a single round of annotation processing.
775 */
776 class Round {
777 /** The round number. */
778 final int number;
779 /** The context for the round. */
780 final Context context;
781 /** The compiler for the round. */
782 final JavaCompiler compiler;
783 /** The log for the round. */
784 final Log log;
786 /** The ASTs to be compiled. */
787 List<JCCompilationUnit> roots;
788 /** The classes to be compiler that have were generated. */
789 Map<String, JavaFileObject> genClassFiles;
791 /** The set of annotations to be processed this round. */
792 Set<TypeElement> annotationsPresent;
793 /** The set of top level classes to be processed this round. */
794 List<ClassSymbol> topLevelClasses;
795 /** The set of package-info files to be processed this round. */
796 List<PackageSymbol> packageInfoFiles;
798 /** The number of Messager errors generated in this round. */
799 int nMessagerErrors;
801 /** Create a round (common code). */
802 private Round(Context context, int number, int priorErrors, int priorWarnings) {
803 this.context = context;
804 this.number = number;
806 compiler = JavaCompiler.instance(context);
807 log = Log.instance(context);
808 log.nerrors = priorErrors;
809 log.nwarnings += priorWarnings;
810 log.deferDiagnostics = true;
812 // the following is for the benefit of JavacProcessingEnvironment.getContext()
813 JavacProcessingEnvironment.this.context = context;
815 // the following will be populated as needed
816 topLevelClasses = List.nil();
817 packageInfoFiles = List.nil();
818 }
820 /** Create the first round. */
821 Round(Context context, List<JCCompilationUnit> roots, List<ClassSymbol> classSymbols) {
822 this(context, 1, 0, 0);
823 this.roots = roots;
824 genClassFiles = new HashMap<String,JavaFileObject>();
826 compiler.todo.clear(); // free the compiler's resources
828 // The reverse() in the following line is to maintain behavioural
829 // compatibility with the previous revision of the code. Strictly speaking,
830 // it should not be necessary, but a javah golden file test fails without it.
831 topLevelClasses =
832 getTopLevelClasses(roots).prependList(classSymbols.reverse());
834 packageInfoFiles = getPackageInfoFiles(roots);
836 findAnnotationsPresent();
837 }
839 /** Create a new round. */
840 private Round(Round prev,
841 Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles) {
842 this(prev.nextContext(),
843 prev.number+1,
844 prev.nMessagerErrors,
845 prev.compiler.log.nwarnings);
846 this.genClassFiles = prev.genClassFiles;
848 List<JCCompilationUnit> parsedFiles = compiler.parseFiles(newSourceFiles);
849 roots = cleanTrees(prev.roots).appendList(parsedFiles);
851 // Check for errors after parsing
852 if (unrecoverableError())
853 return;
855 enterClassFiles(genClassFiles);
856 List<ClassSymbol> newClasses = enterClassFiles(newClassFiles);
857 genClassFiles.putAll(newClassFiles);
858 enterTrees(roots);
860 if (unrecoverableError())
861 return;
863 topLevelClasses = join(
864 getTopLevelClasses(parsedFiles),
865 getTopLevelClassesFromClasses(newClasses));
867 packageInfoFiles = join(
868 getPackageInfoFiles(parsedFiles),
869 getPackageInfoFilesFromClasses(newClasses));
871 findAnnotationsPresent();
872 }
874 /** Create the next round to be used. */
875 Round next(Set<JavaFileObject> newSourceFiles, Map<String, JavaFileObject> newClassFiles) {
876 try {
877 return new Round(this, newSourceFiles, newClassFiles);
878 } finally {
879 compiler.close(false);
880 }
881 }
883 /** Create the compiler to be used for the final compilation. */
884 JavaCompiler finalCompiler(boolean errorStatus) {
885 try {
886 JavaCompiler c = JavaCompiler.instance(nextContext());
887 c.log.nwarnings += compiler.log.nwarnings;
888 if (errorStatus) {
889 c.log.nerrors += compiler.log.nerrors;
890 }
891 return c;
892 } finally {
893 compiler.close(false);
894 }
895 }
897 /** Return the number of errors found so far in this round.
898 * This may include uncoverable errors, such as parse errors,
899 * and transient errors, such as missing symbols. */
900 int errorCount() {
901 return compiler.errorCount();
902 }
904 /** Return the number of warnings found so far in this round. */
905 int warningCount() {
906 return compiler.warningCount();
907 }
909 /** Return whether or not an unrecoverable error has occurred. */
910 boolean unrecoverableError() {
911 if (messager.errorRaised())
912 return true;
914 for (JCDiagnostic d: log.deferredDiagnostics) {
915 switch (d.getKind()) {
916 case WARNING:
917 if (werror)
918 return true;
919 break;
921 case ERROR:
922 if (fatalErrors || !d.isFlagSet(RECOVERABLE))
923 return true;
924 break;
925 }
926 }
928 return false;
929 }
931 /** Find the set of annotations present in the set of top level
932 * classes and package info files to be processed this round. */
933 void findAnnotationsPresent() {
934 ComputeAnnotationSet annotationComputer = new ComputeAnnotationSet(elementUtils);
935 // Use annotation processing to compute the set of annotations present
936 annotationsPresent = new LinkedHashSet<TypeElement>();
937 for (ClassSymbol classSym : topLevelClasses)
938 annotationComputer.scan(classSym, annotationsPresent);
939 for (PackageSymbol pkgSym : packageInfoFiles)
940 annotationComputer.scan(pkgSym, annotationsPresent);
941 }
943 /** Enter a set of generated class files. */
944 private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
945 ClassReader reader = ClassReader.instance(context);
946 Names names = Names.instance(context);
947 List<ClassSymbol> list = List.nil();
949 for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
950 Name name = names.fromString(entry.getKey());
951 JavaFileObject file = entry.getValue();
952 if (file.getKind() != JavaFileObject.Kind.CLASS)
953 throw new AssertionError(file);
954 ClassSymbol cs;
955 if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
956 Name packageName = Convert.packagePart(name);
957 PackageSymbol p = reader.enterPackage(packageName);
958 if (p.package_info == null)
959 p.package_info = reader.enterClass(Convert.shortName(name), p);
960 cs = p.package_info;
961 if (cs.classfile == null)
962 cs.classfile = file;
963 } else
964 cs = reader.enterClass(name, file);
965 list = list.prepend(cs);
966 }
967 return list.reverse();
968 }
970 /** Enter a set of syntax trees. */
971 private void enterTrees(List<JCCompilationUnit> roots) {
972 compiler.enterTrees(roots);
973 }
975 /** Run a processing round. */
976 void run(boolean lastRound, boolean errorStatus) {
977 printRoundInfo(lastRound);
979 TaskListener taskListener = context.get(TaskListener.class);
980 if (taskListener != null)
981 taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
983 try {
984 if (lastRound) {
985 filer.setLastRound(true);
986 Set<Element> emptyRootElements = Collections.emptySet(); // immutable
987 RoundEnvironment renv = new JavacRoundEnvironment(true,
988 errorStatus,
989 emptyRootElements,
990 JavacProcessingEnvironment.this);
991 discoveredProcs.iterator().runContributingProcs(renv);
992 } else {
993 discoverAndRunProcs(context, annotationsPresent, topLevelClasses, packageInfoFiles);
994 }
995 } finally {
996 if (taskListener != null)
997 taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
998 }
1000 nMessagerErrors = messager.errorCount();
1001 }
1003 void showDiagnostics(boolean showAll) {
1004 Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class);
1005 if (!showAll) {
1006 // suppress errors, which are all presumed to be transient resolve errors
1007 kinds.remove(JCDiagnostic.Kind.ERROR);
1008 }
1009 log.reportDeferredDiagnostics(kinds);
1010 }
1012 /** Print info about this round. */
1013 private void printRoundInfo(boolean lastRound) {
1014 if (printRounds || verbose) {
1015 List<ClassSymbol> tlc = lastRound ? List.<ClassSymbol>nil() : topLevelClasses;
1016 Set<TypeElement> ap = lastRound ? Collections.<TypeElement>emptySet() : annotationsPresent;
1017 log.printLines("x.print.rounds",
1018 number,
1019 "{" + tlc.toString(", ") + "}",
1020 ap,
1021 lastRound);
1022 }
1023 }
1025 /** Get the context for the next round of processing.
1026 * Important values are propogated from round to round;
1027 * other values are implicitly reset.
1028 */
1029 private Context nextContext() {
1030 Context next = new Context(context);
1032 Options options = Options.instance(context);
1033 Assert.checkNonNull(options);
1034 next.put(Options.optionsKey, options);
1036 Locale locale = context.get(Locale.class);
1037 if (locale != null)
1038 next.put(Locale.class, locale);
1040 Assert.checkNonNull(messages);
1041 next.put(JavacMessages.messagesKey, messages);
1043 final boolean shareNames = true;
1044 if (shareNames) {
1045 Names names = Names.instance(context);
1046 Assert.checkNonNull(names);
1047 next.put(Names.namesKey, names);
1048 }
1050 DiagnosticListener<?> dl = context.get(DiagnosticListener.class);
1051 if (dl != null)
1052 next.put(DiagnosticListener.class, dl);
1054 TaskListener tl = context.get(TaskListener.class);
1055 if (tl != null)
1056 next.put(TaskListener.class, tl);
1058 FSInfo fsInfo = context.get(FSInfo.class);
1059 if (fsInfo != null)
1060 next.put(FSInfo.class, fsInfo);
1062 JavaFileManager jfm = context.get(JavaFileManager.class);
1063 Assert.checkNonNull(jfm);
1064 next.put(JavaFileManager.class, jfm);
1065 if (jfm instanceof JavacFileManager) {
1066 ((JavacFileManager)jfm).setContext(next);
1067 }
1069 Names names = Names.instance(context);
1070 Assert.checkNonNull(names);
1071 next.put(Names.namesKey, names);
1073 Tokens tokens = Tokens.instance(context);
1074 Assert.checkNonNull(tokens);
1075 next.put(Tokens.tokensKey, tokens);
1077 // propogate the log's writers directly, instead of going through context
1078 Log.instance(next).setWriters(log);
1080 JavaCompiler oldCompiler = JavaCompiler.instance(context);
1081 JavaCompiler nextCompiler = JavaCompiler.instance(next);
1082 nextCompiler.initRound(oldCompiler);
1084 filer.newRound(next);
1085 messager.newRound(next);
1086 elementUtils.setContext(next);
1087 typeUtils.setContext(next);
1089 JavacTaskImpl task = context.get(JavacTaskImpl.class);
1090 if (task != null) {
1091 next.put(JavacTaskImpl.class, task);
1092 task.updateContext(next);
1093 }
1095 JavacTrees trees = context.get(JavacTrees.class);
1096 if (trees != null) {
1097 next.put(JavacTrees.class, trees);
1098 trees.updateContext(next);
1099 }
1101 context.clear();
1102 return next;
1103 }
1104 }
1107 // TODO: internal catch clauses?; catch and rethrow an annotation
1108 // processing error
1109 public JavaCompiler doProcessing(Context context,
1110 List<JCCompilationUnit> roots,
1111 List<ClassSymbol> classSymbols,
1112 Iterable<? extends PackageSymbol> pckSymbols) {
1114 TaskListener taskListener = context.get(TaskListener.class);
1115 log = Log.instance(context);
1117 Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>();
1118 for (PackageSymbol psym : pckSymbols)
1119 specifiedPackages.add(psym);
1120 this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages);
1122 Round round = new Round(context, roots, classSymbols);
1124 boolean errorStatus;
1125 boolean moreToDo;
1126 do {
1127 // Run processors for round n
1128 round.run(false, false);
1130 // Processors for round n have run to completion.
1131 // Check for errors and whether there is more work to do.
1132 errorStatus = round.unrecoverableError();
1133 moreToDo = moreToDo();
1135 round.showDiagnostics(errorStatus || showResolveErrors);
1137 // Set up next round.
1138 // Copy mutable collections returned from filer.
1139 round = round.next(
1140 new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects()),
1141 new LinkedHashMap<String,JavaFileObject>(filer.getGeneratedClasses()));
1143 // Check for errors during setup.
1144 if (round.unrecoverableError())
1145 errorStatus = true;
1147 } while (moreToDo && !errorStatus);
1149 // run last round
1150 round.run(true, errorStatus);
1151 round.showDiagnostics(true);
1153 filer.warnIfUnclosedFiles();
1154 warnIfUnmatchedOptions();
1156 /*
1157 * If an annotation processor raises an error in a round,
1158 * that round runs to completion and one last round occurs.
1159 * The last round may also occur because no more source or
1160 * class files have been generated. Therefore, if an error
1161 * was raised on either of the last *two* rounds, the compile
1162 * should exit with a nonzero exit code. The current value of
1163 * errorStatus holds whether or not an error was raised on the
1164 * second to last round; errorRaised() gives the error status
1165 * of the last round.
1166 */
1167 if (messager.errorRaised()
1168 || werror && round.warningCount() > 0 && round.errorCount() > 0)
1169 errorStatus = true;
1171 Set<JavaFileObject> newSourceFiles =
1172 new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects());
1173 roots = cleanTrees(round.roots);
1175 JavaCompiler compiler = round.finalCompiler(errorStatus);
1177 if (newSourceFiles.size() > 0)
1178 roots = roots.appendList(compiler.parseFiles(newSourceFiles));
1180 errorStatus = errorStatus || (compiler.errorCount() > 0);
1182 // Free resources
1183 this.close();
1185 if (taskListener != null)
1186 taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
1188 if (errorStatus) {
1189 if (compiler.errorCount() == 0)
1190 compiler.log.nerrors++;
1191 return compiler;
1192 }
1194 if (procOnly && !foundTypeProcessors) {
1195 compiler.todo.clear();
1196 } else {
1197 if (procOnly && foundTypeProcessors)
1198 compiler.shouldStopPolicy = CompileState.FLOW;
1200 compiler.enterTrees(roots);
1201 }
1203 return compiler;
1204 }
1206 private void warnIfUnmatchedOptions() {
1207 if (!unmatchedProcessorOptions.isEmpty()) {
1208 log.warning("proc.unmatched.processor.options", unmatchedProcessorOptions.toString());
1209 }
1210 }
1212 /**
1213 * Free resources related to annotation processing.
1214 */
1215 public void close() {
1216 filer.close();
1217 if (discoveredProcs != null) // Make calling close idempotent
1218 discoveredProcs.close();
1219 discoveredProcs = null;
1220 }
1222 private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
1223 List<ClassSymbol> classes = List.nil();
1224 for (JCCompilationUnit unit : units) {
1225 for (JCTree node : unit.defs) {
1226 if (node.hasTag(JCTree.Tag.CLASSDEF)) {
1227 ClassSymbol sym = ((JCClassDecl) node).sym;
1228 Assert.checkNonNull(sym);
1229 classes = classes.prepend(sym);
1230 }
1231 }
1232 }
1233 return classes.reverse();
1234 }
1236 private List<ClassSymbol> getTopLevelClassesFromClasses(List<? extends ClassSymbol> syms) {
1237 List<ClassSymbol> classes = List.nil();
1238 for (ClassSymbol sym : syms) {
1239 if (!isPkgInfo(sym)) {
1240 classes = classes.prepend(sym);
1241 }
1242 }
1243 return classes.reverse();
1244 }
1246 private List<PackageSymbol> getPackageInfoFiles(List<? extends JCCompilationUnit> units) {
1247 List<PackageSymbol> packages = List.nil();
1248 for (JCCompilationUnit unit : units) {
1249 if (isPkgInfo(unit.sourcefile, JavaFileObject.Kind.SOURCE)) {
1250 packages = packages.prepend(unit.packge);
1251 }
1252 }
1253 return packages.reverse();
1254 }
1256 private List<PackageSymbol> getPackageInfoFilesFromClasses(List<? extends ClassSymbol> syms) {
1257 List<PackageSymbol> packages = List.nil();
1258 for (ClassSymbol sym : syms) {
1259 if (isPkgInfo(sym)) {
1260 packages = packages.prepend((PackageSymbol) sym.owner);
1261 }
1262 }
1263 return packages.reverse();
1264 }
1266 // avoid unchecked warning from use of varargs
1267 private static <T> List<T> join(List<T> list1, List<T> list2) {
1268 return list1.appendList(list2);
1269 }
1271 private boolean isPkgInfo(JavaFileObject fo, JavaFileObject.Kind kind) {
1272 return fo.isNameCompatible("package-info", kind);
1273 }
1275 private boolean isPkgInfo(ClassSymbol sym) {
1276 return isPkgInfo(sym.classfile, JavaFileObject.Kind.CLASS) && (sym.packge().package_info == sym);
1277 }
1279 /*
1280 * Called retroactively to determine if a class loader was required,
1281 * after we have failed to create one.
1282 */
1283 private boolean needClassLoader(String procNames, Iterable<? extends File> workingpath) {
1284 if (procNames != null)
1285 return true;
1287 String procPath;
1288 URL[] urls = new URL[1];
1289 for(File pathElement : workingpath) {
1290 try {
1291 urls[0] = pathElement.toURI().toURL();
1292 if (ServiceProxy.hasService(Processor.class, urls))
1293 return true;
1294 } catch (MalformedURLException ex) {
1295 throw new AssertionError(ex);
1296 }
1297 catch (ServiceProxy.ServiceConfigurationError e) {
1298 log.error("proc.bad.config.file", e.getLocalizedMessage());
1299 return true;
1300 }
1301 }
1303 return false;
1304 }
1306 private static <T extends JCTree> List<T> cleanTrees(List<T> nodes) {
1307 for (T node : nodes)
1308 treeCleaner.scan(node);
1309 return nodes;
1310 }
1312 private static TreeScanner treeCleaner = new TreeScanner() {
1313 public void scan(JCTree node) {
1314 super.scan(node);
1315 if (node != null)
1316 node.type = null;
1317 }
1318 public void visitTopLevel(JCCompilationUnit node) {
1319 node.packge = null;
1320 super.visitTopLevel(node);
1321 }
1322 public void visitClassDef(JCClassDecl node) {
1323 node.sym = null;
1324 super.visitClassDef(node);
1325 }
1326 public void visitMethodDef(JCMethodDecl node) {
1327 node.sym = null;
1328 super.visitMethodDef(node);
1329 }
1330 public void visitVarDef(JCVariableDecl node) {
1331 node.sym = null;
1332 super.visitVarDef(node);
1333 }
1334 public void visitNewClass(JCNewClass node) {
1335 node.constructor = null;
1336 super.visitNewClass(node);
1337 }
1338 public void visitAssignop(JCAssignOp node) {
1339 node.operator = null;
1340 super.visitAssignop(node);
1341 }
1342 public void visitUnary(JCUnary node) {
1343 node.operator = null;
1344 super.visitUnary(node);
1345 }
1346 public void visitBinary(JCBinary node) {
1347 node.operator = null;
1348 super.visitBinary(node);
1349 }
1350 public void visitSelect(JCFieldAccess node) {
1351 node.sym = null;
1352 super.visitSelect(node);
1353 }
1354 public void visitIdent(JCIdent node) {
1355 node.sym = null;
1356 super.visitIdent(node);
1357 }
1358 };
1361 private boolean moreToDo() {
1362 return filer.newFiles();
1363 }
1365 /**
1366 * {@inheritdoc}
1367 *
1368 * Command line options suitable for presenting to annotation
1369 * processors. "-Afoo=bar" should be "-Afoo" => "bar".
1370 */
1371 public Map<String,String> getOptions() {
1372 return processorOptions;
1373 }
1375 public Messager getMessager() {
1376 return messager;
1377 }
1379 public Filer getFiler() {
1380 return filer;
1381 }
1383 public JavacElements getElementUtils() {
1384 return elementUtils;
1385 }
1387 public JavacTypes getTypeUtils() {
1388 return typeUtils;
1389 }
1391 public SourceVersion getSourceVersion() {
1392 return Source.toSourceVersion(source);
1393 }
1395 public Locale getLocale() {
1396 return messages.getCurrentLocale();
1397 }
1399 public Set<Symbol.PackageSymbol> getSpecifiedPackages() {
1400 return specifiedPackages;
1401 }
1403 private static final Pattern allMatches = Pattern.compile(".*");
1404 public static final Pattern noMatches = Pattern.compile("(\\P{all})+");
1406 /**
1407 * Convert import-style string for supported annotations into a
1408 * regex matching that string. If the string is a valid
1409 * import-style string, return a regex that won't match anything.
1410 */
1411 private static Pattern importStringToPattern(String s, Processor p, Log log) {
1412 if (isValidImportString(s)) {
1413 return validImportStringToPattern(s);
1414 } else {
1415 log.warning("proc.malformed.supported.string", s, p.getClass().getName());
1416 return noMatches; // won't match any valid identifier
1417 }
1418 }
1420 /**
1421 * Return true if the argument string is a valid import-style
1422 * string specifying claimed annotations; return false otherwise.
1423 */
1424 public static boolean isValidImportString(String s) {
1425 if (s.equals("*"))
1426 return true;
1428 boolean valid = true;
1429 String t = s;
1430 int index = t.indexOf('*');
1432 if (index != -1) {
1433 // '*' must be last character...
1434 if (index == t.length() -1) {
1435 // ... any and preceding character must be '.'
1436 if ( index-1 >= 0 ) {
1437 valid = t.charAt(index-1) == '.';
1438 // Strip off ".*$" for identifier checks
1439 t = t.substring(0, t.length()-2);
1440 }
1441 } else
1442 return false;
1443 }
1445 // Verify string is off the form (javaId \.)+ or javaId
1446 if (valid) {
1447 String[] javaIds = t.split("\\.", t.length()+2);
1448 for(String javaId: javaIds)
1449 valid &= SourceVersion.isIdentifier(javaId);
1450 }
1451 return valid;
1452 }
1454 public static Pattern validImportStringToPattern(String s) {
1455 if (s.equals("*")) {
1456 return allMatches;
1457 } else {
1458 String s_prime = s.replace(".", "\\.");
1460 if (s_prime.endsWith("*")) {
1461 s_prime = s_prime.substring(0, s_prime.length() - 1) + ".+";
1462 }
1464 return Pattern.compile(s_prime);
1465 }
1466 }
1468 /**
1469 * For internal use only. This method will be
1470 * removed without warning.
1471 */
1472 public Context getContext() {
1473 return context;
1474 }
1476 public String toString() {
1477 return "javac ProcessingEnvironment";
1478 }
1480 public static boolean isValidOptionName(String optionName) {
1481 for(String s : optionName.split("\\.", -1)) {
1482 if (!SourceVersion.isIdentifier(s))
1483 return false;
1484 }
1485 return true;
1486 }
1487 }