From a91c7f752d9e9690dd0afd446de9fd9d057afe25 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 18 Feb 2014 15:36:42 +0100 Subject: [PATCH] bound promotion for super wildcard (? super A (bound extends A) == A) --- .../intellij/psi/impl/PsiSubstitutorImpl.java | 10 ++++ .../SuperWildcardWithBoundPromotion.java | 55 +++++++++++++++++++ .../daemon/GenericsHighlightingTest.java | 2 + 3 files changed, 67 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SuperWildcardWithBoundPromotion.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java index 723f5090bda1..17d2ef683b94 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java @@ -389,6 +389,16 @@ public class PsiSubstitutorImpl implements PsiSubstitutor { } } } + } else if (substituted instanceof PsiWildcardType && ((PsiWildcardType)substituted).isSuper()) { + final PsiType erasure = TypeConversionUtil.erasure(((PsiWildcardType)substituted).getBound()); + if (erasure != null) { + final PsiType[] boundTypes = typeParameter.getExtendsListTypes(); + for (PsiType boundType : boundTypes) { + if (TypeConversionUtil.isAssignable(boundType, erasure) || TypeConversionUtil.isAssignable(erasure, boundType)) { + return boundType; + } + } + } } if (captureContext != null) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SuperWildcardWithBoundPromotion.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SuperWildcardWithBoundPromotion.java new file mode 100644 index 000000000000..cfdc2a5402a9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SuperWildcardWithBoundPromotion.java @@ -0,0 +1,55 @@ +import java.io.Serializable; + +interface Parametrized {} + +class Bug1{ + Parametrized foo(Parametrized param) { + return null; + } + + void bug1(Parametrized param) { + foo(param); + } + + +} + +class Bug2{ + Parametrized foo(Parametrized param) { + return null; + } + + void bug1(Parametrized param) { + foo(param); + } + + +} + +class Test { + interface Parametrized {} + + class Bug1{ + Parametrized foo(Parametrized param) { + return null; + } + + void bug1(Parametrized param) { + foo(param); + } + + + } + + class Bug2{ + Parametrized foo(Parametrized param) { + return null; + } + + void bug1(Parametrized param) { + foo(param); + } + + + } +} \ 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 9455c0ec0493..2ed84c6ab14d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -338,6 +338,8 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testIDEA118527() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); } public void testIDEA120153() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); } + public void testSuperWildcardWithBoundPromotion() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);} + public void testJavaUtilCollections_NoVerify() throws Exception { PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule())); assertNotNull(collectionsClass);