mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] DeleteElementFix: ModCommand
GitOrigin-RevId: aefb109889b898b31067f369577f14433075e4e9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c88923f34c
commit
51c5999d0b
+2
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// 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.codeInsight.AnnotationTargetUtil;
|
||||
@@ -75,7 +75,7 @@ public class MeaninglessRecordAnnotationInspection extends AbstractBaseJavaLocal
|
||||
message = JavaBundle.message("inspection.meaningless.record.annotation.message.parameter");
|
||||
}
|
||||
else return;
|
||||
holder.registerProblem(annotation, message, new DeleteElementFix(annotation));
|
||||
holder.problem(annotation, message).fix(new DeleteElementFix(annotation)).register();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+4
-2
@@ -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.codeInsight.daemon.impl.quickfix.DeleteElementFix;
|
||||
@@ -50,7 +50,9 @@ public class RedundantExplicitCloseInspection extends AbstractBaseJavaLocalInspe
|
||||
EquivalenceChecker.getCanonicalPsiEquivalence()
|
||||
.expressionsAreEquivalent(reference, ((PsiResourceExpression)element).getExpression()));
|
||||
if(!isReferenceToResourceVariable) return;
|
||||
holder.registerProblem(last, JavaBundle.message("inspection.redundant.explicit.close"), new DeleteElementFix(last, CommonQuickFixBundle.message("fix.remove.redundant", "close()")));
|
||||
holder.problem(last, JavaBundle.message("inspection.redundant.explicit.close"))
|
||||
.fix(new DeleteElementFix(last, CommonQuickFixBundle.message("fix.remove.redundant", "close()")))
|
||||
.register();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+2
-3
@@ -75,9 +75,8 @@ public class RedundantRecordConstructorInspection extends AbstractBaseJavaLocalI
|
||||
int count = getAssignedComponentsCount(components, parameters, statements);
|
||||
if (count < statements.length) {
|
||||
for (int i = statements.length - count; i < statements.length; i++) {
|
||||
holder.registerProblem(statements[i],
|
||||
JavaBundle.message("inspection.redundant.record.constructor.statement.message"),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new DeleteElementFix(statements[i]));
|
||||
holder.problem(statements[i], JavaBundle.message("inspection.redundant.record.constructor.statement.message"))
|
||||
.fix(new DeleteElementFix(statements[i])).register();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
+8
-14
@@ -1,12 +1,12 @@
|
||||
// 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.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.actions.IntentionActionWithFixAllOption;
|
||||
import com.intellij.codeInsight.intention.FileModifier;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.CommonQuickFixBundle;
|
||||
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
|
||||
import com.intellij.codeInspection.PsiUpdateModCommandAction;
|
||||
import com.intellij.codeInspection.util.IntentionName;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DeleteElementFix extends LocalQuickFixAndIntentionActionOnPsiElement implements IntentionActionWithFixAllOption {
|
||||
public class DeleteElementFix extends PsiUpdateModCommandAction<PsiElement> {
|
||||
private final @Nls String myText;
|
||||
|
||||
public DeleteElementFix(@NotNull PsiElement element) {
|
||||
@@ -33,11 +33,9 @@ public class DeleteElementFix extends LocalQuickFixAndIntentionActionOnPsiElemen
|
||||
myText = text;
|
||||
}
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return myText == null ? getFamilyName() : myText;
|
||||
protected @Nullable Presentation getPresentation(@NotNull ActionContext context, @NotNull PsiElement element) {
|
||||
return Presentation.of(myText == null ? getFamilyName() : myText).withFixAllOption(this);
|
||||
}
|
||||
|
||||
@Nls
|
||||
@@ -48,12 +46,8 @@ public class DeleteElementFix extends LocalQuickFixAndIntentionActionOnPsiElemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project,
|
||||
@NotNull PsiFile file,
|
||||
@Nullable Editor editor,
|
||||
@NotNull PsiElement startElement,
|
||||
@NotNull PsiElement endElement) {
|
||||
new CommentTracker().deleteAndRestoreComments(startElement);
|
||||
protected void invoke(@NotNull ActionContext context, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
new CommentTracker().deleteAndRestoreComments(element);
|
||||
}
|
||||
|
||||
public static final class DeleteMultiFix implements IntentionAction {
|
||||
|
||||
+2
-2
@@ -775,7 +775,7 @@ public final class QuickFixFactoryImpl extends QuickFixFactory {
|
||||
@NotNull
|
||||
@Override
|
||||
public LocalQuickFixAndIntentionActionOnPsiElement createDeleteFix(@NotNull PsiElement element) {
|
||||
return new DeleteElementFix(element);
|
||||
return LocalQuickFixAndIntentionActionOnPsiElement.from(new DeleteElementFix(element), element);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -786,7 +786,7 @@ public final class QuickFixFactoryImpl extends QuickFixFactory {
|
||||
@NotNull
|
||||
@Override
|
||||
public LocalQuickFixAndIntentionActionOnPsiElement createDeleteFix(@NotNull PsiElement element, @Nls @NotNull String text) {
|
||||
return new DeleteElementFix(element, text);
|
||||
return LocalQuickFixAndIntentionActionOnPsiElement.from(new DeleteElementFix(element, text), element);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+4
-4
@@ -482,10 +482,10 @@ public class JavadocDeclarationInspection extends LocalInspectionTool {
|
||||
String inlineRegion = region != null && markup.getRegionStart(region) == null ? null : region;
|
||||
String inlineRendered = renderText(markup, inlineRegion);
|
||||
if (!externalRendered.equals(inlineRendered)) {
|
||||
holder.registerProblem(nameElement,
|
||||
JavaBundle.message("inspection.message.external.snippet.differs.from.inline.snippet"),
|
||||
new SynchronizeInlineMarkupFix(externalRendered),
|
||||
new DeleteElementFix(body));
|
||||
holder.problem(nameElement, JavaBundle.message("inspection.message.external.snippet.differs.from.inline.snippet"))
|
||||
.fix(new SynchronizeInlineMarkupFix(externalRendered))
|
||||
.fix(new DeleteElementFix(body))
|
||||
.register();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-8
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// 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.java.codeInsight.daemon;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
@@ -565,14 +565,10 @@ public class LightAnnotatorHighlightingTest extends LightDaemonAnalyzerTestCase
|
||||
holder.newAnnotation(HighlightSeverity.ERROR, "i hate it")
|
||||
.newFix(new DeleteElementFix(element) {
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project,
|
||||
@NotNull PsiFile file,
|
||||
@Nullable Editor editor,
|
||||
@NotNull PsiElement startElement,
|
||||
@NotNull PsiElement endElement) {
|
||||
return FIX_ENABLED;
|
||||
protected @Nullable Presentation getPresentation(@NotNull ActionContext context, @NotNull PsiElement element) {
|
||||
return FIX_ENABLED ? super.getPresentation(context, element) : null;
|
||||
}
|
||||
}).registerFix().create();
|
||||
}.asIntention()).registerFix().create();
|
||||
iDidIt();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class EmptyStatementBodyInspection extends BaseInspection {
|
||||
@NotNull
|
||||
private static LocalQuickFix createFix(@NotNull PsiStatement statement, PsiExpression expression) {
|
||||
if (expression == null) {
|
||||
return new DeleteElementFix(statement);
|
||||
return new DeleteElementFix(statement).asQuickFix();
|
||||
}
|
||||
return new DeleteSideEffectsAwareFix(statement, expression).asQuickFix();
|
||||
}
|
||||
|
||||
+6
-7
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.siyeh.ig.redundancy;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.DeleteElementFix;
|
||||
@@ -12,6 +12,7 @@ import com.intellij.codeInspection.dataFlow.jvm.SpecialField;
|
||||
import com.intellij.codeInspection.dataFlow.types.DfType;
|
||||
import com.intellij.codeInspection.util.InspectionMessage;
|
||||
import com.intellij.java.JavaBundle;
|
||||
import com.intellij.modcommand.ModCommandAction;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -68,11 +69,11 @@ public class RedundantOperationOnEmptyContainerInspection extends AbstractBaseJa
|
||||
if (container != null) {
|
||||
String msg = getProblemMessage(container);
|
||||
if (msg == null) return;
|
||||
LocalQuickFix fix = null;
|
||||
ModCommandAction fix = null;
|
||||
if (ExpressionUtils.isVoidContext(call)) {
|
||||
fix = new DeleteElementFix(call, InspectionGadgetsBundle.message("remove.call.fix.family.name"));
|
||||
}
|
||||
holder.registerProblem(container, msg, LocalQuickFix.notNullElements(fix, getFindCauseFix(container)));
|
||||
holder.problem(container, msg).maybeFix(fix).fix(getFindCauseFix(container)).register();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,12 +83,10 @@ public class RedundantOperationOnEmptyContainerInspection extends AbstractBaseJa
|
||||
if (value == null) return;
|
||||
String msg = getProblemMessage(value);
|
||||
if (msg == null) return;
|
||||
holder.registerProblem(value, msg,
|
||||
new DeleteElementFix(statement, InspectionGadgetsBundle.message("remove.loop.fix.family.name")),
|
||||
getFindCauseFix(value));
|
||||
holder.problem(value, msg).fix(new DeleteElementFix(statement, InspectionGadgetsBundle.message("remove.loop.fix.family.name"))).fix(getFindCauseFix(value)).register();
|
||||
}
|
||||
|
||||
private @NotNull LocalQuickFix getFindCauseFix(@NotNull PsiExpression value) {
|
||||
private static @NotNull LocalQuickFix getFindCauseFix(@NotNull PsiExpression value) {
|
||||
PsiType type = value.getType();
|
||||
SpecialField field;
|
||||
if (type instanceof PsiArrayType) {
|
||||
|
||||
+3
-3
@@ -518,7 +518,7 @@ public class RedundantStringOperationInspection extends AbstractBaseJavaLocalIns
|
||||
@NotNull @PropertyKey(resourceBundle = BUNDLE) String key) {
|
||||
if (argument == null) return null;
|
||||
LocalQuickFix fix =
|
||||
new DeleteElementFix(argument, InspectionGadgetsBundle.message("inspection.redundant.string.remove.argument.fix.name"));
|
||||
new DeleteElementFix(argument, InspectionGadgetsBundle.message("inspection.redundant.string.remove.argument.fix.name")).asQuickFix();
|
||||
return myManager.createProblemDescriptor(argument,
|
||||
InspectionGadgetsBundle.message(key),
|
||||
myIsOnTheFly,
|
||||
@@ -556,8 +556,8 @@ public class RedundantStringOperationInspection extends AbstractBaseJavaLocalIns
|
||||
if (ExpressionUtils.isZero(args[0])) {
|
||||
return getProblem(call, "inspection.redundant.string.call.message");
|
||||
}
|
||||
DeleteElementFix fix =
|
||||
new DeleteElementFix(args[1], InspectionGadgetsBundle.message("inspection.redundant.string.remove.argument.fix.name"));
|
||||
LocalQuickFix fix =
|
||||
new DeleteElementFix(args[1], InspectionGadgetsBundle.message("inspection.redundant.string.remove.argument.fix.name")).asQuickFix();
|
||||
return myManager.createProblemDescriptor(args[1],
|
||||
InspectionGadgetsBundle.message("inspection.redundant.string.length.argument.message"),
|
||||
fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myIsOnTheFly);
|
||||
|
||||
Reference in New Issue
Block a user