PyFile (@NotNull String qName, @NotNull PsiElement foothold) { final Sdk sdk = PythonSdkUtil.findPythonSdk(foothold); if (sdk != null) { final Project project = foothold.getProject(); final PythonSdkPathCache cache = PythonSdkPathCache.getInstance(project, sdk); final QualifiedName cacheQName = QualifiedName.fromDottedString(USER_SKELETONS_DIR + "." + qName); final List<PsiElement> results = cache.get(cacheQName); if (results != null) { final PsiElement element = results.isEmpty() ? null : results.get(0); if (element instanceof PyFile) { return (PyFile)element; } } final VirtualFile directory = getUserSkeletonsDirectory(); if (directory != null) { final PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(directory); PsiElement fileSkeleton = PyResolveImportUtil.resolveModuleAt(QualifiedName.fromDottedString(qName), psiDirectory, PyResolveImportUtil.fromFoothold(foothold)) .stream().findFirst().orElse(null); if (fileSkeleton instanceof PsiDirectory) { fileSkeleton = PyUtil.getPackageElement((PsiDirectory)fileSkeleton, foothold); } if (fileSkeleton instanceof PyFile) { cache.put(cacheQName, Collections.singletonList(fileSkeleton)); return (PyFile)fileSkeleton; } } cache.put(cacheQName, Collections.emptyList()); } return null; }