From f2ef7b87c11e7f7cb043a0ea28ad3dcfeda0a83c Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 4 Apr 2016 18:48:17 +0200 Subject: [PATCH] revert inference for all type arguments for now (IDEA-153970 Code completion suggestions for SmartType are broken when used with generics) --- .../resolve/graphInference/PsiGraphInferenceHelper.java | 3 +-- .../completion/smartType/SuggestMapInheritors-out.java | 7 +++++++ .../completion/smartType/SuggestMapInheritors.java | 7 +++++++ .../codeInsight/completion/SmartType18CompletionTest.java | 8 ++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/smartType/SuggestMapInheritors-out.java create mode 100644 java/java-tests/testData/codeInsight/completion/smartType/SuggestMapInheritors.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/PsiGraphInferenceHelper.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/PsiGraphInferenceHelper.java index 0d27f4719162..f78c1075a3e9 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/PsiGraphInferenceHelper.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/PsiGraphInferenceHelper.java @@ -117,8 +117,7 @@ public class PsiGraphInferenceHelper implements PsiInferenceHelper { leftTypes = new PsiType[] {arg}; rightTypes = new PsiType[]{param}; } - final PsiTypeParameterListOwner owner = typeParam.getOwner(); - final PsiTypeParameter[] typeParams = owner != null ? owner.getTypeParameters() : new PsiTypeParameter[] {typeParam}; + final PsiTypeParameter[] typeParams = new PsiTypeParameter[] {typeParam}; final InferenceSession inferenceSession = new InferenceSession(typeParams, leftTypes, rightTypes, PsiSubstitutor.EMPTY, myManager, null); if (inferenceSession.isProperType(inferenceSession.substituteWithInferenceVariables(param)) && inferenceSession.isProperType(inferenceSession.substituteWithInferenceVariables(arg))) { diff --git a/java/java-tests/testData/codeInsight/completion/smartType/SuggestMapInheritors-out.java b/java/java-tests/testData/codeInsight/completion/smartType/SuggestMapInheritors-out.java new file mode 100644 index 000000000000..11d19d08542c --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/SuggestMapInheritors-out.java @@ -0,0 +1,7 @@ +import java.util.*; + +class A { + { + Map m = new HashMap<>(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/smartType/SuggestMapInheritors.java b/java/java-tests/testData/codeInsight/completion/smartType/SuggestMapInheritors.java new file mode 100644 index 000000000000..83aca07e93c9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/SuggestMapInheritors.java @@ -0,0 +1,7 @@ +import java.util.*; + +class A { + { + Map m = new HashM + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java index 523d490a7765..78f5bdff569f 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java @@ -17,9 +17,12 @@ package com.intellij.codeInsight.completion; import com.intellij.JavaTestUtil; import com.intellij.codeInsight.lookup.Lookup; +import com.intellij.idea.Bombed; import com.intellij.testFramework.LightProjectDescriptor; import org.jetbrains.annotations.NotNull; +import java.util.Calendar; + public class SmartType18CompletionTest extends LightFixtureCompletionTestCase { @Override protected String getBasePath() { @@ -183,8 +186,13 @@ public void testConvertToObjectStream() { checkResultByFile("/" + getTestName(false) + "-out.java"); } + @Bombed(user = "anna/peter", month = Calendar.MAY, day = 4) public void testOnlyCompatibleTypes() { configureByTestName(); assertOrderedEquals(myFixture.getLookupElementStrings(), "get2"); } + + public void testSuggestMapInheritors() { doTest(); } + + public void testUnboundTypeArgs() { doTest(); } }