mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
nicer API for plugins to modify inspection tool settings
This commit is contained in:
@@ -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<String> ignoredErrors = new ArrayList<String>();
|
||||
public static final String INSPECTION_SHORT_NAME = "PyPep8Inspection";
|
||||
public static final Key<PyPep8Inspection> KEY = Key.create(INSPECTION_SHORT_NAME);
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
|
||||
@@ -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<Visitor> KEY = Key.create("PyUnresolvedReferencesInspection.Visitor");
|
||||
public static final Key<PyUnresolvedReferencesInspection> 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
|
||||
|
||||
+3
-5
@@ -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<ModifiableModel>() {
|
||||
InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
|
||||
profile.modifyToolSettings(PyUnresolvedReferencesInspection.SHORT_NAME_KEY, context, new Consumer<PyUnresolvedReferencesInspection>() {
|
||||
@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;
|
||||
|
||||
@@ -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<Pep8ExternalAnnotat
|
||||
if (!profile.isToolEnabled(key)) {
|
||||
return null;
|
||||
}
|
||||
final LocalInspectionToolWrapper profileEntry = (LocalInspectionToolWrapper)profile.getInspectionTool(
|
||||
PyPep8Inspection.INSPECTION_SHORT_NAME, file);
|
||||
final List<String> ignoredErrors = ((PyPep8Inspection)profileEntry.getTool()).ignoredErrors;
|
||||
final PyPep8Inspection inspection = profile.getUnwrappedTool(PyPep8Inspection.KEY, file);
|
||||
final List<String> 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<Pep8ExternalAnnotat
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, final PsiFile file) throws IncorrectOperationException {
|
||||
InspectionProjectProfileManager.getInstance(project).getInspectionProfile(file).modifyProfile(new Consumer<ModifiableModel>() {
|
||||
InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
|
||||
profile.modifyToolSettings(PyPep8Inspection.KEY, file, new Consumer<PyPep8Inspection>() {
|
||||
@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);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user