PY-17265 Show qualified names of symbols in move dialogs if possible

This commit is contained in:
Mikhail Golubev
2016-10-25 00:03:49 +03:00
parent ba23c01e00
commit 4ccbf4b236
3 changed files with 21 additions and 10 deletions
@@ -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.
* <p>
* If it's not possible to get the qualified name of the element, plain
* {@link PsiNamedElement#getName()} will be called instead.
* <p>
* 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 "";
}
@@ -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));
@@ -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);
}