8369428: Include method name in 'does not override or implement' diagnostics

Reviewed-by: vromero, liach
This commit is contained in:
Liam Miller-Cushon 2025-10-28 08:53:43 +00:00
parent d5ce66698d
commit f82cc22bfe
10 changed files with 15 additions and 12 deletions

View File

@ -1183,7 +1183,7 @@ public class Attr extends JCTree.Visitor {
Errors.DefaultAllowedInIntfAnnotationMember);
}
if (isDefaultMethod || (tree.sym.flags() & (ABSTRACT | NATIVE)) == 0)
log.error(tree.pos(), Errors.MissingMethBodyOrDeclAbstract);
log.error(tree.pos(), Errors.MissingMethBodyOrDeclAbstract(tree.sym, owner));
} else {
if ((tree.sym.flags() & (ABSTRACT|DEFAULT|PRIVATE)) == ABSTRACT) {
if ((owner.flags() & INTERFACE) != 0) {

View File

@ -2080,7 +2080,7 @@ public class Check {
}
}
log.error(pos,
explicitOverride ? (m.isStatic() ? Errors.StaticMethodsCannotBeAnnotatedWithOverride : Errors.MethodDoesNotOverrideSuperclass) :
explicitOverride ? (m.isStatic() ? Errors.StaticMethodsCannotBeAnnotatedWithOverride(m, m.enclClass()) : Errors.MethodDoesNotOverrideSuperclass(m, m.enclClass())) :
Errors.AnonymousDiamondMethodDoesNotOverrideSuperclass(Fragments.DiamondAnonymousMethodsImplicitlyOverride));
}
}

View File

@ -905,14 +905,17 @@ compiler.err.limit.string.overflow=\
compiler.err.malformed.fp.lit=\
malformed floating-point literal
# 0: symbol, 1: symbol
compiler.err.method.does.not.override.superclass=\
method does not override or implement a method from a supertype
{0} in {1} does not override or implement a method from a supertype
# 0: symbol, 1: symbol
compiler.err.static.methods.cannot.be.annotated.with.override=\
static methods cannot be annotated with @Override
static method {0} in {1} cannot be annotated with @Override
# 0: symbol, 1: symbol
compiler.err.missing.meth.body.or.decl.abstract=\
missing method body, or declare abstract
method {0} in {1} is missing a method body, or should be declared abstract
compiler.err.missing.ret.stmt=\
missing return statement

View File

@ -1,2 +1,2 @@
Private.java:14:5: compiler.err.method.does.not.override.superclass
Private.java:14:5: compiler.err.method.does.not.override.superclass: m(), Bar
1 error

View File

@ -1,2 +1,2 @@
T6359949a.java:15:5: compiler.err.static.methods.cannot.be.annotated.with.override
T6359949a.java:15:5: compiler.err.static.methods.cannot.be.annotated.with.override: example(), Test
1 error

View File

@ -92,7 +92,7 @@ public class CrashEmptyEnumConstructorTest extends TestRunner {
""");
List<String> expected = List.of(
"E.java:3: error: missing method body, or declare abstract",
"E.java:3: error: method E(String) in E is missing a method body, or should be declared abstract",
" E(String one);",
" ^",
"1 error");

View File

@ -1,2 +1,2 @@
OverrideNo.java:16:5: compiler.err.method.does.not.override.superclass
OverrideNo.java:16:5: compiler.err.method.does.not.override.superclass: f(), overrideNo.B
1 error

View File

@ -1,4 +1,4 @@
Private02.java:13:31: compiler.err.illegal.combination.of.modifiers: abstract, private
Private02.java:16:22: compiler.err.already.defined: kindname.method, foo(int), kindname.interface, Private02.I
Private02.java:12:22: compiler.err.missing.meth.body.or.decl.abstract
Private02.java:12:22: compiler.err.missing.meth.body.or.decl.abstract: foo(java.lang.String), Private02.I
3 errors

View File

@ -2,7 +2,7 @@ Private08.java:13:28: compiler.err.illegal.combination.of.modifiers: public, pri
Private08.java:14:30: compiler.err.illegal.combination.of.modifiers: abstract, private
Private08.java:15:29: compiler.err.illegal.combination.of.modifiers: private, default
Private08.java:16:24: compiler.err.mod.not.allowed.here: protected
Private08.java:17:22: compiler.err.missing.meth.body.or.decl.abstract
Private08.java:17:22: compiler.err.missing.meth.body.or.decl.abstract: missingBody(), Private08.I
Private08.java:22:33: compiler.err.report.access: foo(), private, Private08.I
Private08.java:27:21: compiler.err.override.weaker.access: (compiler.misc.clashes.with: doo(), Private08_01.J, doo(), Private08.I), public
Private08.java:25:13: compiler.err.non-static.cant.be.ref: kindname.variable, super

View File

@ -5,7 +5,7 @@ BadLocalVarInferenceTest.java:22:13: compiler.err.cant.infer.local.var.type: g,
BadLocalVarInferenceTest.java:23:13: compiler.err.cant.infer.local.var.type: d, (compiler.misc.local.self.ref)
BadLocalVarInferenceTest.java:24:13: compiler.err.cant.infer.local.var.type: k, (compiler.misc.local.array.missing.target)
BadLocalVarInferenceTest.java:25:29: compiler.err.does.not.override.abstract: compiler.misc.anonymous.class: BadLocalVarInferenceTest$1, m(java.lang.Object), BadLocalVarInferenceTest.Foo
BadLocalVarInferenceTest.java:26:13: compiler.err.method.does.not.override.superclass
BadLocalVarInferenceTest.java:26:13: compiler.err.method.does.not.override.superclass: m(java.lang.String), compiler.misc.anonymous.class: BadLocalVarInferenceTest$1
BadLocalVarInferenceTest.java:29:27: compiler.err.cant.resolve.location.args: kindname.method, charAt, , int, (compiler.misc.location.1: kindname.variable, x, java.lang.Object)
BadLocalVarInferenceTest.java:30:13: compiler.err.cant.infer.local.var.type: t, (compiler.misc.local.cant.infer.void)
10 errors