void (@NotNull PsiFileSystemItem target, @NotNull PsiFile file, @NotNull PyElement element) { final PsiFileSystemItem toImport = target.getParent(); if (toImport == null) return; final QualifiedName importPath = QualifiedNameFinder.findCanonicalImportPath(target, element); if (importPath == null) return; final ImportPriority priority = getImportPriority(file, toImport); if (importPath.getComponentCount() == 1 || !PyCodeInsightSettings.getInstance().PREFER_FROM_IMPORT) { final String path = importPath.toString(); addImportStatement(file, path, null, priority, element); final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(file.getProject()); element.replace(elementGenerator.createExpressionFromText(LanguageLevel.forElement(target), path)); } else { addOrUpdateFromImportStatement(file, importPath.removeLastComponent().toString(), target.getName(), null, priority, element); } }