diff --git a/python/src/com/jetbrains/python/refactoring/move/PyMoveRefactoringUtil.java b/python/src/com/jetbrains/python/refactoring/move/PyMoveRefactoringUtil.java index 09a10a62deb8..6f5bbb7a08f8 100644 --- a/python/src/com/jetbrains/python/refactoring/move/PyMoveRefactoringUtil.java +++ b/python/src/com/jetbrains/python/refactoring/move/PyMoveRefactoringUtil.java @@ -23,6 +23,7 @@ import com.intellij.psi.util.QualifiedName; import com.intellij.util.IncorrectOperationException; import com.jetbrains.python.PyBundle; import com.jetbrains.python.psi.PyFunction; +import com.jetbrains.python.psi.PyQualifiedNameOwner; import com.jetbrains.python.psi.resolve.QualifiedNameFinder; import com.jetbrains.python.refactoring.classes.PyClassRefactoringUtil; import org.jetbrains.annotations.NotNull; @@ -49,21 +50,31 @@ public class PyMoveRefactoringUtil { } /** - * Returns short name of the element suitable for displaying inside dialogs. Function have parentheses after their name, - * names of another named elements are returned as is. If {@link PsiNamedElement#getName()} returns {@code null} or emtpy string, + * Returns name of the symbol suitable for displaying inside dialogs. + * Functions will have parentheses after their name, names of another named + * elements are returned as is. + *
+ * If it's not possible to get the qualified name of the element, plain + * {@link PsiNamedElement#getName()} will be called instead. + *
+ * If {@link PsiNamedElement#getName()} returns {@code null} or emtpy string, * empty string is returned. * * @param element named PSI element * @return element name as described */ @NotNull - public static String getCompactPresentableName(@NotNull PsiNamedElement element) { - final String name = element.getName(); + public static String getPresentableName(@NotNull PsiNamedElement element) { + String name = null; + if (element instanceof PyQualifiedNameOwner) { + // Will return null for a local function + name = ((PyQualifiedNameOwner)element).getQualifiedName(); + } + if (StringUtil.isEmpty(name)) { + name = element.getName(); + } if (StringUtil.isNotEmpty(name)) { - if (element instanceof PyFunction) { - return name + "()"; - } - return name; + return element instanceof PyFunction ? name + "()" : name; } return ""; } diff --git a/python/src/com/jetbrains/python/refactoring/move/makeFunctionTopLevel/PyMakeFunctionTopLevelDialog.java b/python/src/com/jetbrains/python/refactoring/move/makeFunctionTopLevel/PyMakeFunctionTopLevelDialog.java index 68edd45712b0..61cc2bd40b2f 100644 --- a/python/src/com/jetbrains/python/refactoring/move/makeFunctionTopLevel/PyMakeFunctionTopLevelDialog.java +++ b/python/src/com/jetbrains/python/refactoring/move/makeFunctionTopLevel/PyMakeFunctionTopLevelDialog.java @@ -33,7 +33,7 @@ public class PyMakeFunctionTopLevelDialog extends PyBaseMoveDialog { @NotNull String sourcePath, @NotNull String destinationPath) { super(project, sourcePath, destinationPath); - final String functionName = PyMoveRefactoringUtil.getCompactPresentableName(function); + final String functionName = PyMoveRefactoringUtil.getPresentableName(function); if (function.getContainingClass() != null) { setTitle(PyBundle.message("refactoring.make.method.top.level.dialog.title")); myDescription.setText(PyBundle.message("refactoring.make.method.top.level.dialog.description", functionName)); diff --git a/python/src/com/jetbrains/python/refactoring/move/moduleMembers/PyMoveModuleMembersDialog.java b/python/src/com/jetbrains/python/refactoring/move/moduleMembers/PyMoveModuleMembersDialog.java index 6cbfe865a45a..e994dd2b6e47 100644 --- a/python/src/com/jetbrains/python/refactoring/move/moduleMembers/PyMoveModuleMembersDialog.java +++ b/python/src/com/jetbrains/python/refactoring/move/moduleMembers/PyMoveModuleMembersDialog.java @@ -93,7 +93,7 @@ public class PyMoveModuleMembersDialog extends PyBaseMoveDialog { final boolean tableIsVisible = mySeveralElementsSelected || PropertiesComponent.getInstance().getBoolean(BULK_MOVE_TABLE_VISIBLE); final String description; if (!tableIsVisible && elements.size() == 1) { - final String name = PyMoveRefactoringUtil.getCompactPresentableName(firstElement); + final String name = PyMoveRefactoringUtil.getPresentableName(firstElement); if (firstElement instanceof PyFunction) { description = PyBundle.message("refactoring.move.module.members.dialog.description.function.$0", name); }