From a2a7ed72e34da1858fa1b6d5ea4746b340fec948 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 28 Feb 2013 11:40:10 +0100 Subject: [PATCH] nicer API for plugins to modify inspection tool settings --- .../python/inspections/PyPep8Inspection.java | 2 ++ .../PyUnresolvedReferencesInspection.java | 6 ++---- .../quickfix/AddIgnoredIdentifierQuickFix.java | 8 +++----- .../python/validation/Pep8ExternalAnnotator.java | 13 +++++-------- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/python/src/com/jetbrains/python/inspections/PyPep8Inspection.java b/python/src/com/jetbrains/python/inspections/PyPep8Inspection.java index 6c105eac2966..d1887a7ac492 100644 --- a/python/src/com/jetbrains/python/inspections/PyPep8Inspection.java +++ b/python/src/com/jetbrains/python/inspections/PyPep8Inspection.java @@ -1,6 +1,7 @@ package com.jetbrains.python.inspections; import com.intellij.codeInspection.ui.ListEditForm; +import com.intellij.openapi.util.Key; import javax.swing.*; import java.util.ArrayList; @@ -15,6 +16,7 @@ import java.util.List; public class PyPep8Inspection extends PyInspection { public List ignoredErrors = new ArrayList(); public static final String INSPECTION_SHORT_NAME = "PyPep8Inspection"; + public static final Key KEY = Key.create(INSPECTION_SHORT_NAME); @Override public JComponent createOptionsPanel() { diff --git a/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java b/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java index 4fd8a4318a83..f6da89696114 100644 --- a/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java @@ -2,7 +2,6 @@ package com.jetbrains.python.inspections; import com.google.common.collect.ImmutableSet; import com.intellij.codeInspection.*; -import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; import com.intellij.codeInspection.ui.ListEditForm; import com.intellij.lang.ASTNode; import com.intellij.lang.annotation.HighlightSeverity; @@ -65,14 +64,13 @@ import static com.jetbrains.python.inspections.quickfix.AddIgnoredIdentifierQuic */ public class PyUnresolvedReferencesInspection extends PyInspection { private static Key KEY = Key.create("PyUnresolvedReferencesInspection.Visitor"); + public static final Key SHORT_NAME_KEY = Key.create(PyUnresolvedReferencesInspection.class.getSimpleName()); public JDOMExternalizableStringList ignoredIdentifiers = new JDOMExternalizableStringList(); public static PyUnresolvedReferencesInspection getInstance(PsiElement element) { final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile(); - final LocalInspectionToolWrapper profileEntry = - (LocalInspectionToolWrapper)inspectionProfile.getInspectionTool(PyUnresolvedReferencesInspection.class.getSimpleName(), element); - return (PyUnresolvedReferencesInspection)profileEntry.getTool(); + return inspectionProfile.getUnwrappedTool(SHORT_NAME_KEY, element); } @Nls diff --git a/python/src/com/jetbrains/python/inspections/quickfix/AddIgnoredIdentifierQuickFix.java b/python/src/com/jetbrains/python/inspections/quickfix/AddIgnoredIdentifierQuickFix.java index 3ae2e3c076aa..9a3e081e3dd9 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/AddIgnoredIdentifierQuickFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/AddIgnoredIdentifierQuickFix.java @@ -44,12 +44,10 @@ public class AddIgnoredIdentifierQuickFix implements LocalQuickFix, LowPriorityA @Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiElement context = descriptor.getPsiElement(); - InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile(context); - profile.modifyProfile(new Consumer() { + InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile(); + profile.modifyToolSettings(PyUnresolvedReferencesInspection.SHORT_NAME_KEY, context, new Consumer() { @Override - public void consume(ModifiableModel model) { - PyUnresolvedReferencesInspection inspection = - (PyUnresolvedReferencesInspection)model.getUnwrappedTool(PyUnresolvedReferencesInspection.class.getSimpleName(), context); + public void consume(PyUnresolvedReferencesInspection inspection) { String name = myIdentifier.toString(); if (myIgnoreAllAttributes) { name += END_WILDCARD; diff --git a/python/src/com/jetbrains/python/validation/Pep8ExternalAnnotator.java b/python/src/com/jetbrains/python/validation/Pep8ExternalAnnotator.java index 65dfb6ff6769..40ce37a5ab2b 100644 --- a/python/src/com/jetbrains/python/validation/Pep8ExternalAnnotator.java +++ b/python/src/com/jetbrains/python/validation/Pep8ExternalAnnotator.java @@ -4,9 +4,7 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel; import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.InspectionProfile; -import com.intellij.codeInspection.ModifiableModel; import com.intellij.codeInspection.ex.CustomEditInspectionToolsSettingsAction; -import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; import com.intellij.execution.process.ProcessOutput; import com.intellij.lang.annotation.Annotation; import com.intellij.lang.annotation.AnnotationHolder; @@ -101,9 +99,8 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator ignoredErrors = ((PyPep8Inspection)profileEntry.getTool()).ignoredErrors; + final PyPep8Inspection inspection = profile.getUnwrappedTool(PyPep8Inspection.KEY, file); + final List ignoredErrors = inspection.ignoredErrors; final int margin = CodeStyleSettingsManager.getInstance(file.getProject()).getCurrentSettings().RIGHT_MARGIN; return new State(homePath, file.getText(), profile.getErrorLevel(key, file), ignoredErrors, margin); } @@ -236,10 +233,10 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator() { + InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile(); + profile.modifyToolSettings(PyPep8Inspection.KEY, file, new Consumer() { @Override - public void consume(ModifiableModel model) { - PyPep8Inspection tool = (PyPep8Inspection)model.getUnwrappedTool(PyPep8Inspection.INSPECTION_SHORT_NAME, file); + public void consume(PyPep8Inspection tool) { tool.ignoredErrors.add(myCode); } });