@NotNull private static List<RatedResolveResult> resolveInPackageDirectory( @Nullable PsiElement parent, @NotNull String referencedName, @Nullable PsiFile containingFile, boolean fileOnly, boolean checkForPackage) { final PsiElement parentDir = PyUtil.turnInitIntoDir(parent); if (parentDir instanceof PsiDirectory) { final List<RatedResolveResult> resolved = resolveInDirectory( referencedName, containingFile, (PsiDirectory) parentDir, fileOnly, checkForPackage); if (!resolved.isEmpty()) { for (RatedResolveResult result : resolved) { if (result.getRate() > RatedResolveResult.RATE_LOW) { return resolved; } } } if (parent instanceof PsiFile) { final PsiElement foreign = resolveForeignImports((PsiFile) parent, referencedName); if (foreign != null) { final ResolveResultList results = new ResolveResultList(); results.addAll(resolved); results.poke(foreign, RatedResolveResult.RATE_NORMAL); return results; } } return resolved; } return Collections.emptyList(); }
@NotNull @Override public Collection<PsiReference> findReferencesToHighlight( @NotNull PsiElement target, @NotNull SearchScope searchScope) { if (target instanceof PyImportedModule) { target = ((PyImportedModule) target).resolve(); } if (target instanceof PyFile && PyNames.INIT_DOT_PY.equals(((PyFile) target).getName())) { List<PsiReference> result = new ArrayList<PsiReference>(); result.addAll(super.findReferencesToHighlight(target, searchScope)); PsiElement targetDir = PyUtil.turnInitIntoDir(target); if (targetDir != null) { result.addAll(ReferencesSearch.search(targetDir, searchScope, false).findAll()); } return result; } return super.findReferencesToHighlight(target, searchScope); }
protected PyModuleFindUsagesHandler(@NotNull PsiFileSystemItem file) { super(file); final PsiElement e = PyUtil.turnInitIntoDir(file); myElement = e instanceof PsiFileSystemItem ? (PsiFileSystemItem) e : file; }