Skip to content
Merged
Show file tree
Hide file tree
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 @@ -375,6 +375,17 @@ else if (i > 0) {
ASTNode nextArg = (ASTNode) arguments.get(i + 1);
int nextArgStart = nextArg.getStartPosition();
for (int j = argEnd; j < nextArgStart && j < source.length(); j++) {
// Skip comments — their text may contain commas.
if (source.charAt(j) == '/' && j + 1 < source.length()
&& (source.charAt(j + 1) == '/' || source.charAt(j + 1) == '*')) {
for (JavaTokens.Token tok : tokensIn(j, nextArgStart)) {
if (tok.start() == j && tok.isComment()) {
j = tok.end() - 1;
break;
}
}
continue;
}
if (source.charAt(j) == ',') {
argEnd = j + 1;
// Extend through any same-line trailing comment after
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,70 @@ void run()
assertCanonicalFormatting(code);
}

@Test
void testFormatterKeepsInlineBlockCommentContainingACommaBetweenArguments()
{
String code =
"""
class Test
{
void run()
{
verify(metadata,
LegacyClass.class,
null,
false /* don't care, but this comment contains a comma */,
attributes);
}
}
""";

assertCanonicalFormatting(code);
}

@Test
void testFormatterKeepsInlineJavadocCommentContainingACommaBetweenArguments()
{
String code =
"""
class Test
{
void run()
{
verify(metadata,
LegacyClass.class,
null,
false /** don't care, but this comment contains a comma */,
attributes);
}
}
""";

assertCanonicalFormatting(code);
}

@Test
void testFormatterKeepsInlineLineCommentContainingACommaBetweenArguments()
{
String code =
"""
class Test
{
void run()
{
verify(metadata,
LegacyClass.class,
null,
false // don't care, but this comment contains a comma
,
attributes);
}
}
""";

assertCanonicalFormatting(code);
}

@Test
void testFormatterKeepsBlockCommentInsideForLoopHeader()
{
Expand Down