@NotNull public static List<PsiElement> resolveFromImportStatementSource( @NotNull PyFromImportStatement fromImportStatement, @Nullable QualifiedName qName) { final boolean absoluteImportEnabled = isAbsoluteImportEnabledFor(fromImportStatement); final PsiFile file = fromImportStatement.getContainingFile(); return resolveModule( qName, file, absoluteImportEnabled, fromImportStatement.getRelativeLevel()); }
@NotNull public static List<RatedResolveResult> resolveNameInFromImport( PyFromImportStatement importStatement, @NotNull QualifiedName qName) { PsiFile file = importStatement.getContainingFile().getOriginalFile(); String name = qName.getComponents().get(0); final List<PsiElement> candidates = importStatement.resolveImportSourceCandidates(); List<PsiElement> resultList = new ArrayList<PsiElement>(); for (PsiElement candidate : candidates) { if (!candidate.isValid()) { throw new PsiInvalidElementAccessException( candidate, "Got an invalid candidate from resolveImportSourceCandidates(): " + candidate.getClass()); } if (candidate instanceof PsiDirectory) { candidate = PyUtil.getPackageElement((PsiDirectory) candidate, importStatement); } List<RatedResolveResult> results = resolveChildren(candidate, name, file, false, true); if (!results.isEmpty()) { for (RatedResolveResult result : results) { final PsiElement element = result.getElement(); if (element != null) { if (!element.isValid()) { throw new PsiInvalidElementAccessException( element, "Got an invalid candidate from resolveChild(): " + element.getClass()); } resultList.add(element); } } } } if (!resultList.isEmpty()) { return rateResults(resultList); } return Collections.emptyList(); }