introduce variable: suggest upper bound of captured wildcard

This commit is contained in:
Anna.Kozlova
2016-07-20 20:42:49 +02:00
parent 5f7f217b92
commit ad86a5171d
4 changed files with 23 additions and 1 deletions
@@ -298,7 +298,7 @@ public class GenericsUtil {
public static PsiType getVariableTypeByExpressionType(@Nullable PsiType type, final boolean openCaptured) {
if (type == null) return null;
if (type instanceof PsiCapturedWildcardType) {
type = ((PsiCapturedWildcardType)type).getWildcard();
type = ((PsiCapturedWildcardType)type).getUpperBound();
}
PsiType transformed = type.accept(new PsiTypeVisitor<PsiType>() {
@Override
@@ -0,0 +1,9 @@
interface I {}
abstract class Test<T extends I> {
void foo(Test<?> t) {
I m = t.get();
}
abstract T get();
}
@@ -0,0 +1,9 @@
interface I {}
abstract class Test<T extends I> {
void foo(Test<?> t) {
<selection>t.get()</selection>
}
abstract T get();
}
@@ -520,6 +520,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
doTest(new MockIntroduceVariableHandler("m", false, false, false, "java.util.function.IntFunction<java.lang.Class<?>[]>"));
}
public void testCapturedWildcardUpperBoundSuggestedAsType() throws Exception {
doTest(new MockIntroduceVariableHandler("m", false, false, false, "I"));
}
public void testReturnNonExportedArray() {
doTest(new MockIntroduceVariableHandler("i", false, false, false, "java.io.File[]") {
@Override