PsiElement (@NotNull PsiElement oldElement, @Nullable QualifiedName newElementName) { if (newElementName != null && PyPsiRefactoringUtil.isValidQualifiedName(newElementName)) { final PyElementGenerator generator = PyElementGenerator.getInstance(oldElement.getProject()); final PsiElement newElement = generator.createExpressionFromText(LanguageLevel.forElement(oldElement), newElementName.toString()); return oldElement.replace(newElement); } return oldElement; }