mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
open capture at top level only when prepare variable type (IDEA-22005)
This commit is contained in:
@@ -234,8 +234,11 @@ public class GenericsUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiType getVariableTypeByExpressionType(@Nullable final PsiType type) {
|
||||
public static PsiType getVariableTypeByExpressionType(@Nullable PsiType type) {
|
||||
if (type == null) return null;
|
||||
if (type instanceof PsiCapturedWildcardType) {
|
||||
type = ((PsiCapturedWildcardType)type).getWildcard();
|
||||
}
|
||||
PsiType transformed = type.accept(new PsiTypeVisitor<PsiType>() {
|
||||
@Override
|
||||
public PsiType visitArrayType(PsiArrayType arrayType) {
|
||||
@@ -271,7 +274,7 @@ public class GenericsUtil {
|
||||
|
||||
@Override
|
||||
public PsiType visitCapturedWildcardType(PsiCapturedWildcardType capturedWildcardType) {
|
||||
return capturedWildcardType.getWildcard().accept(this);
|
||||
return capturedWildcardType;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -492,7 +492,7 @@ public class PsiImplUtil {
|
||||
}
|
||||
|
||||
if (toplevel instanceof PsiArrayAccessExpression && !PsiUtil.isAccessedForWriting(toplevel)) {
|
||||
return type;
|
||||
return PsiUtil.captureToplevelWildcards(type, expression);
|
||||
}
|
||||
|
||||
final PsiType normalized = doNormalizeWildcardByPosition(type, expression, toplevel);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class Test {
|
||||
interface Foo<T> {
|
||||
void boo(T t);
|
||||
}
|
||||
|
||||
private static void f(Foo<?>... fs) {
|
||||
fs[0].boo<error descr="'boo(capture<?>)' in 'Test.Foo' cannot be applied to '(java.lang.String)'">("hey!")</error>;
|
||||
}
|
||||
|
||||
private static void f1(Foo<? extends String>... fs) {
|
||||
fs[0].boo<error descr="'boo(capture<? extends java.lang.String>)' in 'Test.Foo' cannot be applied to '(java.lang.String)'">("hey!")</error>;
|
||||
}
|
||||
}
|
||||
@@ -230,6 +230,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testIDEA21597() throws Exception { doTest5(false);}
|
||||
public void testIDEA20573() throws Exception { doTest5(false);}
|
||||
public void testIDEA20244() throws Exception { doTest5(false);}
|
||||
public void testIDEA22005() throws Exception { doTest5(false);}
|
||||
|
||||
public void testIDEA27185(){ doTest(LanguageLevel.JDK_1_6, JavaSdkVersion.JDK_1_6, false); }
|
||||
public void testIDEA67571(){ doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
|
||||
|
||||
@@ -177,7 +177,7 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testSCR40281() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("temp", false, false, false, "Set<? extends Map<?,String>.Entry<?,String>>"));
|
||||
doTest(new MockIntroduceVariableHandler("temp", false, false, false, "Set<? extends Map<?,java.lang.String>.Entry<capture<?>,java.lang.String>>"));
|
||||
}
|
||||
|
||||
public void testWithIfBranches() throws Exception {
|
||||
@@ -189,7 +189,7 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testDuplicateGenericExpressions() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, "Foo2<? extends Runnable>"));
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, "Foo2<capture<? extends java.lang.Runnable>>"));
|
||||
}
|
||||
|
||||
public void testStaticImport() throws Exception {
|
||||
@@ -308,7 +308,7 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testAssignmentToUnresolvedReference() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("collection", true, true, true, "java.util.List<? extends java.util.Collection<?>>"));
|
||||
doTest(new MockIntroduceVariableHandler("collection", true, true, true, "java.util.List<? extends java.util.Collection<capture<?>>>"));
|
||||
}
|
||||
|
||||
public void testNameSuggestion() throws Exception {
|
||||
|
||||
@@ -52,7 +52,7 @@ class MockIntroduceVariableHandler extends IntroduceVariableBase {
|
||||
PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) {
|
||||
final PsiType type = myLookForType ? findType(typeSelectorManager.getTypesForAll(), typeSelectorManager.getDefaultType())
|
||||
: typeSelectorManager.getDefaultType();
|
||||
Assert.assertTrue(type.getCanonicalText(), type.equalsToText(myExpectedTypeCanonicalName));
|
||||
Assert.assertTrue(type.getInternalCanonicalText(), type.getInternalCanonicalText().equals(myExpectedTypeCanonicalName));
|
||||
IntroduceVariableSettings introduceVariableSettings = new IntroduceVariableSettings() {
|
||||
@Override
|
||||
public String getEnteredName() {
|
||||
|
||||
Reference in New Issue
Block a user