From e43654efe17e6bf0e3024141f4f9062166f96965 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 8 Aug 2011 14:28:00 +0200 Subject: [PATCH] allow suppressing PyCharm inspections from toolwindow (PY-2103) --- .../python/inspections/PyInspection.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/python/src/com/jetbrains/python/inspections/PyInspection.java b/python/src/com/jetbrains/python/inspections/PyInspection.java index 0facd4e49a08..0e92d789d9fa 100644 --- a/python/src/com/jetbrains/python/inspections/PyInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyInspection.java @@ -44,20 +44,20 @@ public abstract class PyInspection extends LocalInspectionTool implements Custom } @Override - public SuppressIntentionAction[] getSuppressActions(@Nullable PsiElement element) { + public SuppressIntentionAction[] getSuppressActions(@Nullable final PsiElement element) { List result = new ArrayList(); - if (element != null) { - if (PsiTreeUtil.getParentOfType(element, PyStatementList.class, false, ScopeOwner.class) != null || - PsiTreeUtil.getParentOfType(element, PyFunction.class, PyClass.class) == null) { - result.add(new PySuppressInspectionFix(getSuppressId(), "Suppress for statement", PyStatement.class)); + result.add(new PySuppressInspectionFix(getSuppressId(), "Suppress for statement", PyStatement.class) { + @Override + protected PsiElement getContainer(PsiElement context) { + if (PsiTreeUtil.getParentOfType(context, PyStatementList.class, false, ScopeOwner.class) != null || + PsiTreeUtil.getParentOfType(context, PyFunction.class, PyClass.class) == null) { + return super.getContainer(context); + } + return null; } - if (PsiTreeUtil.getParentOfType(element, PyFunction.class) != null) { - result.add(new PySuppressInspectionFix(getSuppressId(), "Suppress for function", PyFunction.class)); - } - if (PsiTreeUtil.getParentOfType(element, PyClass.class) != null) { - result.add(new PySuppressInspectionFix(getSuppressId(), "Suppress for class", PyClass.class)); - } - } + }); + result.add(new PySuppressInspectionFix(getSuppressId(), "Suppress for function", PyFunction.class)); + result.add(new PySuppressInspectionFix(getSuppressId(), "Suppress for class", PyClass.class)); return result.toArray(new SuppressIntentionAction[result.size()]); }