From 849769445d6e8519f9cf5aa4bead91e3de493034 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Thu, 30 Sep 2021 12:01:19 +0700 Subject: [PATCH] [intention-preview] Fixes according to review IJ-CR-14677 1. Use LOG.error on fallback path to gather reports 2. Rename parameter to previewDescriptor 3. DelegatingFix.applyFixForPreview 4. Remove QuickFixWrapper.getFileModifierForPreview (unnecessary when invokeForPreview is implemented) GitOrigin-RevId: d5b4c5af510563d47d98c67c26f940e3cd3058bf --- .../src/com/intellij/codeInspection/LocalQuickFix.java | 8 ++++---- .../intellij/codeInspection/ex/QuickFixWrapper.java | 8 -------- .../impl/preview/IntentionPreviewComputable.kt | 2 +- .../src/com/siyeh/ig/DelegatingFix.java | 10 +++------- .../com/siyeh/ig/fixes/ConvertToVarargsMethodFix.java | 4 ++-- 5 files changed, 10 insertions(+), 22 deletions(-) diff --git a/platform/analysis-api/src/com/intellij/codeInspection/LocalQuickFix.java b/platform/analysis-api/src/com/intellij/codeInspection/LocalQuickFix.java index 2dc406752297..162b2e9296aa 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/LocalQuickFix.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/LocalQuickFix.java @@ -51,18 +51,18 @@ public interface LocalQuickFix extends QuickFix, FileModifier * overriding {@code getFileModifierForPreview} or {@code applyFixForPreview} is desired. * * @param project current project - * @param descriptor problem descriptor which refers to the non-physical file copy where the fix should be applied + * @param previewDescriptor problem descriptor which refers to the non-physical file copy where the fix should be applied * @return true if the fix was successfully applied to the copy; false otherwise */ - default boolean applyFixForPreview(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { + default boolean applyFixForPreview(@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) { if (!startInWriteAction()) return false; - PsiElement element = descriptor.getStartElement(); + PsiElement element = previewDescriptor.getStartElement(); if (element == null) return false; PsiFile file = element.getContainingFile(); if (getElementToMakeWritable(file) != file) return false; LocalQuickFix fix = ObjectUtils.tryCast(getFileModifierForPreview(file), LocalQuickFix.class); if (fix == null) return false; - fix.applyFix(project, descriptor); + fix.applyFix(project, previewDescriptor); return true; } } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java index 86210ab07575..5d4b68b933af 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java @@ -115,14 +115,6 @@ public final class QuickFixWrapper implements IntentionAction, PriorityAction { return getText(); } - @Override - public @Nullable IntentionAction getFileModifierForPreview(@NotNull PsiFile target) { - LocalQuickFix result = ObjectUtils.tryCast(myFix.getFileModifierForPreview(target), LocalQuickFix.class); - if (result == null) return null; - ProblemDescriptor descriptor = myDescriptor.getDescriptorForPreview(target); - return new QuickFixWrapper(descriptor, result); - } - @Override public boolean invokeForPreview(@NotNull Project project, Editor editor, PsiFile file) { return myFix.applyFixForPreview(project, myDescriptor.getDescriptorForPreview(file)); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/preview/IntentionPreviewComputable.kt b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/preview/IntentionPreviewComputable.kt index c68fbb5f177a..e6f76157b465 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/preview/IntentionPreviewComputable.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/preview/IntentionPreviewComputable.kt @@ -96,7 +96,7 @@ internal class IntentionPreviewComputable(private val project: Project, return null } val action = findCopyIntention(project, editorCopy, psiFileCopy, action) ?: return null - LOG.warn("Intention preview fallback is used for action " + action::class.java + "|" + action.familyName) + LOG.error("Intention preview fallback is used for action " + action::class.java + "|" + action.familyName) action.invoke(project, editorCopy, psiFileCopy) } ProgressManager.checkCanceled() diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/DelegatingFix.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/DelegatingFix.java index 87063febd342..77d14213419b 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/DelegatingFix.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/DelegatingFix.java @@ -58,12 +58,8 @@ public class DelegatingFix extends InspectionGadgetsFix implements Iconable, Pri } @Override - public @Nullable LocalQuickFix getFileModifierForPreview(@NotNull PsiFile target) { - LocalQuickFix fix = ObjectUtils.tryCast(delegate.getFileModifierForPreview(target), LocalQuickFix.class); - if (fix == null) return null; - if (fix == delegate) return this; - DelegatingFix newFix = new DelegatingFix(fix); - newFix.setOnTheFly(isOnTheFly()); - return newFix; + public boolean applyFixForPreview(@NotNull Project project, + @NotNull ProblemDescriptor previewDescriptor) { + return delegate.applyFixForPreview(project, previewDescriptor); } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/ConvertToVarargsMethodFix.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/ConvertToVarargsMethodFix.java index 4e7081c5bf2b..dc8595f84534 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/ConvertToVarargsMethodFix.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/ConvertToVarargsMethodFix.java @@ -112,8 +112,8 @@ public class ConvertToVarargsMethodFix extends InspectionGadgetsFix { @Override public boolean applyFixForPreview(@NotNull Project project, - @NotNull ProblemDescriptor descriptor) { - final PsiElement element = descriptor.getPsiElement(); + @NotNull ProblemDescriptor previewDescriptor) { + final PsiElement element = previewDescriptor.getPsiElement(); if (!(element instanceof PsiMethod)) { return false; }