mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +07:00
[regexp] Regexp plugin quick-fixes converted to ModCommand
GitOrigin-RevId: 9734abefacb311efc2ba9c42008da783e725458e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9a4c97f26e
commit
bdf9fbcfd5
@@ -2,9 +2,9 @@
|
||||
package org.intellij.lang.regexp.inspection;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
@@ -70,8 +70,7 @@ public class DuplicateAlternationBranchInspection extends LocalInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
private static class DuplicateAlternationBranchFix implements LocalQuickFix {
|
||||
|
||||
private static class DuplicateAlternationBranchFix extends PsiUpdateModCommandQuickFix {
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -80,8 +79,7 @@ public class DuplicateAlternationBranchInspection extends LocalInspectionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
if (!(element instanceof RegExpBranch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
package org.intellij.lang.regexp.inspection;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
@@ -65,7 +67,7 @@ public class DuplicateCharacterInClassInspection extends LocalInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class DuplicateCharacterInClassFix implements LocalQuickFix {
|
||||
private static final class DuplicateCharacterInClassFix extends PsiUpdateModCommandQuickFix {
|
||||
|
||||
private final String myText;
|
||||
|
||||
@@ -84,8 +86,8 @@ public class DuplicateCharacterInClassInspection extends LocalInspectionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
descriptor.getPsiElement().delete();
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
element.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
package org.intellij.lang.regexp.inspection;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
@@ -58,8 +60,7 @@ public class EmptyAlternationBranchInspection extends LocalInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
private static class EmptyAlternationBranchFix implements LocalQuickFix {
|
||||
|
||||
private static class EmptyAlternationBranchFix extends PsiUpdateModCommandQuickFix {
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -68,8 +69,7 @@ public class EmptyAlternationBranchInspection extends LocalInspectionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
if (!(element.getParent() instanceof RegExpPattern)) return;
|
||||
element.getNextSibling().delete();
|
||||
element.delete();
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.intellij.lang.regexp.inspection;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
@@ -53,7 +55,7 @@ public class EscapedMetaCharacterInspection extends LocalInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
private static class EscapedMetaCharacterFix implements LocalQuickFix {
|
||||
private static class EscapedMetaCharacterFix extends PsiUpdateModCommandQuickFix {
|
||||
|
||||
private final char myC;
|
||||
|
||||
@@ -76,8 +78,7 @@ public class EscapedMetaCharacterInspection extends LocalInspectionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
if (!(element instanceof RegExpChar)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
package org.intellij.lang.regexp.inspection;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
@@ -46,7 +48,7 @@ public class OctalEscapeInspection extends LocalInspectionTool {
|
||||
return (hex.length() == 1 ? "\\x0" : "\\x") + hex;
|
||||
}
|
||||
|
||||
private static class ReplaceWithHexEscapeFix implements LocalQuickFix {
|
||||
private static class ReplaceWithHexEscapeFix extends PsiUpdateModCommandQuickFix {
|
||||
private final String myHex;
|
||||
|
||||
ReplaceWithHexEscapeFix(String hex) {
|
||||
@@ -68,12 +70,11 @@ public class OctalEscapeInspection extends LocalInspectionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
if (!(element instanceof RegExpChar)) {
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
if (!(element instanceof RegExpChar regExpChar)) {
|
||||
return;
|
||||
}
|
||||
RegExpReplacementUtil.replaceInContext(element, buildReplacementText((RegExpChar)element));
|
||||
RegExpReplacementUtil.replaceInContext(element, buildReplacementText(regExpChar));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
package org.intellij.lang.regexp.inspection;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.util.IntentionFamilyName;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
@@ -60,7 +60,7 @@ public class RedundantNestedCharacterClassInspection extends LocalInspectionTool
|
||||
}
|
||||
}
|
||||
|
||||
private static class RedundantNestedCharacterClassFix implements LocalQuickFix {
|
||||
private static class RedundantNestedCharacterClassFix extends PsiUpdateModCommandQuickFix {
|
||||
|
||||
@Override
|
||||
public @IntentionFamilyName @NotNull String getFamilyName() {
|
||||
@@ -68,8 +68,8 @@ public class RedundantNestedCharacterClassInspection extends LocalInspectionTool
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement().getParent();
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
element = element.getParent();
|
||||
if (element instanceof RegExpClass regExpClass) {
|
||||
final RegExpClassElement[] elements = regExpClass.getElements();
|
||||
final PsiElement parent = regExpClass.getParent();
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
package org.intellij.lang.regexp.inspection;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
@@ -66,7 +66,7 @@ public class RegExpRedundantClassElementInspection extends LocalInspectionTool {
|
||||
return classElement instanceof RegExpSimpleClass && ((RegExpSimpleClass)classElement).getKind().equals(NON_WORD);
|
||||
}
|
||||
|
||||
private static class RemoveRedundantClassElement implements LocalQuickFix {
|
||||
private static class RemoveRedundantClassElement extends PsiUpdateModCommandQuickFix {
|
||||
private final String myClassElementText;
|
||||
|
||||
private RemoveRedundantClassElement(String text) { myClassElementText = text; }
|
||||
@@ -82,9 +82,7 @@ public class RegExpRedundantClassElementInspection extends LocalInspectionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
PsiElement element = descriptor.getPsiElement();
|
||||
if (element == null) return;
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
element.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.options.OptPane;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.intellij.lang.regexp.RegExpBundle;
|
||||
@@ -72,7 +74,7 @@ public class RegExpRedundantEscapeInspection extends LocalInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveRedundantEscapeFix implements LocalQuickFix {
|
||||
private static class RemoveRedundantEscapeFix extends PsiUpdateModCommandQuickFix {
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@@ -82,12 +84,11 @@ public class RegExpRedundantEscapeInspection extends LocalInspectionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
if (!(element instanceof RegExpChar)) {
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
if (!(element instanceof RegExpChar regExpChar)) {
|
||||
return;
|
||||
}
|
||||
RegExpReplacementUtil.replaceInContext(element, replacement((RegExpChar)element));
|
||||
RegExpReplacementUtil.replaceInContext(element, replacement(regExpChar));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -3,6 +3,9 @@ package org.intellij.lang.regexp.inspection;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.modcommand.ModCommand;
|
||||
import com.intellij.modcommand.ModCommandQuickFix;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -166,7 +169,7 @@ public class RegExpSimplifiableInspection extends LocalInspectionTool {
|
||||
};
|
||||
}
|
||||
|
||||
private static class RegExpSimplifiableFix implements LocalQuickFix {
|
||||
private static class RegExpSimplifiableFix extends ModCommandQuickFix {
|
||||
private final String myExpression;
|
||||
private final boolean myDelete;
|
||||
|
||||
@@ -192,12 +195,13 @@ public class RegExpSimplifiableInspection extends LocalInspectionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
public @NotNull ModCommand perform(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
if (!(element instanceof RegExpElement)) {
|
||||
return;
|
||||
return ModCommand.nop();
|
||||
}
|
||||
RegExpReplacementUtil.replaceInContext(element, myDelete ? "" : myExpression, descriptor.getTextRangeInElement());
|
||||
return ModCommand.psiUpdate(element, e ->
|
||||
RegExpReplacementUtil.replaceInContext(e, myDelete ? "" : myExpression, descriptor.getTextRangeInElement()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.intellij.lang.regexp.inspection;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.modcommand.ModCommand;
|
||||
import com.intellij.modcommand.ModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -86,7 +88,7 @@ public class RepeatedSpaceInspection extends LocalInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
private static class RepeatedSpaceFix implements LocalQuickFix {
|
||||
private static class RepeatedSpaceFix extends ModCommandQuickFix {
|
||||
private final int myCount;
|
||||
|
||||
RepeatedSpaceFix(int count) {
|
||||
@@ -108,10 +110,10 @@ public class RepeatedSpaceInspection extends LocalInspectionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
public @NotNull ModCommand perform(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
if (!(element instanceof RegExpBranch)) {
|
||||
return;
|
||||
return ModCommand.nop();
|
||||
}
|
||||
final InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(element.getProject());
|
||||
final TextRange range = descriptor.getTextRangeInElement();
|
||||
@@ -128,7 +130,7 @@ public class RepeatedSpaceInspection extends LocalInspectionTool {
|
||||
}
|
||||
child = child.getNextSibling();
|
||||
}
|
||||
RegExpReplacementUtil.replaceInContext(element, text.toString());
|
||||
return ModCommand.psiUpdate(element, e -> RegExpReplacementUtil.replaceInContext(e, text.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
package org.intellij.lang.regexp.inspection;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
@@ -51,7 +53,7 @@ public class SingleCharAlternationInspection extends LocalInspectionTool {
|
||||
return atoms.length == 1 && atoms[0] instanceof RegExpChar;
|
||||
}
|
||||
|
||||
private static class SingleCharAlternationFix implements LocalQuickFix {
|
||||
private static class SingleCharAlternationFix extends PsiUpdateModCommandQuickFix {
|
||||
|
||||
private final String myText;
|
||||
|
||||
@@ -74,14 +76,13 @@ public class SingleCharAlternationInspection extends LocalInspectionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
if (!(element instanceof RegExpPattern pattern)) {
|
||||
return;
|
||||
}
|
||||
final PsiElement parent = pattern.getParent();
|
||||
final PsiElement victim =
|
||||
(parent instanceof RegExpGroup && ((RegExpGroup)parent).getType() == RegExpGroup.Type.NON_CAPTURING) ? parent : pattern;
|
||||
(parent instanceof RegExpGroup group && group.getType() == RegExpGroup.Type.NON_CAPTURING) ? parent : pattern;
|
||||
final String replacementText = buildReplacementText(pattern);
|
||||
if (replacementText == null) {
|
||||
return;
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.util.IntentionFamilyName;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
@@ -78,15 +80,15 @@ public class UnnecessaryNonCapturingGroupInspection extends LocalInspectionTool
|
||||
return atoms.length != 1 ? null : atoms[0];
|
||||
}
|
||||
|
||||
private static class UnnecessaryNonCapturingGroupFix implements LocalQuickFix {
|
||||
private static class UnnecessaryNonCapturingGroupFix extends PsiUpdateModCommandQuickFix {
|
||||
@Override
|
||||
public @IntentionFamilyName @NotNull String getFamilyName() {
|
||||
return RegExpBundle.message("inspection.quick.fix.remove.unnecessary.non.capturing.group");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement().getParent();
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
element = element.getParent();
|
||||
if (!(element instanceof RegExpGroup group)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.find.FindManager;
|
||||
import com.intellij.find.FindModel;
|
||||
import com.intellij.find.FindResult;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
@@ -203,7 +205,7 @@ public class CustomRegExpInspection extends LocalInspectionTool implements Dynam
|
||||
configuration.getProblemDescriptor(), configuration.getSuppressId());
|
||||
}
|
||||
|
||||
private static class CustomRegExpQuickFix implements LocalQuickFix {
|
||||
private static class CustomRegExpQuickFix extends PsiUpdateModCommandQuickFix {
|
||||
private final int myStartOffset;
|
||||
private final int myEndOffset;
|
||||
private final String myReplacement;
|
||||
@@ -232,8 +234,8 @@ public class CustomRegExpInspection extends LocalInspectionTool implements Dynam
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
PsiFile file = descriptor.getPsiElement().getContainingFile();
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
PsiFile file = element.getContainingFile();
|
||||
final Document document = file.getViewProvider().getDocument();
|
||||
if (myOriginal.equals(document.getText(TextRange.create(myStartOffset, myEndOffset)))) {
|
||||
document.replaceString(myStartOffset, myEndOffset, myReplacement);
|
||||
|
||||
Reference in New Issue
Block a user