mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-115790 default methods cannot override Object methods
This commit is contained in:
+26
-1
@@ -464,13 +464,38 @@ public class GenericsHighlightUtil {
|
||||
|
||||
final PsiIdentifier classIdentifier = aClass.getNameIdentifier();
|
||||
if (PsiUtil.isLanguageLevel8OrHigher(aClass) && classIdentifier != null) {
|
||||
final HighlightInfo info = checkUnrelatedDefaultMethods(aClass, signaturesWithSupers, classIdentifier);
|
||||
HighlightInfo info = checkUnrelatedDefaultMethods(aClass, signaturesWithSupers, classIdentifier);
|
||||
if (info != null) return info;
|
||||
info = checkDefaultMethodOverrideEquivalentToObjectNonPrivate(aClass, signaturesWithSupers);
|
||||
if (info != null) return info;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HighlightInfo checkDefaultMethodOverrideEquivalentToObjectNonPrivate(PsiClass aClass,
|
||||
Collection<HierarchicalMethodSignature> withSupers) {
|
||||
if (aClass.isInterface()) {
|
||||
for (HierarchicalMethodSignature sig : withSupers) {
|
||||
final PsiMethod method = sig.getMethod();
|
||||
if (method.hasModifierProperty(PsiModifier.DEFAULT)) {
|
||||
for (HierarchicalMethodSignature methodSignature : sig.getSuperSignatures()) {
|
||||
final PsiClass containingClass = methodSignature.getMethod().getContainingClass();
|
||||
if (containingClass != null && CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) {
|
||||
final PsiIdentifier identifier = method.getNameIdentifier();
|
||||
LOG.assertTrue(identifier != null);
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
|
||||
.descriptionAndTooltip("Default method " + sig.getName() + " overrides a member of java.lang.Object")
|
||||
.range(identifier)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HighlightInfo checkUnrelatedDefaultMethods(PsiClass aClass,
|
||||
Collection<HierarchicalMethodSignature> signaturesWithSupers,
|
||||
PsiIdentifier classIdentifier) {
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
interface A {
|
||||
default String <error descr="Default method toString overrides a member of java.lang.Object">toString</error>() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
+1
@@ -31,6 +31,7 @@ public class Interface8MethodsHighlightingTest extends LightDaemonAnalyzerTestCa
|
||||
public void testCyclicSubstitutor() { doTest(false, false); }
|
||||
public void testThisAccessibility() { doTest(false, false); }
|
||||
public void testStaticMethodCalls() { doTest(false, false); }
|
||||
public void testDefaultMethodOverrideEquivalentObject() { doTest(false, false); }
|
||||
|
||||
private void doTest() {
|
||||
doTest(false, false);
|
||||
|
||||
Reference in New Issue
Block a user