boolean (@NotNull PyImportStatementBase importStatement, @NotNull PsiNamedElement element) { final String name = PyPsiRefactoringUtil.getOriginalName(element); if (name != null) { PyImportElement importElement = null; for (PyImportElement e : importStatement.getImportElements()) { if (name.equals(PyPsiRefactoringUtil.getOriginalName(e))) { importElement = e; } } if (importElement != null) { final PsiFile file = importStatement.getContainingFile(); final PsiFile newFile = element.getContainingFile(); if (newFile == file || PyPsiRefactoringUtil.insertImport(importStatement, element, importElement.getAsName(), true)) { if (importStatement.getImportElements().length == 1) { final boolean isInjected = InjectedLanguageManager.getInstance(importElement.getProject()).isInjectedFragment(importElement.getContainingFile()); if (!isInjected) { importStatement.delete(); } else { deleteImportStatementFromInjected(importStatement); } } else { importElement.delete(); } return true; } } } return false; }