mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
[java-highlighting] IDEA-332057 Not show cannot override instance error in case static methods is inherited
GitOrigin-RevId: c16f27e9799cba34bf15ec27c40430161bb7c9b3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
458edd5fcb
commit
0aa4d2f4f2
@@ -1688,7 +1688,13 @@ public final class HighlightMethodUtil {
|
|||||||
description = error;
|
description = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method.hasModifierProperty(PsiModifier.STATIC)) {
|
if (method.hasModifierProperty(PsiModifier.STATIC) &&
|
||||||
|
//jsl 8, chapter 9.4.1
|
||||||
|
//chapter 8.4.8.2 speaks about a class that "declares or inherits a static method",
|
||||||
|
// at the same time the rule from chapter 9.4.1 speaks only about an interface that "declares a static method"
|
||||||
|
//There is no point to add java version check, because static methods in interfaces are allowed from java 8 too.
|
||||||
|
(!aClass.isInterface() ||
|
||||||
|
aClass.getManager().areElementsEquivalent(aClass, method.getContainingClass()))) {
|
||||||
for (HierarchicalMethodSignature superSignature : superSignatures) {
|
for (HierarchicalMethodSignature superSignature : superSignatures) {
|
||||||
PsiMethod superMethod = superSignature.getMethod();
|
PsiMethod superMethod = superSignature.getMethod();
|
||||||
if (!superMethod.hasModifierProperty(PsiModifier.STATIC)) {
|
if (!superMethod.hasModifierProperty(PsiModifier.STATIC)) {
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
interface A {
|
||||||
|
|
||||||
|
static void a() {
|
||||||
|
System.out.println("1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface B {
|
||||||
|
|
||||||
|
void a();
|
||||||
|
}
|
||||||
|
|
||||||
|
interface C extends A, B { //no error
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
interface C1 extends B{
|
||||||
|
<error descr="Static method 'a()' in 'C1' cannot override instance method 'a()' in 'B'">static void a()</error>{}; //error
|
||||||
|
}
|
||||||
@@ -128,6 +128,10 @@ public class Interface8MethodsHighlightingTest extends LightJavaCodeInsightFixtu
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInheritedStaticMethodOverrideAnotherInterface() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
public void testAmbiguousStaticCall() {
|
public void testAmbiguousStaticCall() {
|
||||||
myFixture.addClass("""
|
myFixture.addClass("""
|
||||||
package sample;
|
package sample;
|
||||||
|
|||||||
Reference in New Issue
Block a user