-
Notifications
You must be signed in to change notification settings - Fork 781
Description
Description of the feature request:
I would like to be able to concatenate string literals in the suggested replacement of a Refaster rule, e.g., an existing string literal of the source code (from a parameter of the rule) with a literal that is specified in the rule itself, such that I have "foobar" instead of "foo" + "bar" as result, where "foo" might come from the matched source code.
Feature requests: what underlying problem are you trying to solve with this feature?
I have a Refaster rule that replaces checkArgument(cond, "message " + o); with checkArgument(cond, "message " + "%s", o); (with an arbitrary message). I would like to get "message %s" in the suggested replacement.
(click here for full rule)
@BeforeTemplate
void eager(boolean b, @Matches(CompileTimeConstantExpressionMatcher.class) String msg1, Object o1) {
Preconditions.checkArgument(b, msg1 + o1);
}
@AfterTemplate
void lazy(boolean b, String msg1, Object o1) {
Preconditions.checkArgument(b, msg1 + "%s", o1);
}
Suggested solution
Another magic method Refaster.stringConcat(String... parts) that could be used as Refaster.stringConcat(msg, "%s") and would create a string literal with the concatenation of msg and "%s" if msg is a literal.
What version of Error Prone are you using?
2.3.4
Have you found anything relevant by searching the web?
No.