@@ -82,15 +82,18 @@ private static String wrapOnce(final int columnLimit, String input, Formatter fo
8282 return input ;
8383 }
8484
85- TreeRangeMap <Integer , String > replacements = getReflowReplacements (columnLimit , input );
85+ // The pieces continue the way the formatter continues a chain of +: four columns times the multiplier of its
86+ // style, eight in OJF.
87+ var continuationIndent = 4 * formatter .options ().indentationMultiplier ();
88+ TreeRangeMap <Integer , String > replacements = getReflowReplacements (columnLimit , continuationIndent , input );
8689 String firstPass =
8790 formatter .formatSource (input , replacements .asMapOfRanges ().keySet ());
8891
8992 if (!firstPass .equals (input )) {
9093 // If formatting the replacement ranges resulted in a change, recalculate the replacements on
9194 // the updated input.
9295 input = firstPass ;
93- replacements = getReflowReplacements (columnLimit , input );
96+ replacements = getReflowReplacements (columnLimit , continuationIndent , input );
9497 }
9598
9699 String result = applyReplacements (input , replacements );
@@ -99,7 +102,7 @@ private static String wrapOnce(final int columnLimit, String input, Formatter fo
99102 String secondPass = formatter .formatSource (result , rangesAfterAppliedReplacements (replacements ));
100103
101104 if (!secondPass .equals (result )) {
102- replacements = getReflowReplacements (columnLimit , secondPass );
105+ replacements = getReflowReplacements (columnLimit , continuationIndent , secondPass );
103106 result = applyReplacements (secondPass , replacements );
104107 }
105108
@@ -141,21 +144,23 @@ private static ImmutableSet<Range<Integer>> rangesAfterAppliedReplacements(
141144 return outputRanges .build ();
142145 }
143146
144- public static TreeRangeMap <Integer , String > getReflowReplacements (int columnLimit , final String input )
145- throws FormatterException {
146- return new Reflower (columnLimit , input ).getReflowReplacements ();
147+ public static TreeRangeMap <Integer , String > getReflowReplacements (
148+ int columnLimit , int continuationIndent , final String input ) throws FormatterException {
149+ return new Reflower (columnLimit , continuationIndent , input ).getReflowReplacements ();
147150 }
148151
149152 private static class Reflower {
150153
151154 private final String input ;
152155 private final int columnLimit ;
156+ private final int continuationIndent ;
153157 private final String separator ;
154158 private final JCTree .JCCompilationUnit unit ;
155159 private final Position .LineMap lineMap ;
156160
157- Reflower (int columnLimit , String input ) throws FormatterException {
161+ Reflower (int columnLimit , int continuationIndent , String input ) throws FormatterException {
158162 this .columnLimit = columnLimit ;
163+ this .continuationIndent = continuationIndent ;
159164 this .input = input ;
160165 this .separator = Newlines .guessLineSeparator (input );
161166 this .unit = parse (input , /* allowStringFolding= */ false );
@@ -418,7 +423,16 @@ private void wrapLongStrings(
418423
419424 // Get the original source text of the string literals, excluding `"` and `+`.
420425 ImmutableList <String > components = stringComponents (input , unit , flat );
421- var plain = reflow (columnLimit , trailing , components , first .get (), startColumn , fistLineCol , "" , "" );
426+ var plain = reflow (
427+ columnLimit ,
428+ continuationIndent ,
429+ trailing ,
430+ components ,
431+ first .get (),
432+ startColumn ,
433+ fistLineCol ,
434+ "" ,
435+ "" );
422436 chains .add (new Chain (
423437 flat ,
424438 first .get (),
@@ -443,6 +457,7 @@ private void wrapLongStrings(
443457 var components = stringComponents (input , unit , chain .flat ());
444458 var pieces = reflow (
445459 columnLimit ,
460+ continuationIndent ,
446461 markers .tail (2 ).length (),
447462 components ,
448463 chain .firstInChain (),
@@ -460,7 +475,7 @@ private String join(Chain chain, List<String> pieces, String firstLineMarkers, S
460475 return render (
461476 separator ,
462477 pieces ,
463- chain .firstInChain () ? chain .firstLineColumn () + 4 : chain .startColumn () - 2 ,
478+ chain .firstInChain () ? chain .firstLineColumn () + continuationIndent : chain .startColumn () - 2 ,
464479 firstLineMarkers ,
465480 otherLineMarkers );
466481 }
@@ -680,6 +695,8 @@ private static boolean isEscaped(String input, int idx) {
680695 * {@link #render}.
681696 *
682697 * @param columnLimit the number of columns to wrap at
698+ * @param continuationIndent how far the lines after the first are indented from the start of the first, before
699+ * their {@code + }, when the text begins its chain
683700 * @param trailing extra space to leave after the last line
684701 * @param components the text to reflow
685702 * @param first0 true if the text includes the beginning of its enclosing concat chain, i.e. a
@@ -692,6 +709,7 @@ private static boolean isEscaped(String input, int idx) {
692709 */
693710 private static List <String > reflow (
694711 int columnLimit ,
712+ int continuationIndent ,
695713 int trailing ,
696714 ImmutableList <String > components ,
697715 boolean first0 ,
@@ -727,8 +745,8 @@ private static List<String> reflow(
727745 // add the split line to the output, and process whatever's left
728746 lines .add (String .join ("" , line ));
729747 if (first ) {
730- // Subsequent lines have a four-space continuation indent and a `+ `.
731- width -= 6 ;
748+ // Subsequent lines have a continuation indent and a `+ `.
749+ width -= continuationIndent + 2 ;
732750 // Also, switch to firstLineStartColumn in order to account for the fact that continuations
733751 // should get indented from the beginning of the first line.
734752 // This is to handle cases like:
0 commit comments