diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java b/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java index d0c84aecae1..9506d9ed517 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java @@ -132,12 +132,13 @@ public Description matchMethod(MethodTree tree, VisitorState state) { boolean fixable = !suggested.equals(name) && canBeRemoved(symbol, state); String diagnostic = "Methods and non-static variables should be named in lowerCamelCase" - + (suggested.equals(renamed) ? "" : INITIALISM_DETAIL); + + (suggested.equals(renamed) ? "" : INITIALISM_DETAIL) + + ", but " + + symbol.getSimpleName() + + " is not"; return buildDescription(tree) .setMessage( - fixable - ? diagnostic - : diagnostic + String.format("; did you" + " mean '%s'?", suggested)) + fixable ? diagnostic : diagnostic + String.format("; did you mean '%s'?", suggested)) .addFix(fixable ? renameMethodWithInvocations(tree, suggested, state) : emptyFix()) .build(); } @@ -183,7 +184,10 @@ public Description matchVariable(VariableTree tree, VisitorState state) { boolean fixable = !suggested.equals(name) && canBeRenamed(symbol); String diagnostic = (isStaticVariable(symbol) ? STATIC_VARIABLE_FINDING : message()) - + (suggested.equals(renamed) ? "" : INITIALISM_DETAIL); + + (suggested.equals(renamed) ? "" : INITIALISM_DETAIL) + + ", but " + + symbol.getSimpleName() + + " is not"; return buildDescription(tree) .setMessage( fixable diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java index a1da16d7349..c1df079c152 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java @@ -202,7 +202,7 @@ public void nameWithLeadingUppercase() { .addSourceLines( "Test.java", "class Test {", - " // BUG: Diagnostic contains:", + " // BUG: Diagnostic contains: foo", " private int Foo;", " int get() {", " return Foo;", @@ -347,7 +347,7 @@ public void methodWithUnderscores_notOverriddenFromGeneratedSupertype_bug() { .addSourceLines( "Test.java", "class Test extends Base {", - " // BUG: Diagnostic contains:", + " // BUG: Diagnostic contains: get_more", " public int get_more() {", " return 0;", " }", @@ -361,7 +361,7 @@ public void nonConformantOverride_nameMatchesSuper_ignored() { .addSourceLines( "Base.java", "interface Base {", - " // BUG: Diagnostic contains:", + " // BUG: Diagnostic contains: a_b", " void foo(int a_b);", "}") .addSourceLines(