< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java

Print this page

        

*** 684,719 **** * only) getSupportedAnnotationTypes call to the processor. */ static class ProcessorState { public Processor processor; public boolean contributed; ! private ArrayList<Pattern> supportedAnnotationPatterns; ! private ArrayList<String> supportedOptionNames; ProcessorState(Processor p, Log log, Source source, DeferredCompletionFailureHandler dcfh, ! boolean allowModules, ProcessingEnvironment env) { processor = p; contributed = false; Handler prevDeferredHandler = dcfh.setHandler(dcfh.userCodeHandler); try { processor.init(env); checkSourceVersionCompatibility(source, log); ! supportedAnnotationPatterns = new ArrayList<>(); ! for (String importString : processor.getSupportedAnnotationTypes()) { ! supportedAnnotationPatterns.add(importStringToPattern(allowModules, ! importString, ! processor, ! log)); } ! supportedOptionNames = new ArrayList<>(); for (String optionName : processor.getSupportedOptions() ) { ! if (checkOptionName(optionName, log)) ! supportedOptionNames.add(optionName); } } catch (ClientCodeException e) { throw e; } catch (Throwable t) { --- 684,748 ---- * only) getSupportedAnnotationTypes call to the processor. */ static class ProcessorState { public Processor processor; public boolean contributed; ! private Set<String> supportedAnnotationStrings; // Used for warning generation ! private Set<Pattern> supportedAnnotationPatterns; ! private Set<String> supportedOptionNames; ProcessorState(Processor p, Log log, Source source, DeferredCompletionFailureHandler dcfh, ! boolean allowModules, ProcessingEnvironment env, boolean lint) { processor = p; contributed = false; Handler prevDeferredHandler = dcfh.setHandler(dcfh.userCodeHandler); try { processor.init(env); checkSourceVersionCompatibility(source, log); ! ! // Check for direct duplicates in the strings of ! // supported annotation types. Do not check for ! // duplicates that would result after stripping of ! // module prefixes. ! supportedAnnotationStrings = new LinkedHashSet<>(); ! supportedAnnotationPatterns = new LinkedHashSet<>(); ! for (String annotationPattern : processor.getSupportedAnnotationTypes()) { ! boolean patternAdded = supportedAnnotationStrings.add(annotationPattern); ! ! supportedAnnotationPatterns. ! add(importStringToPattern(allowModules, annotationPattern, ! processor, log, lint)); ! if (lint && !patternAdded) { ! log.warning(Warnings.ProcDuplicateSupportedAnnotation(annotationPattern, ! p.getClass().getName())); ! } ! } ! ! // If a processor supports "*", that matches ! // everything and other entries are redundant. With ! // more work, it could be checked that the supported ! // annotation types were otherwise non-overlapping ! // with each other in other cases, for example "foo.*" ! // and "foo.bar.*". ! if (lint && ! supportedAnnotationPatterns.contains(MatchingUtils.validImportStringToPattern("*")) && ! supportedAnnotationPatterns.size() > 1) { ! log.warning(Warnings.ProcRedundantTypesWithWildcard(p.getClass().getName())); } ! supportedOptionNames = new LinkedHashSet<>(); for (String optionName : processor.getSupportedOptions() ) { ! if (checkOptionName(optionName, log)) { ! boolean optionAdded = supportedOptionNames.add(optionName); ! if (lint && !optionAdded) { ! log.warning(Warnings.ProcDuplicateOptionName(optionName, ! p.getClass().getName())); ! } ! } } } catch (ClientCodeException e) { throw e; } catch (Throwable t) {
*** 795,805 **** if (psi.processorIterator.hasNext()) { ProcessorState ps = new ProcessorState(psi.processorIterator.next(), log, source, dcfh, Feature.MODULES.allowedInSource(source), ! JavacProcessingEnvironment.this); psi.procStateList.add(ps); return ps; } else throw new NoSuchElementException(); } --- 824,835 ---- if (psi.processorIterator.hasNext()) { ProcessorState ps = new ProcessorState(psi.processorIterator.next(), log, source, dcfh, Feature.MODULES.allowedInSource(source), ! JavacProcessingEnvironment.this, ! lint); psi.procStateList.add(ps); return ps; } else throw new NoSuchElementException(); }
*** 1703,1732 **** /** * Convert import-style string for supported annotations into a * regex matching that string. If the string is not a valid * import-style string, return a regex that won't match anything. */ ! private static Pattern importStringToPattern(boolean allowModules, String s, Processor p, Log log) { String module; String pkg; int slash = s.indexOf('/'); if (slash == (-1)) { if (s.equals("*")) { return MatchingUtils.validImportStringToPattern(s); } module = allowModules ? ".*/" : ""; pkg = s; } else { ! module = Pattern.quote(s.substring(0, slash + 1)); pkg = s.substring(slash + 1); } if (MatchingUtils.isValidImportString(pkg)) { return Pattern.compile(module + MatchingUtils.validImportStringToPatternString(pkg)); } else { log.warning(Warnings.ProcMalformedSupportedString(s, p.getClass().getName())); - return noMatches; // won't match any valid identifier } } /** * For internal use only. This method may be removed without warning. */ --- 1733,1773 ---- /** * Convert import-style string for supported annotations into a * regex matching that string. If the string is not a valid * import-style string, return a regex that won't match anything. */ ! private static Pattern importStringToPattern(boolean allowModules, String s, Processor p, Log log, boolean lint) { String module; String pkg; int slash = s.indexOf('/'); if (slash == (-1)) { if (s.equals("*")) { return MatchingUtils.validImportStringToPattern(s); } module = allowModules ? ".*/" : ""; pkg = s; } else { ! String moduleName = s.substring(0, slash); ! if (!SourceVersion.isIdentifier(moduleName)) { ! return warnAndNoMatches(s, p, log, lint); ! } ! module = Pattern.quote(moduleName + "/"); ! // And warn if module is specified if modules aren't supported, conditional on -Xlint:proc? pkg = s.substring(slash + 1); } if (MatchingUtils.isValidImportString(pkg)) { return Pattern.compile(module + MatchingUtils.validImportStringToPatternString(pkg)); } else { + return warnAndNoMatches(s, p, log, lint); + } + } + + private static Pattern warnAndNoMatches(String s, Processor p, Log log, boolean lint) { + if (lint) { log.warning(Warnings.ProcMalformedSupportedString(s, p.getClass().getName())); } + return noMatches; // won't match any valid identifier } /** * For internal use only. This method may be removed without warning. */
< prev index next >