mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
[java-intentions] A simple generic rename mod-command based intention; used in createRenameFix to avoid creating a descriptor.
GitOrigin-RevId: ac583b578e486be3a679fc22f373a53b5fdfe596
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9d303e0f9a
commit
165421c59d
@@ -233,6 +233,10 @@ public abstract class QuickFixFactory {
|
||||
@NotNull
|
||||
public abstract IntentionAction createRenameFileFix(@NotNull String newName);
|
||||
|
||||
/**
|
||||
* @param element element to rename (either {@link PsiNameIdentifierOwner} or its child)
|
||||
* @return fix that ivokes the rename refactoring on an element; null if element is not suitable for rename
|
||||
*/
|
||||
@Nullable
|
||||
public abstract IntentionAction createRenameFix(@NotNull PsiElement element);
|
||||
|
||||
|
||||
@@ -412,17 +412,12 @@ public final class QuickFixFactoryImpl extends QuickFixFactory {
|
||||
public IntentionAction createRenameFix(@NotNull PsiElement element) {
|
||||
PsiFile file = element.getContainingFile();
|
||||
if (file == null) return null;
|
||||
if(!element.isPhysical()) return null;
|
||||
ProblemDescriptor descriptor = new ProblemDescriptorBase(element,
|
||||
element,
|
||||
"",
|
||||
null,
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
false,
|
||||
null,
|
||||
true,
|
||||
false);
|
||||
return QuickFixWrapper.wrap(descriptor, new RenameFix());
|
||||
PsiNameIdentifierOwner target = element instanceof PsiNameIdentifierOwner owner ? owner :
|
||||
element.getParent() instanceof PsiNameIdentifierOwner owner ? owner : null;
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException("Wrong element is supplied: " + element.getClass());
|
||||
}
|
||||
return new RenameModCommandAction(target).asIntention();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.siyeh.ig.fixes;
|
||||
|
||||
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo;
|
||||
import com.intellij.modcommand.ActionContext;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandAction;
|
||||
import com.intellij.openapi.util.text.HtmlChunk;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.usageView.UsageViewUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class RenameModCommandAction extends PsiUpdateModCommandAction<PsiNameIdentifierOwner> {
|
||||
public RenameModCommandAction(@NotNull PsiNameIdentifierOwner element) {
|
||||
super(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void invoke(@NotNull ActionContext context, @NotNull PsiNameIdentifierOwner element, @NotNull ModPsiUpdater updater) {
|
||||
updater.rename(element, ContainerUtil.createMaybeSingletonList(element.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getFamilyName() {
|
||||
return InspectionGadgetsBundle.message("rename.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull IntentionPreviewInfo generatePreview(ActionContext context, PsiNameIdentifierOwner element) {
|
||||
String what = UsageViewUtil.getType(element) + " '" + element.getName() + "'";
|
||||
String message = RefactoringBundle.message("rename.0.and.its.usages.preview.text", what);
|
||||
return new IntentionPreviewInfo.Html(HtmlChunk.text(message));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user