diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/ConvertFormatOperatorToMethodIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/ConvertFormatOperatorToMethodIntention.java index c419f521048f..f17eb83d68d0 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/ConvertFormatOperatorToMethodIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/ConvertFormatOperatorToMethodIntention.java @@ -202,6 +202,10 @@ public class ConvertFormatOperatorToMethodIntention extends BaseIntentionAction } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PyBinaryExpression binaryExpression = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyBinaryExpression.class, false); if (binaryExpression == null) { diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/ConvertVariadicParamIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/ConvertVariadicParamIntention.java index 5a635aa57fef..436bdaf46c34 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/ConvertVariadicParamIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/ConvertVariadicParamIntention.java @@ -44,6 +44,10 @@ public class ConvertVariadicParamIntention extends BaseIntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PyFunction function = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyFunction.class); if (function != null) { diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/ImportFromToImportIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/ImportFromToImportIntention.java index bb881905c74b..509513ff32cc 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/ImportFromToImportIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/ImportFromToImportIntention.java @@ -128,6 +128,10 @@ public class ImportFromToImportIntention implements IntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + InfoHolder info = InfoHolder.collect(getElementFromEditor(editor, file)); info.myModuleReference = null; final PsiElement position = file.findElementAt(editor.getCaretModel().getOffset()); diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/ImportToImportFromIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/ImportToImportFromIntention.java index 7a7767b6d8b8..ffaabaa1fd2f 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/ImportToImportFromIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/ImportToImportFromIntention.java @@ -214,6 +214,10 @@ public class ImportToImportFromIntention implements IntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + IntentionState state = new IntentionState(editor, file); if (state.isAvailable()) { myText = state.getText(); diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/ImportToggleAliasIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/ImportToggleAliasIntention.java index 166206f6451b..335c37178a62 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/ImportToggleAliasIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/ImportToggleAliasIntention.java @@ -103,6 +103,10 @@ public class ImportToggleAliasIntention implements IntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + IntentionState state = IntentionState.fromContext(editor, file); myLastText = state.getText(); return state.isAvailable(); diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertLambdaToFunctionIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertLambdaToFunctionIntention.java index 462b4d723f37..e9fe4b870465 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertLambdaToFunctionIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertLambdaToFunctionIntention.java @@ -40,6 +40,10 @@ public class PyConvertLambdaToFunctionIntention extends BaseIntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PyLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyLambdaExpression.class); if (lambdaExpression != null) { if (lambdaExpression.getBody() != null) { diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertTripleQuotedStringIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertTripleQuotedStringIntention.java index a84d19f71dd7..dd420026e520 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertTripleQuotedStringIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertTripleQuotedStringIntention.java @@ -42,6 +42,10 @@ public class PyConvertTripleQuotedStringIntention extends BaseIntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PyStringLiteralExpression string = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyStringLiteralExpression.class); if (string != null) { final PyDocStringOwner docStringOwner = PsiTreeUtil.getParentOfType(string, PyDocStringOwner.class); diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyDemorganIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyDemorganIntention.java index 64271ef3366f..4becd23721ce 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyDemorganIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyDemorganIntention.java @@ -30,6 +30,10 @@ public class PyDemorganIntention extends BaseIntentionAction { @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PyBinaryExpression expression = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyBinaryExpression.class); if (expression != null) { PyElementType op = expression.getOperator(); diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyDictConstructorToLiteralFormIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyDictConstructorToLiteralFormIntention.java index 34634a3e03f3..c25580b1fd8d 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyDictConstructorToLiteralFormIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyDictConstructorToLiteralFormIntention.java @@ -33,6 +33,10 @@ public class PyDictConstructorToLiteralFormIntention extends BaseIntentionAction } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PyCallExpression expression = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyCallExpression.class); diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyDictLiteralFormToConstructorIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyDictLiteralFormToConstructorIntention.java index a87ed6eb6c21..2a36bc9ca5da 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyDictLiteralFormToConstructorIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyDictLiteralFormToConstructorIntention.java @@ -33,6 +33,9 @@ public class PyDictLiteralFormToConstructorIntention extends BaseIntentionAction } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } PyDictLiteralExpression dictExpression = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyDictLiteralExpression.class); diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyFlipComparisonIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyFlipComparisonIntention.java index 3e6be16fd645..84ec2d5b0b6e 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyFlipComparisonIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyFlipComparisonIntention.java @@ -13,6 +13,7 @@ import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.psi.PyBinaryExpression; import com.jetbrains.python.psi.PyElementGenerator; import com.jetbrains.python.psi.PyElementType; +import com.jetbrains.python.psi.PyFile; import org.jetbrains.annotations.NotNull; import java.util.Map; @@ -42,6 +43,10 @@ public class PyFlipComparisonIntention extends BaseIntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); PyBinaryExpression binaryExpression = PsiTreeUtil.getParentOfType(element, PyBinaryExpression.class, false); while (binaryExpression != null) { diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyGenerateDocstringIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyGenerateDocstringIntention.java index 1f53df064d86..1940d7cc233c 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyGenerateDocstringIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyGenerateDocstringIntention.java @@ -13,6 +13,7 @@ import com.jetbrains.python.debugger.PySignature; import com.jetbrains.python.debugger.PySignatureCacheManager; import com.jetbrains.python.documentation.PyDocstringGenerator; import com.jetbrains.python.documentation.doctest.PyDocstringFile; +import com.jetbrains.python.psi.PyFile; import com.jetbrains.python.psi.PyFunction; import com.jetbrains.python.psi.PyUtil; import org.jetbrains.annotations.NotNull; @@ -37,7 +38,7 @@ public class PyGenerateDocstringIntention extends BaseIntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { - if (file instanceof PyDocstringFile) return false; + if (!(file instanceof PyFile) || file instanceof PyDocstringFile) return false; PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset()); if (elementAt == null) { return false; diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyJoinIfIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyJoinIfIntention.java index 3ee654506755..7421520190d3 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyJoinIfIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyJoinIfIntention.java @@ -39,6 +39,10 @@ public class PyJoinIfIntention extends BaseIntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PyIfStatement expression = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyIfStatement.class); diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyNegateComparisonIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyNegateComparisonIntention.java index 788915d1be38..cedf015dc498 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyNegateComparisonIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyNegateComparisonIntention.java @@ -49,6 +49,9 @@ public class PyNegateComparisonIntention extends BaseIntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); PyBinaryExpression binaryExpression = PsiTreeUtil.getParentOfType(element, PyBinaryExpression.class, false); diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java index c73e3216038b..95cf10332609 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java @@ -9,6 +9,7 @@ import com.intellij.util.IncorrectOperationException; import com.jetbrains.python.PyBundle; import com.jetbrains.python.psi.PyDocStringOwner; import com.jetbrains.python.psi.PyElementGenerator; +import com.jetbrains.python.psi.PyFile; import com.jetbrains.python.psi.PyStringLiteralExpression; import com.jetbrains.python.psi.impl.PyStringLiteralExpressionImpl; import org.jetbrains.annotations.NotNull; @@ -25,6 +26,10 @@ public class PyQuotedStringIntention extends BaseIntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PyStringLiteralExpression string = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyStringLiteralExpression.class); if (string != null) { final PyDocStringOwner docStringOwner = PsiTreeUtil.getParentOfType(string, PyDocStringOwner.class); diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PySplitIfIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PySplitIfIntention.java index aaf3254e7379..20a77cb070de 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PySplitIfIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PySplitIfIntention.java @@ -26,6 +26,10 @@ public class PySplitIfIntention extends BaseIntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PsiElement elementAtOffset = file.findElementAt(editor.getCaretModel().getOffset()); if (elementAtOffset == null || elementAtOffset.getNode() == null) { return false; diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyStringConcatenationToFormatIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyStringConcatenationToFormatIntention.java index 690207bcb9f5..aadbaa1897ef 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyStringConcatenationToFormatIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyStringConcatenationToFormatIntention.java @@ -35,6 +35,10 @@ public class PyStringConcatenationToFormatIntention extends BaseIntentionAction } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PsiElement element = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyBinaryExpression.class, false); if (element == null) { diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyTransformConditionalExpressionIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyTransformConditionalExpressionIntention.java index 93e770441e5d..e98eb03c316b 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyTransformConditionalExpressionIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyTransformConditionalExpressionIntention.java @@ -36,6 +36,10 @@ public class PyTransformConditionalExpressionIntention extends BaseIntentionActi } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PyAssignmentStatement expression = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyAssignmentStatement.class); if (expression != null && expression.getAssignedValue() instanceof PyConditionalExpression) { diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/ReplaceListComprehensionWithForIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/ReplaceListComprehensionWithForIntention.java index 6154b79bca44..9beb2a40fe39 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/ReplaceListComprehensionWithForIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/ReplaceListComprehensionWithForIntention.java @@ -29,6 +29,10 @@ public class ReplaceListComprehensionWithForIntention implements IntentionAction } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PyListCompExpression expression = PsiTreeUtil.getTopmostParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyListCompExpression.class); if (expression == null) { diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/TypeAssertionIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/TypeAssertionIntention.java index 1dc1d8ca8309..e3cea61295bd 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/TypeAssertionIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/TypeAssertionIntention.java @@ -41,6 +41,10 @@ public class TypeAssertionIntention implements IntentionAction { } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof PyFile)) { + return false; + } + PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset()); PyExpression problemElement = PsiTreeUtil.getParentOfType(elementAt, PyReferenceExpression.class); if (problemElement == null) return false; diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/TypeIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/TypeIntention.java index 5777e44ee12e..37c309997b4d 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/TypeIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/TypeIntention.java @@ -24,7 +24,7 @@ import org.jetbrains.annotations.Nullable; public abstract class TypeIntention implements IntentionAction { public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { - if (file instanceof PyDocstringFile) return false; + if (!(file instanceof PyFile) || file instanceof PyDocstringFile) return false; updateText(false); final PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());