Skip to content

Commit

Permalink
Don't consider {...} as duplicate placeholder name
Browse files Browse the repository at this point in the history
  • Loading branch information
fluentfuture committed Dec 29, 2024
1 parent 05aac9d commit 899292d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ private void checkDuplicatePlaceholderNames(
VisitorState state)
throws ErrorReport {
ImmutableListMultimap<String, ExpressionTree> allPlaceholders =
BiStream.zip(placeholderVariableNames, args).collect(toImmutableListMultimap());
BiStream.zip(placeholderVariableNames, args)
.skipKeysIf("..."::equals) // wildcard doesn't count as duplicate name
.collect(toImmutableListMultimap());
for (Map.Entry<String, List<ExpressionTree>> entry :
Multimaps.asMap(allPlaceholders).entrySet()) {
List<ExpressionTree> conflicts =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,22 @@ public void format_duplicatePlaceholderNameWithConflictingValues() {
.doTest();
}

@Test
public void to_wildcardDoesNotCountAsDuplicateName() {
helper
.addSourceLines(
"Test.java",
"import com.google.mu.util.StringFormat;",
"class Test {",
" private static final StringFormat.Template<IllegalArgumentException> TEMPLATE =",
" StringFormat.to(IllegalArgumentException::new, \"{...}={...}\");",
" void test() {",
" TEMPLATE.with(1, 2);",
" }",
"}")
.doTest();
}

@Test
public void format_duplicatePlaceholderNameWithConsistentValues() {
helper
Expand Down

0 comments on commit 899292d

Please sign in to comment.