mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
[java-intentions] Quick-fixes to change method/var return type when inference fails
Fixes IDEA-354184 Quick-fix for generic types GitOrigin-RevId: 65d513f5303a082c26283e09275470840df90d30
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9f5cf87b91
commit
78d4bd2c8b
@@ -663,6 +663,15 @@ public final class HighlightMethodUtil {
|
||||
if (methodCall instanceof PsiExpression) {
|
||||
AdaptExpressionTypeFixUtil.registerExpectedTypeFixes(builder, fixRange, (PsiExpression)methodCall, expectedTypeByParent, actualType);
|
||||
}
|
||||
PsiElement parent = PsiUtil.skipParenthesizedExprUp(methodCall.getParent());
|
||||
if (parent instanceof PsiReturnStatement) {
|
||||
PsiParameterListOwner context = PsiTreeUtil.getParentOfType(parent, PsiMethod.class, PsiLambdaExpression.class);
|
||||
if (context instanceof PsiMethod containingMethod) {
|
||||
HighlightUtil.registerReturnTypeFixes(builder, containingMethod, actualType);
|
||||
}
|
||||
} else if (parent instanceof PsiLocalVariable var) {
|
||||
HighlightFixUtil.registerChangeVariableTypeFixes(var, actualType, var.getInitializer(), builder);
|
||||
}
|
||||
}
|
||||
else {
|
||||
builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).descriptionAndTooltip(errorMessage).range(fixRange);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Make 'getList()' return 'A.Box<java.util.List<java.lang.String>>' or ancestor" "true-preview"
|
||||
import java.util.*;
|
||||
|
||||
public class A {
|
||||
Box<List<String>> getList() {
|
||||
return new Box<>(Arrays.asList("foo"));
|
||||
}
|
||||
|
||||
class Box<T> {
|
||||
Box(T value) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Make 'getList()' return 'A.Box<java.util.List<java.lang.String>>' or ancestor" "true-preview"
|
||||
import java.util.*;
|
||||
|
||||
public class A {
|
||||
Box<Set<String>> getList() {
|
||||
return new <caret>Box<>(Arrays.asList("foo"));
|
||||
}
|
||||
|
||||
class Box<T> {
|
||||
Box(T value) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Change variable 'box' type to 'A.Box<List<String>>'" "true-preview"
|
||||
import java.util.*;
|
||||
|
||||
public class A {
|
||||
void test() {
|
||||
Box<List<String>> box = new Box<>(Arrays.asList("foo"));
|
||||
}
|
||||
|
||||
class Box<T> {
|
||||
Box(T value) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Change variable 'box' type to 'A.Box<List<String>>'" "true-preview"
|
||||
import java.util.*;
|
||||
|
||||
public class A {
|
||||
void test() {
|
||||
Box<Set<String>> box = new <caret>Box<>(Arrays.asList("foo"));
|
||||
}
|
||||
|
||||
class Box<T> {
|
||||
Box(T value) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user