TypeName.super checks for classes fixed (IDEA-150141)

This commit is contained in:
Anna Kozlova
2016-01-14 18:42:40 +01:00
parent 1976c64367
commit 0926ee29c1
3 changed files with 41 additions and 7 deletions
@@ -60,7 +60,10 @@ import com.intellij.util.ui.UIUtil;
import com.intellij.xml.util.XmlStringUtil;
import gnu.trove.THashMap;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.*;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.PropertyKey;
import java.util.*;
import java.util.regex.Matcher;
@@ -1548,12 +1551,25 @@ public class HighlightUtil extends HighlightUtilBase {
//or if there exists some other direct superclass or direct superinterface of T, J, such that J is a subtype of I.
final PsiClass classT = PsiTreeUtil.getParentOfType(expr, PsiClass.class);
if (classT != null) {
final PsiElement parent = expr.getParent();
final PsiElement resolved = parent instanceof PsiReferenceExpression ? ((PsiReferenceExpression)parent).resolve() : null;
for (PsiClass superClass : classT.getSupers()) {
if (superClass.isInterface() && //check spec-javac relations
superClass.isInheritor(aClass, true)) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(qualifier)
.descriptionAndTooltip(JavaErrorMessages.message("bad.qualifier.in.super.method.reference", format(aClass), formatClass(superClass))).create();
if (superClass.isInheritor(aClass, true)) {
String cause = null;
if (superClass.isInterface()) {
cause = "redundant interface " + format(aClass) + " is extended by ";
}
else if (resolved instanceof PsiMethod &&
MethodSignatureUtil.findMethodBySuperMethod(superClass, (PsiMethod)resolved, true) != resolved) {
cause = "method " + ((PsiMethod)resolved).getName() + " is overridden in ";
}
if (cause != null) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(qualifier)
.descriptionAndTooltip(JavaErrorMessages.message("bad.qualifier.in.super.method.reference", cause + formatClass(superClass))).create();
}
}
}
@@ -99,7 +99,7 @@ illegal.generic.type.for.instanceof=Illegal generic type for instanceof
cannot.select.dot.class.from.type.variable=Cannot select from a type variable
method.does.not.override.super=Method does not override method from its superclass
call.to.super.is.not.allowed.in.enum.constructor=Call to super is not allowed in enum constructor
bad.qualifier.in.super.method.reference=Bad type qualifier in default super call: redundant interface {0} is extended by {1}
bad.qualifier.in.super.method.reference=Bad type qualifier in default super call: {0}
vararg.not.last.parameter=Vararg parameter must be the last in the list
modifiers.for.enum.constants=No modifiers allowed for enum constants
generics.type.arguments.on.raw.type=Type arguments given on a raw type
@@ -45,5 +45,23 @@ class Test {
J.super.toString();
}
}
class E implements I {
public void a() {}
}
class F extends E implements I {
void bar() {
<error descr="Bad type qualifier in default super call: method a is overridden in Test.E">I</error>.super.a();
Runnable r = <error descr="Bad type qualifier in default super call: method a is overridden in Test.E">I</error>.super::a;
}
}
class G extends A implements I {
void bar() {
I.super.a();
Runnable r = I.super::a;
}
}
}