mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SetInspectionOptionFix: apply option to the correct scope (IDEA-188134)
This commit is contained in:
+12
-10
@@ -10,6 +10,7 @@ import com.intellij.openapi.command.undo.UndoManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.ReflectionUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -17,13 +18,13 @@ import org.jetbrains.annotations.NotNull;
|
||||
import javax.swing.*;
|
||||
|
||||
public class SetInspectionOptionFix implements LocalQuickFix, LowPriorityAction, Iconable {
|
||||
private final String myShortName;
|
||||
private final String myID;
|
||||
private final String myProperty;
|
||||
private final String myMessage;
|
||||
private final boolean myValue;
|
||||
|
||||
public SetInspectionOptionFix(InspectionProfileEntry inspection, String property, String message, boolean value) {
|
||||
myShortName = inspection.getShortName();
|
||||
public SetInspectionOptionFix(LocalInspectionTool inspection, String property, String message, boolean value) {
|
||||
myID = inspection.getID();
|
||||
myProperty = property;
|
||||
myMessage = message;
|
||||
myValue = value;
|
||||
@@ -50,24 +51,25 @@ public class SetInspectionOptionFix implements LocalQuickFix, LowPriorityAction,
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
setOption(project, myValue);
|
||||
final VirtualFile vFile = descriptor.getPsiElement().getContainingFile().getVirtualFile();
|
||||
PsiFile file = descriptor.getPsiElement().getContainingFile();
|
||||
setOption(file, myValue);
|
||||
final VirtualFile vFile = file.getVirtualFile();
|
||||
UndoManager.getInstance(project).undoableActionPerformed(new BasicUndoableAction(vFile) {
|
||||
@Override
|
||||
public void undo() {
|
||||
setOption(project, !myValue);
|
||||
setOption(file, !myValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redo() {
|
||||
setOption(project, myValue);
|
||||
setOption(file, myValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setOption(@NotNull Project project, boolean value) {
|
||||
InspectionProfileModifiableModelKt.modifyAndCommitProjectProfile(project, model -> {
|
||||
InspectionToolWrapper tool = model.getInspectionTool(myShortName, project);
|
||||
private void setOption(@NotNull PsiFile file, boolean value) {
|
||||
InspectionProfileModifiableModelKt.modifyAndCommitProjectProfile(file.getProject(), model -> {
|
||||
InspectionToolWrapper tool = model.getToolById(myID, file);
|
||||
if(tool == null) return;
|
||||
InspectionProfileEntry inspection = tool.getTool();
|
||||
ReflectionUtil.setField(inspection.getClass(), inspection, boolean.class, myProperty, value);
|
||||
|
||||
Reference in New Issue
Block a user