Skip to content

Commit

Permalink
Add the name of the method to the diagnostic message for MemberName.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 669411448
  • Loading branch information
graememorgan authored and Error Prone Team committed Aug 30, 2024
1 parent 671ac41 commit dab4089
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;",
Expand Down Expand Up @@ -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;",
" }",
Expand All @@ -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(
Expand Down

0 comments on commit dab4089

Please sign in to comment.