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