diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/ImportToggleAliasIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/ImportToggleAliasIntention.java index f9f1ee19435a..6b79d2104f44 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/ImportToggleAliasIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/ImportToggleAliasIntention.java @@ -181,13 +181,16 @@ public class ImportToggleAliasIntention implements IntentionAction { InjectedLanguageManager.getInstance(project).getInjectedPsiFiles(host); if (files != null) { for (Pair pair : files) { - final ScopeOwner scopeOwner = (ScopeOwner)pair.getFirst(); - PsiTreeUtil.processElements(scopeOwner, new PsiElementProcessor() { - public boolean execute(@NotNull PsiElement element) { - getReferences(element); - return true; - } - }); + final PsiElement first = pair.getFirst(); + if (first instanceof ScopeOwner) { + final ScopeOwner scopeOwner = (ScopeOwner)first; + PsiTreeUtil.processElements(scopeOwner, new PsiElementProcessor() { + public boolean execute(@NotNull PsiElement element) { + getReferences(element); + return true; + } + }); + } } } } diff --git a/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java b/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java index 40908da4b5c0..c224801cd1fb 100644 --- a/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java +++ b/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java @@ -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 elementsRange, @NotNull PsiElement callElement) {