From fa68185dd22e7268f4e3de0a266a62e08fbbe365 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 30 Aug 2013 21:44:33 +0200 Subject: [PATCH] IDEA-112173 Smart completion after 'new' should honor upper bound of generic parameters --- java/java-psi-api/src/com/intellij/psi/GenericsUtil.java | 2 +- .../smartType/NewWithTypeParameterErasure-out.java | 7 +++++++ .../completion/smartType/NewWithTypeParameterErasure.java | 7 +++++++ .../codeInsight/completion/SmartTypeCompletionTest.java | 2 ++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/completion/smartType/NewWithTypeParameterErasure-out.java create mode 100644 java/java-tests/testData/codeInsight/completion/smartType/NewWithTypeParameterErasure.java diff --git a/java/java-psi-api/src/com/intellij/psi/GenericsUtil.java b/java/java-psi-api/src/com/intellij/psi/GenericsUtil.java index 4132f2389d43..5ef2b8fe2ead 100644 --- a/java/java-psi-api/src/com/intellij/psi/GenericsUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/GenericsUtil.java @@ -448,7 +448,7 @@ public class GenericsUtil { PsiType substituted = resolveResult.getSubstitutor().substitute(typeParam); if (substituted instanceof PsiWildcardType) { substituted = ((PsiWildcardType)substituted).getBound(); - if (substituted == null) substituted = PsiType.getJavaLangObject(manager, aClass.getResolveScope()); + if (substituted == null) substituted = TypeConversionUtil.typeParameterErasure(typeParam); } map.put(typeParam, substituted); } diff --git a/java/java-tests/testData/codeInsight/completion/smartType/NewWithTypeParameterErasure-out.java b/java/java-tests/testData/codeInsight/completion/smartType/NewWithTypeParameterErasure-out.java new file mode 100644 index 000000000000..3c92b3691c06 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/NewWithTypeParameterErasure-out.java @@ -0,0 +1,7 @@ +class A {} +class B { + { + m(new A()); + } + void m(A a) { } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/smartType/NewWithTypeParameterErasure.java b/java/java-tests/testData/codeInsight/completion/smartType/NewWithTypeParameterErasure.java new file mode 100644 index 000000000000..492eafeb6d7c --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/NewWithTypeParameterErasure.java @@ -0,0 +1,7 @@ +class A {} +class B { + { + m(new ) + } + void m(A a) { } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index ed7e90dd5957..44ebc9bd194d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -627,6 +627,8 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { public void testDefaultAnnoParam() throws Throwable { doTest(); } public void testCastGenericQualifier() throws Throwable { doTest(); } + + public void testNewWithTypeParameterErasure() throws Throwable { doTest(); } public void testEverythingDoubles() throws Throwable { configureByTestName();