< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/model/JavacElements.java

Print this page
rev 50958 : imported patch 8189747

*** 24,36 **** --- 24,38 ---- */ package com.sun.tools.javac.model; import java.util.Collections; + import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Map; + import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import javax.lang.model.AnnotatedConstruct; import javax.lang.model.SourceVersion;
*** 182,199 **** --- 184,204 ---- return nameToSymbol((ModuleSymbol) module, strName, clazz); } } private final Set<String> alreadyWarnedDuplicates = new HashSet<>(); + private final Map<Pair<String, String>, Optional<Symbol>> resultCache = new HashMap<>(); + @SuppressWarnings("unchecked") private <S extends Symbol> S unboundNameToSymbol(String methodName, String nameStr, Class<S> clazz) { if (modules.getDefaultModule() == syms.noModule) { //not a modular mode: return nameToSymbol(syms.noModule, nameStr, clazz); } + return (S) resultCache.computeIfAbsent(Pair.of(methodName, nameStr), p -> { Set<S> found = new LinkedHashSet<>(); for (ModuleSymbol msym : modules.allModules()) { S sym = nameToSymbol(msym, nameStr, clazz);
*** 213,237 **** } } } if (found.size() == 1) { ! return found.iterator().next(); } else if (found.size() > 1) { //more than one element found, produce a note: if (alreadyWarnedDuplicates.add(methodName + ":" + nameStr)) { String moduleNames = found.stream() .map(s -> s.packge().modle) .map(m -> m.toString()) .collect(Collectors.joining(", ")); log.note(Notes.MultipleElements(methodName, nameStr, moduleNames)); } ! return null; } else { ! //not found, or more than one element found: ! return null; } } /** * Returns a symbol given the type's or package's canonical name, * or null if the name isn't found. --- 218,243 ---- } } } if (found.size() == 1) { ! return Optional.of(found.iterator().next()); } else if (found.size() > 1) { //more than one element found, produce a note: if (alreadyWarnedDuplicates.add(methodName + ":" + nameStr)) { String moduleNames = found.stream() .map(s -> s.packge().modle) .map(m -> m.toString()) .collect(Collectors.joining(", ")); log.note(Notes.MultipleElements(methodName, nameStr, moduleNames)); } ! return Optional.empty(); } else { ! //not found: ! return Optional.empty(); } + }).orElse(null); } /** * Returns a symbol given the type's or package's canonical name, * or null if the name isn't found.
*** 785,790 **** --- 791,800 ---- private static <T> T cast(Class<T> clazz, Object o) { if (! clazz.isInstance(o)) throw new IllegalArgumentException(o.toString()); return clazz.cast(o); } + + public void newRound() { + resultCache.clear(); + } }
< prev index next >