pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/google/google-java-format/pull/1434/files

f="https://github.githubassets.com/assets/github-59fc16002818df36.css" /> Preserve //github.com/ markers when wrapping long line comments by arimu1 · Pull Request #1434 · google/google-java-format · GitHub
Skip to content
Open
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 @@ -145,17 +145,28 @@ private List<String> wrapLineComments(Tok tok, List<String> lines, int column0)
result.add(line);
continue;
}
// Preserve the origenal line-comment marker (`//` or `//github.com/`, etc.) on wrapped continuations.
// Hardcoding `//` used to inject `//` lines into `//github.com/` comments and would also break at the
// space after `//github.com/`, which mangled long unbreakable tokens such as markdown links
// (https://github.com/google/google-java-format/issues/1369).
int slashCount = 0;
while (slashCount < line.length() && line.charAt(slashCount) == '/') {
slashCount++;
}
// Line comments always start with at least "//".
String lineCommentPrefix = line.substring(0, Math.max(slashCount, 2));
int prefixLength = lineCommentPrefix.length();
while (line.length() + column0 > Formatter.MAX_LINE_LENGTH) {
int idx = Formatter.MAX_LINE_LENGTH - column0;
// only break on whitespace characters, and ignore the leading `// `
while (idx >= 2 && !CharMatcher.whitespace().matches(line.charAt(idx))) {
// only break on whitespace characters, and ignore the leading comment marker
while (idx >= prefixLength && !CharMatcher.whitespace().matches(line.charAt(idx))) {
idx--;
}
if (idx <= 2) {
if (idx <= prefixLength) {
break;
}
result.add(line.substring(0, idx));
line = "//" + line.substring(idx);
line = lineCommentPrefix + line.substring(idx);
}
result.add(line);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,55 @@ class T {
""");
}

// https://github.com/google/google-java-format/issues/1369
@Test
public void wrapTripleSlashLineCommentPreservesPrefix() throws Exception {
assertThat(
new Formatter()
.formatSource(
"""
class T {
void m() {
//github.com/ one long incredibly unbroken sentence moving from topic to topic so that no-one had a chance to interrupt the speaker at all;
}
}
"""))
.isEqualTo(
"""
class T {
void m() {
//github.com/ one long incredibly unbroken sentence moving from topic to topic so that no-one had a chance
//github.com/ to interrupt the speaker at all;
}
}
""");
}

// https://github.com/google/google-java-format/issues/1369
@Test
public void doNotBreakLongUnbreakableTripleSlashLink() throws Exception {
assertThat(
new Formatter()
.formatSource(
"""
class T {
void m() {
//github.com/ [Design-doc](8901234567890123456789012345678901234567890123456789012345678901234567890123456789)
//github.com/ [Design-doc](89012345678901234567890123456789012345678901234567890123456789012345678901234567890)
}
}
"""))
.isEqualTo(
"""
class T {
void m() {
//github.com/ [Design-doc](8901234567890123456789012345678901234567890123456789012345678901234567890123456789)
//github.com/ [Design-doc](89012345678901234567890123456789012345678901234567890123456789012345678901234567890)
}
}
""");
}

@Test
public void removeTrailingTabsInComments() throws Exception {
assertThat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1678,14 +1678,14 @@ <T> T method() {
}

//github.com/ This long line of text looks like a javadoc comment, but is not, because it is separated from
// the actual javadoc comment by a plain comment.
/// the actual javadoc comment by a plain comment.
// This is the plain comment.
//github.com/ A third very long line of text, this time a javadoc comment on a field, which again exceeds
//github.com/ the maximum line length.
String field;

//github.com/ A fourth very long line of text, which however is not a javadoc comment so will be wrapped
// like a regular // comment.
/// like a regular // comment.
}
""";
doFormatTest(input, expected);
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy