From 5bb39a4c90a500da27442a9b6777dcfe2e5d39ff Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Fri, 27 May 2022 14:26:56 +0200 Subject: [PATCH] [java-intentions] RemoveRedundantArgumentsFix: fix preview; enable when calling library methods GitOrigin-RevId: b2c765ef889f3c3081ba1c14adcbece0863a0b77 --- .../daemon/impl/quickfix/RemoveRedundantArgumentsFix.java | 5 +++-- .../quickFix/removeRedundantArgument/afterLibraryCall.java | 6 ++++++ .../quickFix/removeRedundantArgument/beforeLibraryCall.java | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeRedundantArgument/afterLibraryCall.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeRedundantArgument/beforeLibraryCall.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveRedundantArgumentsFix.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveRedundantArgumentsFix.java index d18a23aef826..92be20c873f4 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveRedundantArgumentsFix.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveRedundantArgumentsFix.java @@ -26,6 +26,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.util.PsiUtil; import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.ContainerUtil; @@ -125,7 +126,7 @@ public final class RemoveRedundantArgumentsFix implements IntentionAction { if (!candidate.isStaticsScopeCorrect()) return; PsiMethod method = (PsiMethod)candidate.getElement(); PsiSubstitutor substitutor = candidate.getSubstitutor(); - if (method != null && BaseIntentionAction.canModify(method)) { + if (method != null && BaseIntentionAction.canModify(arguments)) { QuickFixAction .registerQuickFixAction(highlightInfo, fixRange, new RemoveRedundantArgumentsFix(method, arguments.getExpressions(), substitutor)); } @@ -134,7 +135,7 @@ public final class RemoveRedundantArgumentsFix implements IntentionAction { @Override public @NotNull FileModifier getFileModifierForPreview(@NotNull PsiFile target) { return new RemoveRedundantArgumentsFix( - PsiTreeUtil.findSameElementInCopy(myTargetMethod, target), + myTargetMethod, ContainerUtil.map2Array(myArguments, PsiExpression.class, arg -> PsiTreeUtil.findSameElementInCopy(arg, target)), mySubstitutor); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeRedundantArgument/afterLibraryCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeRedundantArgument/afterLibraryCall.java new file mode 100644 index 000000000000..59e2fd7f6875 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeRedundantArgument/afterLibraryCall.java @@ -0,0 +1,6 @@ +// "Remove redundant arguments to call 'trim()'" "true" +class A { + public A() { + String s = "xyz".trim() + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeRedundantArgument/beforeLibraryCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeRedundantArgument/beforeLibraryCall.java new file mode 100644 index 000000000000..bf494bb1e638 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeRedundantArgument/beforeLibraryCall.java @@ -0,0 +1,6 @@ +// "Remove redundant arguments to call 'trim()'" "true" +class A { + public A() { + String s = "xyz".trim("123") + } +} \ No newline at end of file