use type parameter bound when normalize super wildcard by position (IDEA-73980)

This commit is contained in:
anna
2011-09-14 19:36:26 +02:00
parent daa3c0ff05
commit 263680df94
3 changed files with 78 additions and 0 deletions
@@ -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);
@@ -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<N extends Number> extends List<N>
{
}
void test(MyList<? super Integer> list)
{
Number n = list.get(0);
}
}
class Test1
{
public interface MyList<N extends Number> extends List<N> {
@Override
N get(int index);
}
void test(MyList<? super Integer> list)
{
Number n = list.get(0);
}
}
class Test2
{
public interface MyList<N extends Number>{
N get(int index);
}
void test(MyList<? super Integer> list)
{
Number n = list.get(0);
}
}
@@ -290,4 +290,8 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
enableInspectionTool(new UnusedDeclarationInspection());
doTest(true, false);
}
public void testSuperBound() throws Exception {
doTest(false, false);
}
}