langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
equal
deleted
inserted
replaced
112 private final boolean verbose; |
112 private final boolean verbose; |
113 private final boolean lint; |
113 private final boolean lint; |
114 private final boolean fatalErrors; |
114 private final boolean fatalErrors; |
115 private final boolean werror; |
115 private final boolean werror; |
116 private final boolean showResolveErrors; |
116 private final boolean showResolveErrors; |
|
117 private final boolean allowModules; |
117 |
118 |
118 private final JavacFiler filer; |
119 private final JavacFiler filer; |
119 private final JavacMessager messager; |
120 private final JavacMessager messager; |
120 private final JavacElements elementUtils; |
121 private final JavacElements elementUtils; |
121 private final JavacTypes typeUtils; |
122 private final JavacTypes typeUtils; |
176 private final Symtab symtab; |
177 private final Symtab symtab; |
177 private final Names names; |
178 private final Names names; |
178 private final Enter enter; |
179 private final Enter enter; |
179 private final Completer initialCompleter; |
180 private final Completer initialCompleter; |
180 private final Check chk; |
181 private final Check chk; |
181 private final ModuleSymbol defaultModule; |
|
182 |
182 |
183 private final Context context; |
183 private final Context context; |
184 |
184 |
185 /** Get the JavacProcessingEnvironment instance for this context. */ |
185 /** Get the JavacProcessingEnvironment instance for this context. */ |
186 public static JavacProcessingEnvironment instance(Context context) { |
186 public static JavacProcessingEnvironment instance(Context context) { |
228 enter = Enter.instance(context); |
228 enter = Enter.instance(context); |
229 initialCompleter = ClassFinder.instance(context).getCompleter(); |
229 initialCompleter = ClassFinder.instance(context).getCompleter(); |
230 chk = Check.instance(context); |
230 chk = Check.instance(context); |
231 initProcessorLoader(); |
231 initProcessorLoader(); |
232 |
232 |
233 defaultModule = source.allowModules() && options.isUnset("noModules") |
233 allowModules = source.allowModules() && options.isUnset("noModules"); |
234 ? symtab.unnamedModule : symtab.noModule; |
|
235 } |
234 } |
236 |
235 |
237 public void setProcessors(Iterable<? extends Processor> processors) { |
236 public void setProcessors(Iterable<? extends Processor> processors) { |
238 Assert.checkNull(discoveredProcs); |
237 Assert.checkNull(discoveredProcs); |
239 initProcessorIterator(processors); |
238 initProcessorIterator(processors); |
663 public Processor processor; |
662 public Processor processor; |
664 public boolean contributed; |
663 public boolean contributed; |
665 private ArrayList<Pattern> supportedAnnotationPatterns; |
664 private ArrayList<Pattern> supportedAnnotationPatterns; |
666 private ArrayList<String> supportedOptionNames; |
665 private ArrayList<String> supportedOptionNames; |
667 |
666 |
668 ProcessorState(Processor p, Log log, Source source, ProcessingEnvironment env) { |
667 ProcessorState(Processor p, Log log, Source source, boolean allowModules, ProcessingEnvironment env) { |
669 processor = p; |
668 processor = p; |
670 contributed = false; |
669 contributed = false; |
671 |
670 |
672 try { |
671 try { |
673 processor.init(env); |
672 processor.init(env); |
674 |
673 |
675 checkSourceVersionCompatibility(source, log); |
674 checkSourceVersionCompatibility(source, log); |
676 |
675 |
677 supportedAnnotationPatterns = new ArrayList<>(); |
676 supportedAnnotationPatterns = new ArrayList<>(); |
678 for (String importString : processor.getSupportedAnnotationTypes()) { |
677 for (String importString : processor.getSupportedAnnotationTypes()) { |
679 supportedAnnotationPatterns.add(importStringToPattern(importString, |
678 supportedAnnotationPatterns.add(importStringToPattern(allowModules, |
|
679 importString, |
680 processor, |
680 processor, |
681 log)); |
681 log)); |
682 } |
682 } |
683 |
683 |
684 supportedOptionNames = new ArrayList<>(); |
684 supportedOptionNames = new ArrayList<>(); |
766 onProcInterator = true; |
766 onProcInterator = true; |
767 } |
767 } |
768 |
768 |
769 if (psi.processorIterator.hasNext()) { |
769 if (psi.processorIterator.hasNext()) { |
770 ProcessorState ps = new ProcessorState(psi.processorIterator.next(), |
770 ProcessorState ps = new ProcessorState(psi.processorIterator.next(), |
771 log, source, JavacProcessingEnvironment.this); |
771 log, source, allowModules, |
|
772 JavacProcessingEnvironment.this); |
772 psi.procStateList.add(ps); |
773 psi.procStateList.add(ps); |
773 return ps; |
774 return ps; |
774 } else |
775 } else |
775 throw new NoSuchElementException(); |
776 throw new NoSuchElementException(); |
776 } |
777 } |
832 List<ModuleSymbol> moduleInfoFiles) { |
833 List<ModuleSymbol> moduleInfoFiles) { |
833 Map<String, TypeElement> unmatchedAnnotations = new HashMap<>(annotationsPresent.size()); |
834 Map<String, TypeElement> unmatchedAnnotations = new HashMap<>(annotationsPresent.size()); |
834 |
835 |
835 for(TypeElement a : annotationsPresent) { |
836 for(TypeElement a : annotationsPresent) { |
836 ModuleElement mod = elementUtils.getModuleOf(a); |
837 ModuleElement mod = elementUtils.getModuleOf(a); |
837 unmatchedAnnotations.put((mod != null ? mod.getSimpleName() + "/" : "") + a.getQualifiedName().toString(), |
838 String moduleSpec = allowModules && mod != null ? mod.getSimpleName() + "/" : ""; |
|
839 unmatchedAnnotations.put(moduleSpec + a.getQualifiedName().toString(), |
838 a); |
840 a); |
839 } |
841 } |
840 |
842 |
841 // Give "*" processors a chance to match |
843 // Give "*" processors a chance to match |
842 if (unmatchedAnnotations.size() == 0) |
844 if (unmatchedAnnotations.size() == 0) |
1655 /** |
1657 /** |
1656 * Convert import-style string for supported annotations into a |
1658 * Convert import-style string for supported annotations into a |
1657 * regex matching that string. If the string is not a valid |
1659 * regex matching that string. If the string is not a valid |
1658 * import-style string, return a regex that won't match anything. |
1660 * import-style string, return a regex that won't match anything. |
1659 */ |
1661 */ |
1660 private static Pattern importStringToPattern(String s, Processor p, Log log) { |
1662 private static Pattern importStringToPattern(boolean allowModules, String s, Processor p, Log log) { |
1661 String module; |
1663 String module; |
1662 String pkg; |
1664 String pkg; |
1663 int slash = s.indexOf('/'); |
1665 int slash = s.indexOf('/'); |
1664 if (slash == (-1)) { |
1666 if (slash == (-1)) { |
1665 if (s.equals("*")) { |
1667 if (s.equals("*")) { |
1670 } else { |
1672 } else { |
1671 module = Pattern.quote(s.substring(0, slash + 1)); |
1673 module = Pattern.quote(s.substring(0, slash + 1)); |
1672 pkg = s.substring(slash + 1); |
1674 pkg = s.substring(slash + 1); |
1673 } |
1675 } |
1674 if (MatchingUtils.isValidImportString(pkg)) { |
1676 if (MatchingUtils.isValidImportString(pkg)) { |
1675 return Pattern.compile(module + MatchingUtils.validImportStringToPatternString(pkg)); |
1677 return Pattern.compile((allowModules ? module : "") + MatchingUtils.validImportStringToPatternString(pkg)); |
1676 } else { |
1678 } else { |
1677 log.warning("proc.malformed.supported.string", s, p.getClass().getName()); |
1679 log.warning("proc.malformed.supported.string", s, p.getClass().getName()); |
1678 return noMatches; // won't match any valid identifier |
1680 return noMatches; // won't match any valid identifier |
1679 } |
1681 } |
1680 } |
1682 } |