diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java index 65a45e901a71..17ad3309791a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.codeInsight.intention.impl.config; import com.intellij.codeInsight.CodeInsightWorkspaceSettings; @@ -19,6 +19,7 @@ import com.intellij.codeInsight.intention.AbstractIntentionAction; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInsight.intention.QuickFixFactory; import com.intellij.codeInsight.intention.impl.*; +import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo; import com.intellij.codeInspection.*; import com.intellij.codeInspection.actions.UnimplementInterfaceAction; import com.intellij.codeInspection.dataFlow.fix.DeleteSwitchLabelFix; @@ -729,30 +730,34 @@ public final class QuickFixFactoryImpl extends QuickFixFactory { @Override public @NotNull IntentionAction createSafeDeleteUnusedParameterInHierarchyFix(@NotNull PsiParameter parameter, boolean excludingHierarchy) { - IntentionAction intentionAction; if (excludingHierarchy) { - intentionAction = new AbstractIntentionAction() { + final SetInspectionOptionFix myFix = + SetInspectionOptionFix.createFix(UnusedSymbolLocalInspectionBase.SHORT_NAME, + "myCheckParameterExcludingHierarchy", + JavaErrorBundle.message("parameter.excluding.hierarchy.disable.text"), false, + profileEntry -> profileEntry instanceof UnusedDeclarationInspectionBase + ? ((UnusedDeclarationInspectionBase)profileEntry).getSharedLocalInspectionTool() + : profileEntry); + return new AbstractIntentionAction() { @Override public @NotNull String getText() { return JavaErrorBundle.message("parameter.excluding.hierarchy.disable.text"); } @Override - public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { - SetInspectionOptionFix.createFix(UnusedSymbolLocalInspectionBase.SHORT_NAME, - "myCheckParameterExcludingHierarchy", - JavaErrorBundle.message("parameter.excluding.hierarchy.disable.text"), false, - profileEntry -> profileEntry instanceof UnusedDeclarationInspectionBase - ? ((UnusedDeclarationInspectionBase)profileEntry).getSharedLocalInspectionTool() - : profileEntry) - .applyFix(project, file); + public void invoke(@NotNull Project project, Editor editor, PsiFile file) { + myFix.applyFix(project, file); + } + + @Override + public @NotNull IntentionPreviewInfo generatePreview(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { + return myFix.generatePreview(project, file, "members."); } }; } else { - intentionAction = new SafeDeleteFix(parameter); + return new SafeDeleteFix(parameter); } - return intentionAction; } @NotNull diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/SetInspectionOptionFix.java b/platform/analysis-impl/src/com/intellij/codeInspection/SetInspectionOptionFix.java index d24d17c14bc8..a7e9f5b3dc81 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/SetInspectionOptionFix.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/SetInspectionOptionFix.java @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.codeInspection; import com.intellij.analysis.AnalysisBundle; @@ -18,6 +18,7 @@ import com.intellij.openapi.util.text.HtmlBuilder; import com.intellij.openapi.util.text.HtmlChunk; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.profile.codeInspection.InspectionProfileManager; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.util.ObjectUtils; @@ -98,11 +99,17 @@ public class SetInspectionOptionFix implements OnTheFlyLocalFix, LowPriorityActi @Override public @NotNull IntentionPreviewInfo generatePreview(@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) { + PsiElement element = previewDescriptor.getPsiElement(); + return generatePreview(project, element, ""); + } + + @NotNull + public IntentionPreviewInfo generatePreview(@NotNull Project project, PsiElement element, String prefix) { InspectionToolWrapper tool = - InspectionProfileManager.getInstance(project).getCurrentProfile().getInspectionTool(myShortName, previewDescriptor.getPsiElement()); + InspectionProfileManager.getInstance(project).getCurrentProfile().getInspectionTool(myShortName, element); if (tool == null) return IntentionPreviewInfo.EMPTY; OptPane pane = tool.getTool().getOptionsPane(); - OptCheckbox control = ObjectUtils.tryCast(pane.findControl(myProperty), OptCheckbox.class); + OptCheckbox control = ObjectUtils.tryCast(pane.findControl(prefix + myProperty), OptCheckbox.class); if (control == null) return IntentionPreviewInfo.EMPTY; HtmlChunk label = HtmlChunk.text(control.label().label()); HtmlChunk.Element checkbox = HtmlChunk.tag("input").attr("type", "checkbox").attr("readonly", "true");