Skip to content

Commit

Permalink
Avoid trailing blanks in SingleLineComment (#3589)
Browse files Browse the repository at this point in the history
Fixes #3588.
  • Loading branch information
Bananeweizen authored Oct 1, 2023
1 parent 8e76a43 commit e900928
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,17 @@ class Test {
)
);
}

@Test
void emptyCommentLineDoesNotGetTrailingBlank() {
rewriteRun(
java(
"""
// Copyright
//
// Some long license text
"""
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public Space visitSpace(Space space, Space.Location loc, ExecutionContext ctx) {
return space.withComments(ListUtils.map(space.getComments(), c -> {
if (!c.isMultiline()) {
TextComment tc = (TextComment) c;
if (!tc.getText().startsWith(" ")) {
return tc.withText(" " + tc.getText());
String commentText = tc.getText();
if (!commentText.isEmpty() && !commentText.startsWith(" ")) {
return tc.withText(" " + commentText);
}
}
return c;
Expand Down

0 comments on commit e900928

Please sign in to comment.