[java-inspection] IDEA-376232 JEP 512: 'safe delete' for 'args' in main method in the compact source file at the first place in the list of suggested quick-fixes

- return ordered quick-fixes unused inspections

(cherry picked from commit b4abe529ad318430466b3e3e9d39dd2d12916a3e)

GitOrigin-RevId: 58d37e7cf5fac5425e4b15aa27cd7c5a6a69e175
This commit is contained in:
Mikhail Pyltsin
2025-07-22 18:05:18 +02:00
committed by intellij-monorepo-bot
parent d1a5734347
commit 7b4509504b
2 changed files with 51 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
import com.intellij.codeInsight.daemon.impl.analysis.LocalRefUseInfo;
import com.intellij.codeInsight.daemon.impl.quickfix.ReplaceWithUnnamedPatternFix;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.PriorityAction;
import com.intellij.codeInsight.intention.QuickFixFactory;
import com.intellij.codeInsight.intention.impl.PriorityIntentionActionWrapper;
import com.intellij.codeInspection.*;
@@ -409,10 +410,24 @@ public final class UnusedSymbolLocalInspection extends AbstractBaseJavaLocalInsp
private static @NotNull LocalQuickFix toLocalQuickFix(IntentionAction fix) {
ModCommandAction action = fix.asModCommandAction();
return action == null ? new LocalQuickFixBackedByIntentionAction(fix) :
return action == null ? new OrderedLocalQuickFixBackedByIntentionAction(fix) :
LocalQuickFix.from(action);
}
private static class OrderedLocalQuickFixBackedByIntentionAction extends LocalQuickFixBackedByIntentionAction implements PriorityAction {
private final @NotNull Priority myPriority;
private OrderedLocalQuickFixBackedByIntentionAction(@NotNull IntentionAction action) {
super(action);
myPriority = action instanceof PriorityAction priorityAction ? priorityAction.getPriority() : Priority.HIGH;
}
@Override
public @NotNull Priority getPriority() {
return myPriority;
}
}
@Override
public @NotNull OptPane getOptionsPane() {
return pane(

View File

@@ -0,0 +1,35 @@
// Copyright 2000-2025 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.intention.IntentionAction;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.testFramework.LightProjectDescriptor;
import com.siyeh.ig.LightJavaInspectionTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class RemoveUnusedParameterMainMethodTest extends LightJavaInspectionTestCase {
@Override
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
return JAVA_25;
}
@Nullable
@Override
protected InspectionProfileEntry getInspection() {
return new UnusedDeclarationInspection(true);
}
public void testSimple() {
myFixture.configureByText("Main.java", """
void main(String[] args<caret>) { }
""");
List<IntentionAction> intentions = myFixture.getAvailableIntentions();
assertEquals("Safe delete 'args'", intentions.get(0).getText());
}
}