IDEA-127637 code completion utility should strip 'extends' wildcards from generic qualifiers of generated anonymous classes

This commit is contained in:
peter
2014-07-29 08:41:03 +02:00
parent 086fc3480a
commit e4df02442d
4 changed files with 38 additions and 2 deletions
@@ -476,6 +476,13 @@ public class GenericsUtil {
PsiType substituted = resolveResult.getSubstitutor().substitute(typeParam);
if (substituted instanceof PsiWildcardType) {
substituted = ((PsiWildcardType)substituted).getBound();
if (substituted instanceof PsiCapturedWildcardType) {
PsiType bound = ((PsiCapturedWildcardType)substituted).getLowerBound();
if (bound == null || bound == PsiType.NULL) {
bound = ((PsiCapturedWildcardType)substituted).getUpperBound();
}
substituted = bound;
}
if (substituted == null) substituted = TypeConversionUtil.typeParameterErasure(typeParam);
}
map.put(typeParam, substituted);
@@ -0,0 +1,16 @@
class Main {
void foo(List<? extends Number> list) {
list.forEach(new Consumer<Number>() {
@Override
public void consume(Number number) {
<caret>
}
});
}
}
class List<T> {
void forEach(Consumer<? super T> consumer);
}
interface Consumer<T> { void consume(T t); }
@@ -0,0 +1,11 @@
class Main {
void foo(List<? extends Number> list) {
list.forEach(new <caret>);
}
}
class List<T> {
void forEach(Consumer<? super T> consumer);
}
interface Consumer<T> { void consume(T t); }
@@ -716,7 +716,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testMethodColon() throws Exception { doFirstItemTest(':'); }
public void testVariableColon() throws Exception { doFirstItemTest(':'); }
private void doFirstItemTest(char c) throws Exception {
private void doFirstItemTest(char c) {
configureByTestName();
select(c);
checkResultByTestName();
@@ -824,6 +824,8 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
doActionTest();
}
public void testDontSuggestWildcardGenerics() { doItemTest(); }
public void testCastWith2TypeParameters() throws Throwable { doTest(); }
public void testClassLiteralInArrayAnnoInitializer() throws Throwable { doTest(); }
public void testClassLiteralInArrayAnnoInitializer2() throws Throwable { doTest(); }
@@ -1141,7 +1143,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByTestName();
}
private void doItemTest() throws Exception {
private void doItemTest() {
doFirstItemTest('\n');
}