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

Don't perform the inlining if parameter names are stripped. #4564

Merged
merged 1 commit into from
Sep 9, 2024
Merged
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 @@ -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
Loading