From d88f344fd628ed2ab4b03ddc56c9dbca591f20d9 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 28 Nov 2013 17:06:10 +0100 Subject: [PATCH] ready to nulls (EA-52470 - IAE: TypeCompatibilityConstraint.) --- .../graphInference/PsiGraphInferenceHelper.java | 10 ++++++++++ .../completion/smartType/InferFromRawType.java | 5 +++++ .../completion/SmartType18CompletionTest.java | 16 ++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/completion/smartType/InferFromRawType.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 6915b5f1c1c6..cb671b0b9fc8 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 @@ -18,6 +18,8 @@ package com.intellij.psi.impl.source.resolve.graphInference; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.impl.source.resolve.ParameterTypeInferencePolicy; +import com.intellij.psi.util.PsiUtil; +import com.intellij.psi.util.TypeConversionUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -86,6 +88,14 @@ public class PsiGraphInferenceHelper implements PsiInferenceHelper { boolean isContraVariantPosition, LanguageLevel languageLevel) { if (arg == PsiType.VOID || param == PsiType.VOID) return PsiType.NULL; + if (param instanceof PsiArrayType && arg instanceof PsiArrayType) { + return getSubstitutionForTypeParameter(typeParam, ((PsiArrayType)param).getComponentType(), ((PsiArrayType)arg).getComponentType(), isContraVariantPosition, languageLevel); + } + + if (!(param instanceof PsiClassType)) return PsiType.NULL; + if (arg == null) { + return PsiType.NULL; + } final PsiType[] leftTypes; final PsiType[] rightTypes; if (isContraVariantPosition) { diff --git a/java/java-tests/testData/codeInsight/completion/smartType/InferFromRawType.java b/java/java-tests/testData/codeInsight/completion/smartType/InferFromRawType.java new file mode 100644 index 000000000000..8a2ea295de31 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/InferFromRawType.java @@ -0,0 +1,5 @@ +class A { + { + A a = new A<>(); + } +} \ 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 c386bd3c0f7a..08d2b5ba4ae3 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java @@ -17,6 +17,9 @@ package com.intellij.codeInsight.completion; import com.intellij.JavaTestUtil; import com.intellij.codeInsight.lookup.Lookup; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.impl.source.resolve.PsiResolveHelperImpl; +import com.intellij.psi.impl.source.resolve.graphInference.PsiGraphInferenceHelper; import com.intellij.testFramework.LightProjectDescriptor; import org.jetbrains.annotations.NotNull; @@ -70,6 +73,19 @@ public class SmartType18CompletionTest extends LightFixtureCompletionTestCase { doTest(); } + public void testInferFromRawType() throws Exception { + final PsiResolveHelperImpl helper = (PsiResolveHelperImpl)JavaPsiFacade.getInstance(getProject()).getResolveHelper(); + helper.setTestHelper(new PsiGraphInferenceHelper(getPsiManager())); + try { + configureByFile("/" + getTestName(false) + ".java"); + assertNotNull(myItems); + assertTrue(myItems.length == 0); + } + finally { + helper.setTestHelper(null); + } + } + private void doTest() { configureByFile("/" + getTestName(false) + ".java"); assertNotNull(myItems);