check for type param numbers in java 1.6 should not rise error if super methods have type params (IDEA-57338)

This commit is contained in:
Anna Kozlova
2014-06-09 15:32:55 +04:00
parent 598f9219a6
commit 2f0830187b
3 changed files with 26 additions and 1 deletions
@@ -137,7 +137,7 @@ public class GenericsHighlightUtil {
if (targetParametersNum == 0) {
if (PsiTreeUtil.getParentOfType(referenceParameterList, PsiCall.class) != null &&
typeParameterListOwner instanceof PsiMethod &&
javaSdkVersion.isAtLeast(JavaSdkVersion.JDK_1_7)) {
(javaSdkVersion.isAtLeast(JavaSdkVersion.JDK_1_7) || hasSuperMethodsWithTypeParams((PsiMethod)typeParameterListOwner))) {
description = null;
}
else {
@@ -196,6 +196,13 @@ public class GenericsHighlightUtil {
return null;
}
private static boolean hasSuperMethodsWithTypeParams(PsiMethod method) {
for (PsiMethod superMethod : method.findDeepestSuperMethods()) {
if (superMethod.hasTypeParameters()) return true;
}
return false;
}
private static PsiType detectExpectedType(PsiReferenceParameterList referenceParameterList) {
final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(referenceParameterList, PsiNewExpression.class);
LOG.assertTrue(newExpression != null);
@@ -0,0 +1,17 @@
abstract class A {
abstract <T> void foo();
}
abstract class B extends A {
void foo()
{
this.<Integer>foo();
}
}
abstract class C {
void foo()
{
this.<error descr="Method 'foo()' does not have type parameters"><Integer></error>foo();
}
}
@@ -366,6 +366,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA57388() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA125800() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA125816() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA57338() { doTest(LanguageLevel.JDK_1_6, JavaSdkVersion.JDK_1_6, false); }
//jdk should propagate LL 1.4 but actually it provides LL 1.7?!
public void testCastObjectToIntJdk14() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_4, false); }