From ed23e353b45d27d74ee5888d48a8f530908b2043 Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 19 Nov 2012 15:55:29 +0100 Subject: [PATCH] intersection type flattening: prefer non raw types (IDEA-95124) --- .../com/intellij/psi/PsiIntersectionType.java | 3 ++- .../FlattenIntersectionType.java | 16 ++++++++++++++++ .../daemon/GenericsHighlightingTest.java | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/FlattenIntersectionType.java diff --git a/java/java-psi-api/src/com/intellij/psi/PsiIntersectionType.java b/java/java-psi-api/src/com/intellij/psi/PsiIntersectionType.java index 410dd391511f..0624a9d9eea0 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiIntersectionType.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiIntersectionType.java @@ -17,6 +17,7 @@ package com.intellij.psi; import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.util.TypeConversionUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; @@ -67,7 +68,7 @@ public class PsiIntersectionType extends PsiType { PsiType type = iterator.next(); for (PsiType existing : array) { - if (type != existing && type.isAssignableFrom(existing)) { + if (type != existing && TypeConversionUtil.isAssignable(type, existing, false)) { iterator.remove(); break; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/FlattenIntersectionType.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/FlattenIntersectionType.java new file mode 100644 index 000000000000..4ff85a2320dc --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/FlattenIntersectionType.java @@ -0,0 +1,16 @@ +interface BusinessEntity> { +} + +interface EntityId { + E getEntity(); +} + +public class MyTest { + > T getEntity(EntityId defaultValue) { + return getEntityID(defaultValue).getEntity(); + } + + public

> P getEntityID(P defaultValue) { + return null; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index 37b3169a864f..aaffb7add958 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -203,6 +203,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testSpecificReturnType() throws Exception { doTest17Incompatibility(false); } public void testParameterizedParameterBound() throws Exception { doTest17Incompatibility(false); } public void testInstanceClassInStaticContextAccess() throws Exception { doTest17Incompatibility(false); } + public void testFlattenIntersectionType() throws Exception { doTest17Incompatibility(false); } public void testJavaUtilCollections_NoVerify() throws Exception { PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));