From bcb02af54c050cce5b2cc293aa90d6534c90bd1d Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Wed, 5 Apr 2017 18:18:02 +0300 Subject: [PATCH] Fix return value of QualifiedNameFinder#findShortestImportableName() in case of a cache hit It returned a string representation of the list of saved names instead of the shorted qualified name itself. --- .../python/psi/resolve/QualifiedNameFinder.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/python/src/com/jetbrains/python/psi/resolve/QualifiedNameFinder.java b/python/src/com/jetbrains/python/psi/resolve/QualifiedNameFinder.java index 24c4213715ef..3fc8cb5cbe3c 100644 --- a/python/src/com/jetbrains/python/psi/resolve/QualifiedNameFinder.java +++ b/python/src/com/jetbrains/python/psi/resolve/QualifiedNameFinder.java @@ -36,6 +36,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * @author yole @@ -90,16 +91,14 @@ public class QualifiedNameFinder { @Nullable public static String findShortestImportableName(Module module, @NotNull VirtualFile vfile) { final PythonPathCache cache = PythonModulePathCache.getInstance(module); - final List names = cache.getNames(vfile); - if (names != null) { - return names.toString(); + List names = cache.getNames(vfile); + if (names == null) { + final PathChoosingVisitor visitor = new PathChoosingVisitor(vfile); + RootVisitorHost.visitRoots(module, false, visitor); + names = visitor.getResults(); + cache.putNames(vfile, names); } - PathChoosingVisitor visitor = new PathChoosingVisitor(vfile); - RootVisitorHost.visitRoots(module, false, visitor); - final List results = visitor.getResults(); - cache.putNames(vfile, results); - final QualifiedName qName = shortestQName(results); - return qName == null ? null : qName.toString(); + return Objects.toString(shortestQName(names), null); } /**