@Override
public Description matchVariable(VariableTree tree, VisitorState state) {
if (ANNOTATED_WITH_GUICE_INJECT_MATCHER.matches(tree, state)
&& FINAL_FIELD_MATCHER.matches(tree, state)) {
JCModifiers modifiers = ((JCVariableDecl) tree).getModifiers();
long replacementFlags = modifiers.flags ^ Flags.FINAL;
JCModifiers replacementModifiers = TreeMaker.instance(state.context)
.Modifiers(replacementFlags, modifiers.annotations);
/*
* replace new lines with strings, trim whitespace and remove empty parens to make the
* suggested fixes look sane
*/
String replacementModifiersString =
replacementModifiers.toString().replace('\n', ' ').replace("()", "").trim();
return describeMatch(modifiers,
SuggestedFix.replace(modifiers, replacementModifiersString));
}
return Description.NO_MATCH;
}