@@ -89,6 +89,10 @@ public final class MemberName extends BugChecker implements MethodTreeMatcher, V
8989 "Static variables should be named in UPPER_SNAKE_CASE if deeply immutable or lowerCamelCase"
9090 + " if not." ;
9191
92+ private static final String INITIALISM_DETAIL =
93+ ", with acronyms treated as words"
94+ + " (https://google.github.io/styleguide/javaguide.html#s5.3-camel-case)" ;
95+
9296 @ Override
9397 public Description matchMethod (MethodTree tree , VisitorState state ) {
9498 MethodSymbol symbol = getSymbol (tree );
@@ -123,16 +127,19 @@ public Description matchMethod(MethodTree tree, VisitorState state) {
123127 if (isConformant (symbol , name )) {
124128 return NO_MATCH ;
125129 }
126- String suggested = fixInitialisms (suggestedRename (symbol , name ));
127- return suggested .equals (name ) || !canBeRemoved (symbol , state )
128- ? buildDescription (tree )
129- .setMessage (
130- String .format (
131- "Methods and non-static variables should be named in lowerCamelCase; did you"
132- + " mean '%s'?" ,
133- suggested ))
134- .build ()
135- : describeMatch (tree , renameMethodWithInvocations (tree , suggested , state ));
130+ String renamed = suggestedRename (symbol , name );
131+ String suggested = fixInitialisms (renamed );
132+ boolean fixable = !suggested .equals (name ) && canBeRemoved (symbol , state );
133+ String diagnostic =
134+ "Methods and non-static variables should be named in lowerCamelCase"
135+ + (suggested .equals (renamed ) ? "" : INITIALISM_DETAIL );
136+ return buildDescription (tree )
137+ .setMessage (
138+ fixable
139+ ? diagnostic
140+ : diagnostic + String .format ("; did you" + " mean '%s'?" , suggested ))
141+ .addFix (fixable ? renameMethodWithInvocations (tree , suggested , state ) : emptyFix ())
142+ .build ();
136143 }
137144
138145 private static boolean hasTestAnnotation (MethodSymbol symbol ) {
@@ -171,17 +178,18 @@ public Description matchVariable(VariableTree tree, VisitorState state) {
171178 if (EXEMPTED_VARIABLE_NAMES .contains (name )) {
172179 return NO_MATCH ;
173180 }
174- String suggested = fixInitialisms (suggestedRename (symbol , name ));
181+ String renamed = suggestedRename (symbol , name );
182+ String suggested = fixInitialisms (renamed );
175183 boolean fixable = !suggested .equals (name ) && canBeRenamed (symbol );
184+ String diagnostic =
185+ (isStaticVariable (symbol ) ? STATIC_VARIABLE_FINDING : message ())
186+ + (suggested .equals (renamed ) ? "" : INITIALISM_DETAIL );
176187 return buildDescription (tree )
177- .addFix (fixable ? renameVariable (tree , suggested , state ) : emptyFix ())
178188 .setMessage (
179- isStaticVariable (symbol )
180- ? STATIC_VARIABLE_FINDING
181- : message ()
182- + (fixable || suggested .equals (name )
183- ? ""
184- : (" Did you mean " + suggested + "?" )))
189+ fixable
190+ ? diagnostic
191+ : diagnostic + String .format ("; did you" + " mean '%s'?" , suggested ))
192+ .addFix (fixable ? renameVariable (tree , suggested , state ) : emptyFix ())
185193 .build ();
186194 }
187195
0 commit comments