From 123f00950f6aca3fdc96eb0f21c9553f21101706 Mon Sep 17 00:00:00 2001 From: Mitchell Smith Date: Sat, 26 Oct 2024 15:18:01 +0900 Subject: [PATCH] edits --- .../java/com/google/googlejavaformat/java/Formatter.java | 2 +- .../google/googlejavaformat/java/JavaCommentsHelper.java | 9 +++++---- .../googlejavaformat/java/javadoc/JavadocFormatter.java | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/google/googlejavaformat/java/Formatter.java b/core/src/main/java/com/google/googlejavaformat/java/Formatter.java index 3e973958d..6afff6d6a 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/Formatter.java +++ b/core/src/main/java/com/google/googlejavaformat/java/Formatter.java @@ -89,7 +89,7 @@ @Immutable public final class Formatter { - public static final int MAX_LINE_LENGTH = 100; + public static final int MAX_LINE_LENGTH = 120; static final Range EMPTY_RANGE = Range.closedOpen(-1, -1); diff --git a/core/src/main/java/com/google/googlejavaformat/java/JavaCommentsHelper.java b/core/src/main/java/com/google/googlejavaformat/java/JavaCommentsHelper.java index 346324a45..3603e0428 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/JavaCommentsHelper.java +++ b/core/src/main/java/com/google/googlejavaformat/java/JavaCommentsHelper.java @@ -121,10 +121,12 @@ private List wrapLineComments(List lines, int column0) { result.add(line); continue; } - while (line.length() + column0 > Formatter.MAX_LINE_LENGTH) { - int idx = Formatter.MAX_LINE_LENGTH - column0; + while (line.length() > Formatter.MAX_LINE_LENGTH - column0) { + int idx = line.length() - 1; // only break on whitespace characters, and ignore the leading `// ` - while (idx >= 2 && !CharMatcher.whitespace().matches(line.charAt(idx))) { + while (idx >= 2 + && (!CharMatcher.whitespace().matches(line.charAt(idx)) + || idx > Formatter.MAX_LINE_LENGTH - column0)) { idx--; } if (idx <= 2) { @@ -179,4 +181,3 @@ private static boolean javadocShaped(List lines) { return true; } } - diff --git a/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocFormatter.java b/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocFormatter.java index 5addc6770..6fdb15218 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocFormatter.java +++ b/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocFormatter.java @@ -36,7 +36,7 @@ */ public final class JavadocFormatter { - static final int MAX_LINE_LENGTH = 100; + static final int MAX_LINE_LENGTH = 120; /** * Formats the given Javadoc comment, which must start with ∕✱✱ and end with ✱∕. The output will