List<QualifiedName> (@NotNull PyImportElement element) { final List<QualifiedName> importedQNames = new ArrayList<>(); final PyStatement stmt = element.getContainingImportStatement(); final PyFromImportStatement fromImportStatement = ObjectUtils.tryCast(stmt, PyFromImportStatement.class); if (fromImportStatement != null) { final QualifiedName importedQName = fromImportStatement.getImportSourceQName(); final String visibleName = element.getVisibleName(); if (importedQName != null) { importedQNames.add(importedQName); if (visibleName != null) { importedQNames.add(importedQName.append(visibleName)); } } else { final List<PsiElement> elements = ResolveImportUtil.resolveFromImportStatementSource(fromImportStatement, element.getImportedQName()); for (PsiElement psiElement : elements) { if (psiElement instanceof PsiFile) { final VirtualFile virtualFile = ((PsiFile)psiElement).getVirtualFile(); final QualifiedName qName = QualifiedNameFinder.findShortestImportableQName(element, virtualFile); if (qName != null) { importedQNames.add(qName); } } } } } else if (stmt instanceof PyImportStatement) { final QualifiedName importedQName = element.getImportedQName(); if (importedQName != null) { importedQNames.add(importedQName); } } if (!ResolveImportUtil.isAbsoluteImportEnabledFor(element) || (fromImportStatement != null && fromImportStatement.getRelativeLevel() == 1)) { PsiFile file = element.getContainingFile(); if (file != null) { file = file.getOriginalFile(); } final QualifiedName absoluteQName = QualifiedNameFinder.findShortestImportableQName(file); if (file != null && absoluteQName != null) { final QualifiedName prefixQName = PyUtil.isPackage(file) ? absoluteQName : absoluteQName.removeLastComponent(); if (prefixQName.getComponentCount() > 0) { final List<QualifiedName> results = new ArrayList<>(importedQNames); for (QualifiedName qName : importedQNames) { final List<String> components = new ArrayList<>(); components.addAll(prefixQName.getComponents()); components.addAll(qName.getComponents()); results.add(QualifiedName.fromComponents(components)); } return results; } } } return importedQNames; }