Skip to content

Commit

Permalink
Don't perform the inlining if parameter names are stripped.
Browse files Browse the repository at this point in the history
#inlineme

PiperOrigin-RevId: 672578943
  • Loading branch information
kluever authored and Error Prone Team committed Sep 9, 2024
1 parent dab4089 commit 494e2c6
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,18 @@ && stringContainsComments(state.getSourceForNode(tree), state.context)) {
}

for (int i = 0; i < varNames.size(); i++) {
String varName = varNames.get(i);

// If the parameter names are missing (b/365094947), don't perform the inlining.
if (varName.matches("arg[0-9]+")) {
return Description.NO_MATCH;
}

// The replacement logic below assumes the existence of another token after the parameter
// in the replacement string (ex: a trailing parens, comma, dot, etc.). However, in the case
// where the replacement is _just_ one parameter, there isn't a trailing token. We just make
// the direct replacement here.
if (replacement.equals(varNames.get(i))) {
if (replacement.equals(varName)) {
replacement = callingVars.get(i);
break;
}
Expand All @@ -252,7 +259,7 @@ && stringContainsComments(state.getSourceForNode(tree), state.context)) {
String capturePrefixForVarargs = terminalVarargsReplacement ? "(?:,\\s*)?" : "\\b";
// We want to avoid replacing a method invocation with the same name as the method.
var extractArgAndNextToken =
Pattern.compile(capturePrefixForVarargs + Pattern.quote(varNames.get(i)) + "\\b([^(])");
Pattern.compile(capturePrefixForVarargs + Pattern.quote(varName) + "\\b([^(])");
String replacementResult =
Matcher.quoteReplacement(terminalVarargsReplacement ? "" : callingVars.get(i)) + "$1";
Matcher matcher = extractArgAndNextToken.matcher(replacement);
Expand Down

0 comments on commit 494e2c6

Please sign in to comment.