@@ -360,10 +360,10 @@ static int hasEscapedNewlineAt(String input, int idx) {
360360 *
361361 * @param separator the line separator
362362 * @param columnLimit the number of columns to wrap at
363- * @param startColumn the column position of the beginning of the original text
364363 * @param trailing extra space to leave after the last line
365364 * @param components the text to reflow
366365 * @param first0 true if the text includes the beginning of its enclosing concat chain, i.e. a
366+ * @param textStartColumn the column position of the beginning of the original text
367367 * @param firstLineStartColumn the column where the very first line starts (can be less than textStartColumn if text
368368 * follows variable declaration)
369369 */
@@ -373,21 +373,18 @@ private static String reflow(
373373 int trailing ,
374374 ImmutableList <String > components ,
375375 boolean first0 ,
376- int startColumn ,
376+ int textStartColumn ,
377377 int firstLineStartColumn ) {
378378 // We have space between the start column and the limit to output the first line.
379379 // Reserve two spaces for the quotes.
380- int width = columnLimit - startColumn - 2 ;
380+ int width = columnLimit - textStartColumn - 2 ;
381381 Deque <String > input = new ArrayDeque <>(components );
382382 List <String > lines = new ArrayList <>();
383383 boolean first = first0 ;
384384 while (!input .isEmpty ()) {
385385 int length = 0 ;
386386 List <String > line = new ArrayList <>();
387- // If we know this is going to be the last line, then remove a bit of width to account for the
388- // trailing characters.
389387 if (input .stream ().mapToInt (String ::length ).sum () <= width ) {
390- // This isn’t quite optimal, but arguably good enough. See b/179561701
391388 width -= trailing ;
392389 }
393390 while (!input .isEmpty ()
@@ -412,14 +409,14 @@ private static String reflow(
412409 // This is to handle cases like:
413410 // String foo = "first component"
414411 // + "rest";
415- width += startColumn - firstLineStartColumn ;
412+ width += textStartColumn - firstLineStartColumn ;
416413 first = false ;
417414 }
418415 }
419416
420417 return lines .stream ()
421418 .collect (joining (
422- "\" " + separator + " " .repeat (first0 ? firstLineStartColumn + 4 : startColumn - 2 ) + "+ \" " ,
419+ "\" " + separator + " " .repeat (first0 ? firstLineStartColumn + 4 : textStartColumn - 2 ) + "+ \" " ,
423420 "\" " ,
424421 "\" " ));
425422 }
@@ -483,8 +480,11 @@ private static int getStartPosition(Tree tree) {
483480 return ((JCTree ) tree ).getStartPosition ();
484481 }
485482
486- /** Returns true if any lines in the given Java source exceed the column limit. */
487- public static boolean needWrapping (int columnLimit , String input ) {
483+ /**
484+ * Returns true if any lines in the given Java source exceed the column limit or contain text blocks.
485+ * Keep this method and {@code linesNeedWrapping} in line.
486+ * */
487+ private static boolean needWrapping (int columnLimit , String input ) {
488488 // TODO(cushon): consider adding Newlines.lineIterable?
489489 Iterator <String > it = Newlines .lineIterator (input );
490490 while (it .hasNext ()) {
@@ -496,7 +496,11 @@ public static boolean needWrapping(int columnLimit, String input) {
496496 return false ;
497497 }
498498
499- /** Returns true if any lines in the given Java source exceed the column limit. */
499+ /**
500+ * Returns true if the lines containing the {@code initialRangesToChange} in the given Java source exceed the
501+ * column limit or contain text blocks. Used by the Intellij plugin to check if we need to run StringWrapper.wrap.
502+ * Keep this method and {@code needWrapping} in line.
503+ * */
500504 public static boolean linesNeedWrapping (int columnLimit , String input , RangeSet <Integer > initialRangesToChange ) {
501505 // TODO(cushon): consider adding Newlines.lineIterable?
502506 RangeSet <Integer > linesToChange = TreeRangeSet .create ();
0 commit comments