Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the name of the method to the diagnostic message for MemberName. #4559

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading