ImportPriorityChoice (@NotNull PyImportStatementBase importStatement) { final PsiElement resolved; final PsiElement resolveAnchor; if (importStatement instanceof PyFromImportStatement fromImportStatement) { if (fromImportStatement.isFromFuture()) { return new ImportPriorityChoice(ImportPriority.FUTURE, "import from __future__"); } if (fromImportStatement.getRelativeLevel() > 0) { return new ImportPriorityChoice(ImportPriority.PROJECT, "explicit relative import"); } resolveAnchor = ((PyFromImportStatement)importStatement).getImportSource(); resolved = fromImportStatement.resolveImportSource(); } else { final PyImportElement firstImportElement = ArrayUtil.getFirstElement(importStatement.getImportElements()); if (firstImportElement == null) { return new ImportPriorityChoice(UNRESOLVED_SYMBOL_PRIORITY, "incomplete import statement"); } resolveAnchor = firstImportElement; resolved = firstImportElement.resolve(); } if (resolved == null) { return new ImportPriorityChoice(UNRESOLVED_SYMBOL_PRIORITY, resolveAnchor == null ? "incomplete import statement" : resolveAnchor.getText() + " is unresolved"); } PsiFileSystemItem resolvedFileOrDir; if (resolved instanceof PsiDirectory) { resolvedFileOrDir = (PsiFileSystemItem)resolved; } // resolved symbol may be PsiPackage in Jython else if (resolved instanceof PsiDirectoryContainer) { resolvedFileOrDir = ArrayUtil.getFirstElement(((PsiDirectoryContainer)resolved).getDirectories()); } else { resolvedFileOrDir = resolved.getContainingFile(); } if (resolvedFileOrDir instanceof PyiFile) { final PsiElement original = PyiUtil.getOriginalElement((PyiFile)resolvedFileOrDir); resolvedFileOrDir = ObjectUtils.notNull(as(original, PsiFileSystemItem.class), resolvedFileOrDir); } if (resolvedFileOrDir == null) { return new ImportPriorityChoice(UNRESOLVED_SYMBOL_PRIORITY, resolved + " is not a file or directory"); } return getImportPriorityWithReason(importStatement, resolvedFileOrDir); }