diff --git a/check_api/src/main/java/com/google/errorprone/VisitorState.java b/check_api/src/main/java/com/google/errorprone/VisitorState.java index 4439345e6c13..bf347ba67e3b 100644 --- a/check_api/src/main/java/com/google/errorprone/VisitorState.java +++ b/check_api/src/main/java/com/google/errorprone/VisitorState.java @@ -44,13 +44,13 @@ import com.sun.tools.javac.code.Type.ArrayType; import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.Types; +import com.sun.tools.javac.comp.Modules; import com.sun.tools.javac.model.JavacElements; import com.sun.tools.javac.parser.Tokens.Token; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.tree.TreeMaker; import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.Convert; import com.sun.tools.javac.util.Name; import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Options; @@ -406,8 +406,20 @@ public Name binaryNameFromClassname(String className) { */ @Nullable public ClassSymbol getSymbolFromName(Name name) { - ModuleSymbol msym = getSymtab().inferModule(Convert.packagePart(name)); - return msym != null ? getSymbolFromString(msym, name) : null; + boolean modular = sharedState.modules.getDefaultModule() != getSymtab().noModule; + if (!modular) { + return getSymbolFromString(getSymtab().noModule, name); + } + for (ModuleSymbol msym : sharedState.modules.allModules()) { + ClassSymbol result = getSymbolFromString(msym, name); + if (result != null) { + // TODO(cushon): the path where we iterate over all modules is probably slow. + // Try to learn some lessons from JDK-8189747, and consider disallowing this case and + // requiring users to call the getSymbolFromString(ModuleSymbol, Name) overload instead. + return result; + } + } + return null; } @Nullable @@ -723,6 +735,7 @@ public static Supplier memoize(Supplier f) { * {@code SomeClass.instance(context)} has sizable performance improvements in aggregate. */ private static final class SharedState { + private final Modules modules; private final Names names; private final Symtab symtab; private final ErrorProneTimings timings; @@ -746,6 +759,7 @@ private static final class SharedState { StatisticsCollector statisticsCollector, Map severityMap, ErrorProneOptions errorProneOptions) { + this.modules = Modules.instance(context); this.names = Names.instance(context); this.symtab = Symtab.instance(context); this.timings = ErrorProneTimings.instance(context);