3636 */
3737public final class JavadocFormatter {
3838
39- static final int MAX_LINE_LENGTH = 100 ;
39+ private final int maxLineLength ;
40+
41+ public JavadocFormatter (int maxLineLength ) {
42+ this .maxLineLength = maxLineLength ;
43+ }
4044
4145 /**
4246 * Formats the given Javadoc comment, which must start with ∕✱✱ and end with ✱∕. The output will
4347 * start and end with the same characters.
4448 */
45- public static String formatJavadoc (String input , int blockIndent ) {
49+ public String formatJavadoc (String input , int blockIndent ) {
4650 ImmutableList <Token > tokens ;
4751 try {
4852 tokens = lex (input );
@@ -53,8 +57,8 @@ public static String formatJavadoc(String input, int blockIndent) {
5357 return makeSingleLineIfPossible (blockIndent , result );
5458 }
5559
56- private static String render (List <Token > input , int blockIndent ) {
57- JavadocWriter output = new JavadocWriter (blockIndent );
60+ private String render (List <Token > input , int blockIndent ) {
61+ JavadocWriter output = new JavadocWriter (blockIndent , maxLineLength );
5862 for (Token token : input ) {
5963 switch (token .getType ()) {
6064 case BEGIN_JAVADOC :
@@ -165,8 +169,8 @@ private static Token standardize(Token token, Token standardToken) {
165169 * Returns the given string or a one-line version of it (e.g., "∕✱✱ Tests for foos. ✱∕") if it
166170 * fits on one line.
167171 */
168- private static String makeSingleLineIfPossible (int blockIndent , String input ) {
169- int oneLinerContentLength = MAX_LINE_LENGTH - "/** */" .length () - blockIndent ;
172+ private String makeSingleLineIfPossible (int blockIndent , String input ) {
173+ int oneLinerContentLength = maxLineLength - "/** */" .length () - blockIndent ;
170174 Matcher matcher = ONE_CONTENT_LINE_PATTERN .matcher (input );
171175 if (matcher .matches () && matcher .group (1 ).isEmpty ()) {
172176 return "/** */" ;
@@ -175,6 +179,4 @@ private static String makeSingleLineIfPossible(int blockIndent, String input) {
175179 }
176180 return input ;
177181 }
178-
179- private JavadocFormatter () {}
180182}
0 commit comments