[java-intentions] Remove external type annotations on ChangeMethodSignatureFromUsageFix

Follow-up for IDEA-363866 Remove redundant type annotations on 'Change variable type' fix

GitOrigin-RevId: fc52a66f6b7192ed6c111737619d9fd5dab6817d
This commit is contained in:
Tagir Valeev
2024-11-27 12:52:44 +00:00
committed by intellij-monorepo-bot
parent d8ac43a850
commit 01dab26f64
4 changed files with 41 additions and 2 deletions
@@ -354,8 +354,9 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction/*, Hig
if (PsiPolyExpressionUtil.isPolyExpression(expression)) return null;
PsiType exprType = CommonJavaRefactoringUtil.getTypeByExpression(expression);
if (exprType == null || PsiTypes.voidType().equals(exprType)) return null;
if (exprType instanceof PsiDisjunctionType) {
exprType = ((PsiDisjunctionType)exprType).getLeastUpperBound();
exprType = PsiTypesUtil.removeExternalAnnotations(exprType);
if (exprType instanceof PsiDisjunctionType disjunctionType) {
exprType = disjunctionType.getLeastUpperBound();
}
if (!PsiTypesUtil.allTypeParametersResolved(myTargetMethod, exprType)) return null;
final ParameterInfoImpl changedParameterInfo = ParameterInfoImpl.create(i).withName(parameter.getName()).withType(exprType);
@@ -0,0 +1,15 @@
// "Change 1st parameter of method 'use' from 'Map<String, String>' to 'Map<String, Integer>'" "true"
import java.util.Map;
import java.util.stream.Collectors;
class Test {
void testMethodRef(Map<String, Integer> list) {
var map = list.entrySet().stream()
.filter(e -> !e.getKey().isEmpty())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
use(map);
}
private void use(Map<String, Integer> collect) {
}
}
@@ -0,0 +1,15 @@
// "Change 1st parameter of method 'use' from 'Map<String, String>' to 'Map<String, Integer>'" "true"
import java.util.Map;
import java.util.stream.Collectors;
class Test {
void testMethodRef(Map<String, Integer> list) {
var map = list.entrySet().stream()
.filter(e -> !e.getKey().isEmpty())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
use(<caret>map);
}
private void use(Map<String, String> collect) {
}
}
@@ -2,6 +2,10 @@
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
import static com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase.JAVA_21_ANNOTATED;
public class ChangeMethodSignatureFromUsageModernTest extends LightQuickFixParameterizedTestCase {
@@ -10,4 +14,8 @@ public class ChangeMethodSignatureFromUsageModernTest extends LightQuickFixParam
return "/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsageModern";
}
@Override
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
return JAVA_21_ANNOTATED;
}
}