Skip to content

Commit 0ef517a

Browse files
authored
Merge pull request #41 from openjavaformat/comment-nbsp-wrap
Stop breaking line comments at a no-break space
2 parents 53ac7d8 + 3810d50 commit 0ef517a

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎open-java-format/src/main/java/com/palantir/javaformat/java/JavaCommentsHelper.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,11 @@ private List<String> wrapLineComments(List<String> lines, int column0) {
139139
String prefix = lineCommentPrefix(line);
140140
while (line.length() + column0 > options.maxLineLength()) {
141141
int idx = options.maxLineLength() - column0;
142-
// only break on whitespace characters, and ignore the leading `// `
143-
while (idx >= prefix.length() && !CharMatcher.whitespace().matches(line.charAt(idx))) {
142+
// only break on whitespace characters, and ignore the leading `// `. Not on a no-break space
143+
// such as U+00A0: the new line would start with `//` and that space, which the next run takes
144+
// for a missing space and pads, and then the comment never settles.
145+
while (idx >= prefix.length()
146+
&& !CharMatcher.breakingWhitespace().matches(line.charAt(idx))) {
144147
idx--;
145148
}
146149
if (idx <= prefix.length()) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class NbspLineComment {
2+
// Batches are capped: the importer rejects any upstream export file whose total row count is at or above 1 000 000 000 rows, so split larger files first.
3+
int rows;
4+
5+
//String testString = " thisisnotaHYPERLINKandsoitshouldntbetruncatedinsteaditshouldbedroppedthisisnotaHYPERLINKandsoit \"http://www.example.com/\""
6+
String url;
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class NbspLineComment {
2+
// Batches are capped: the importer rejects any upstream export file whose total row count is at or above
3+
// 1 000 000 000 rows, so split larger files first.
4+
int rows;
5+
6+
// String testString =
7+
// " thisisnotaHYPERLINKandsoitshouldntbetruncatedinsteaditshouldbedroppedthisisnotaHYPERLINKandsoit
8+
// \"http://www.example.com/\""
9+
String url;
10+
}

0 commit comments

Comments
 (0)