PY-21147 Don't use targetContainer param of doMove for destination path
authorMikhail Golubev <mikhail.golubev@jetbrains.com>
Wed, 19 Oct 2016 21:25:41 +0000 (00:25 +0300)
committerMikhail Golubev <mikhail.golubev@jetbrains.com>
Mon, 24 Oct 2016 21:03:49 +0000 (00:03 +0300)
It seems to be specified only when Move refactoring is launched outside
of the editor (according to MoveHandler's implementation) and this
refactoring doesn't support such way to run it anyway

python/src/com/jetbrains/python/refactoring/move/PyMoveSymbolDelegate.java

index cea549b75595937c2664280169f4279fca2685a7..e49d4a4d6f278e4d388951884c7f2438ad80303a 100644 (file)
@@ -79,14 +79,7 @@ public class PyMoveSymbolDelegate extends MoveHandlerDelegate {
 
   @Override
   public void doMove(Project project, PsiElement[] elements, @Nullable PsiElement targetContainer, @Nullable MoveCallback callback) {
-    String initialPath = null;
-    if (targetContainer instanceof PsiFile) {
-      initialPath = StringUtil.notNullize(PyPsiUtils.getContainingFilePath(targetContainer));
-    }
-    if (initialPath == null) {
-      initialPath = StringUtil.notNullize(PyPsiUtils.getContainingFilePath(elements[0]));
-    }
-    
+    final String initialPath = StringUtil.notNullize(PyPsiUtils.getContainingFilePath(elements[0]));
     final BaseRefactoringProcessor processor;
     if (isMovableLocalFunctionOrMethod(elements[0])) {
       final PyFunction function = (PyFunction)elements[0];
@@ -137,27 +130,23 @@ public class PyMoveSymbolDelegate extends MoveHandlerDelegate {
                            @Nullable DataContext dataContext,
                            @Nullable PsiReference reference,
                            @Nullable Editor editor) {
-    PsiFile targetContainer = null;
-    if (editor != null) {
-      final Document document = editor.getDocument();
-      targetContainer = PsiDocumentManager.getInstance(project).getPsiFile(document);
-      if (targetContainer instanceof PyFile && selectionSpansMultipleLines(editor)) {
-        final List<PyElement> moduleMembers = collectAllMovableElementsInSelection(editor, (PyFile)targetContainer);
-        if (moduleMembers.isEmpty()) {
-          showBadSelectionErrorHint(project, editor);
-        }
-        else {
-          doMove(project, ContainerUtil.findAllAsArray(moduleMembers, PsiNamedElement.class), targetContainer, null);
-        }
-        return true;
+    final PsiFile currentFile = element.getContainingFile();
+    if (editor != null && currentFile instanceof PyFile && selectionSpansMultipleLines(editor)) {
+      final List<PyElement> moduleMembers = collectAllMovableElementsInSelection(editor, (PyFile)currentFile);
+      if (moduleMembers.isEmpty()) {
+        showBadSelectionErrorHint(project, editor);
+      }
+      else {
+        doMove(project, ContainerUtil.findAllAsArray(moduleMembers, PsiNamedElement.class), null, null);
       }
+      return true;
     }
 
     // Fallback to the old way to select single element to move
     final PsiNamedElement e = PyMoveModuleMembersHelper.extractNamedElement(element);
     if (e != null && PyMoveModuleMembersHelper.hasMovableElementType(e)) {
       if (PyMoveModuleMembersHelper.isMovableModuleMember(e) || isMovableLocalFunctionOrMethod(e)) {
-        doMove(project, new PsiElement[]{e}, targetContainer, null);
+        doMove(project, new PsiElement[]{e}, null, null);
       }
       else {
         showBadSelectionErrorHint(project, editor);