[java] more descriptive error message for Override annotation on static method ( IDEA-294005)

GitOrigin-RevId: cbd30e2f727120140a15b6cfd144a59552040143
This commit is contained in:
Anna Kozlova
2022-05-13 19:20:43 +02:00
committed by intellij-monorepo-bot
parent 8963de463a
commit 62ce7483bd
4 changed files with 17 additions and 2 deletions

View File

@@ -1060,6 +1060,11 @@ public final class GenericsHighlightUtil {
static HighlightInfo checkOverrideAnnotation(@NotNull PsiMethod method,
@NotNull PsiAnnotation overrideAnnotation,
@NotNull LanguageLevel languageLevel) {
if (method.hasModifierProperty(PsiModifier.STATIC)) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(overrideAnnotation)
.descriptionAndTooltip(
JavaErrorBundle.message("static.method.cannot.be.annotated.with.override")).create();
}
try {
MethodSignatureBackedByPsiMethod superMethod = SuperMethodsSearch.search(method, null, true, false).findFirst();
if (superMethod != null && method.getContainingClass().isInterface()) {

View File

@@ -83,6 +83,7 @@ instanceof.pattern.supertype=Pattern type ''{0}'' is a supertype of expression t
instanceof.pattern.equals=Pattern type ''{0}'' is the same as expression type
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
static.method.cannot.be.annotated.with.override=Static methods cannot be annotated with @Override
call.to.super.is.not.allowed.in.enum.constructor=Call to super is not allowed in enum constructor
bad.qualifier.in.super.method.reference.overridden=Bad type qualifier in default super call: method {0} is overridden in {1}

View File

@@ -107,4 +107,13 @@ interface BMultiple {
void m() throws java.io.EOFException, sqlExcept, timeoutEx;
}
interface DMultiple extends AMultiple, BMultiple {}
interface DMultiple extends AMultiple, BMultiple {}
interface WithStatic {
static void f() {}
}
class WithStaticImpl implements WithStatic {
<error descr="Static methods cannot be annotated with @Override">@Override</error>
static void f() {}
}

View File

@@ -107,7 +107,7 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testCtrCallIsFirst() { doTest(false); }
public void testAccessLevelClash() { doTest(false); }
public void testCasts() { doTest(false); }
public void testOverrideConflicts() { doTest(false); }
public void testOverrideConflicts() { IdeaTestUtil.withLevel(getModule(), LanguageLevel.HIGHEST, () -> doTest(false)); }
public void testOverriddenMethodIsFinal() { doTest(false); }
public void testMissingReturn() { doTest(false); }
public void testUnreachable() { doTest(false); }