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 @@ -112,15 +112,18 @@ private String preserveIndentation(List<String> lines, int column0) {
private String indentLineComments(Tok tok, List<String> lines, int column0) {
lines = wrapLineComments(tok, lines, column0);
StringBuilder builder = new StringBuilder();
builder.append(lines.get(0).trim());
String indentString = options.indentString(column0);
for (int i = 1; i < lines.size(); ++i) {
builder.append(lineSeparator).append(indentString).append(lines.get(i).trim());
for (int i = 0; i < lines.size(); ++i) {
if (i > 0) {
builder.append(lineSeparator).append(indentString);
}
builder.append(CharMatcher.whitespace().trimFrom(lines.get(i)));
}
return builder.toString();
}

private static final Pattern LINE_COMMENT_MISSING_SPACE_PREFIX = Pattern.compile("^(//+)[^\\s/]");
private static final Pattern LINE_COMMENT_MISSING_SPACE_PREFIX =
Pattern.compile("^(//+)[^\\s/]", Pattern.UNICODE_CHARACTER_CLASS);

// Preserve special `//noinspection` and `//$NON-NLS-x$` comments used by IDEs, which cannot
// contain leading spaces.
Expand Down Expand Up @@ -149,8 +152,8 @@ private List<String> wrapLineComments(Tok tok, List<String> lines, int column0)
}
while (line.length() + column0 > options.maxLineLength()) {
int idx = options.maxLineLength() - column0;
// only break on whitespace characters, and ignore the leading `// `
while (idx >= 2 && !CharMatcher.whitespace().matches(line.charAt(idx))) {
// only break on breaking whitespace characters, and ignore the leading `// `
while (idx >= 2 && !CharMatcher.breakingWhitespace().matches(line.charAt(idx))) {
idx--;
}
if (idx <= 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1360,10 +1360,10 @@ class T {
String expected =
"""
class T {
// Copyright (C) 2017 Interactive Brokers LLC. All rights reserved. This code is subject to the
//\u00a0terms and conditions of the IB API Non-Commercial License or the IB API Commercial License, as
// applicable.
// \u00a0non-breaking space after comment prefix
// Copyright (C) 2017 Interactive Brokers LLC. All rights reserved. This code is subject to
// the\u00a0terms and conditions of the IB API Non-Commercial License or the IB API Commercial License,
// as applicable.
//\u00a0non-breaking space after comment prefix
}
""";
assertThat(new Formatter().formatSource(input)).isEqualTo(expected);
Expand Down
Loading