From 263680df94d9213e67d51598224bacdf6089407e Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 14 Sep 2011 19:34:46 +0200 Subject: [PATCH] use type parameter bound when normalize super wildcard by position (IDEA-73980) --- .../java/PsiMethodCallExpressionImpl.java | 21 ++++++++ .../advHighlighting7/SuperBound.java | 53 +++++++++++++++++++ .../daemon/LightAdvHighlightingJdk7Test.java | 4 ++ 3 files changed, 78 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/SuperBound.java diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java index a5c59b5d1f82..659aad6d2bf4 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java @@ -204,6 +204,27 @@ public class PsiMethodCallExpressionImpl extends ExpressionPsiElement implements final PsiSubstitutor substitutor = result.getSubstitutor(); if (PsiUtil.isRawSubstitutor(method, substitutor)) return TypeConversionUtil.erasure(ret); PsiType substitutedReturnType = substitutor.substitute(ret); + PsiType lowerBound = PsiType.NULL; + if (substitutedReturnType instanceof PsiCapturedWildcardType) { + lowerBound = ((PsiCapturedWildcardType)substitutedReturnType).getLowerBound(); + } else if (substitutedReturnType instanceof PsiWildcardType) { + lowerBound = ((PsiWildcardType)substitutedReturnType).getSuperBound(); + } + if (lowerBound != PsiType.NULL) { //? super + final PsiClass containingClass = method.getContainingClass(); + final PsiExpression qualifierExpression = methodExpression.getQualifierExpression(); + final PsiClass childClass = qualifierExpression != null ? PsiUtil.resolveClassInClassTypeOnly(qualifierExpression.getType()) : null; + if (containingClass != null && childClass != null) { + final PsiType typeInChildClassTypeParams = TypeConversionUtil.getSuperClassSubstitutor(containingClass, childClass, PsiSubstitutor.EMPTY).substitute(ret); + final PsiClass substituted = PsiUtil.resolveClassInClassTypeOnly(typeInChildClassTypeParams); + if (substituted instanceof PsiTypeParameter) { + final PsiClassType[] extendsListTypes = substituted.getExtendsListTypes(); + if (extendsListTypes.length == 1) { + return extendsListTypes[0]; + } + } + } + } return PsiImplUtil.normalizeWildcardTypeByPosition(substitutedReturnType, call); } return TypeConversionUtil.erasure(ret); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/SuperBound.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/SuperBound.java new file mode 100644 index 000000000000..3ceb429b3524 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/SuperBound.java @@ -0,0 +1,53 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.lang.Override; +import java.util.List; +public class Test +{ + public interface MyList extends List + { + } + + void test(MyList list) + { + Number n = list.get(0); + } +} + +class Test1 +{ + public interface MyList extends List { + @Override + N get(int index); + } + + void test(MyList list) + { + Number n = list.get(0); + } +} + +class Test2 +{ + public interface MyList{ + N get(int index); + } + + void test(MyList list) + { + Number n = list.get(0); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java index 515d20ba8472..86a214a6f9b9 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java @@ -290,4 +290,8 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase { enableInspectionTool(new UnusedDeclarationInspection()); doTest(true, false); } + + public void testSuperBound() throws Exception { + doTest(false, false); + } }