fixed EA-53046 - NPE: PyExtractMethodUtil.a
authorEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Mon, 13 Jan 2014 09:27:49 +0000 (13:27 +0400)
committerEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Mon, 13 Jan 2014 09:27:49 +0000 (13:27 +0400)
python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java

index 40908da4b5c0da08af3776ae49365b969f540a5b..c224801cd1fb8e27fbafd7a4a36208b51cdd8d16 100644 (file)
@@ -40,7 +40,10 @@ import com.intellij.util.Consumer;
 import com.intellij.util.Function;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.containers.hash.HashMap;
-import com.jetbrains.python.*;
+import com.jetbrains.python.PyBundle;
+import com.jetbrains.python.PyNames;
+import com.jetbrains.python.PythonFileType;
+import com.jetbrains.python.PythonLanguage;
 import com.jetbrains.python.codeInsight.codeFragment.PyCodeFragment;
 import com.jetbrains.python.codeInsight.controlflow.ControlFlowCache;
 import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
@@ -332,9 +335,12 @@ public class PyExtractMethodUtil {
     }
   }
 
-  private static void setSelectionAndCaret(Editor editor, final PsiElement callElement) {
+  private static void setSelectionAndCaret(Editor editor, @Nullable final PsiElement callElement) {
     editor.getSelectionModel().removeSelection();
-    editor.getCaretModel().moveToOffset(callElement.getTextOffset());
+    if (callElement != null) {
+      final int offset = callElement.getTextOffset();
+      editor.getCaretModel().moveToOffset(offset);
+    }
   }
 
   private static PsiElement replaceElements(final List<PsiElement> elementsRange, @NotNull PsiElement callElement) {