void (@NotNull PsiNamedElement targetElement, @NotNull PyQualifiedExpression expression) { final PyElementGenerator generator = PyElementGenerator.getInstance(expression.getProject()); final PsiFile srcFile = targetElement.getContainingFile(); final LanguageLevel languageLevel = LanguageLevel.forElement(expression); if (srcFile != expression.getContainingFile()) { final QualifiedName qualifier = QualifiedNameFinder.findCanonicalImportPath(srcFile, expression); PyPsiRefactoringUtil.insertImport(expression, srcFile, null, false); final String newQualifiedReference = qualifier + "." + expression.getReferencedName(); expression.replace(generator.createExpressionFromText(languageLevel, newQualifiedReference)); } else { expression.replace(generator.createExpressionFromText(languageLevel, expression.getReferencedName())); } }