[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
This commit is contained in:
Tagir Valeev
2021-09-30 10:57:33 +00:00
committed by intellij-monorepo-bot
parent c174c74466
commit 849769445d
5 changed files with 10 additions and 22 deletions
@@ -51,18 +51,18 @@ public interface LocalQuickFix extends QuickFix<ProblemDescriptor>, 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;
}
}
@@ -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));
@@ -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()
@@ -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);
}
}
@@ -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;
}