1414
1515package com .google .googlejavaformat .java ;
1616
17- import static com .google .common .collect .ImmutableList .toImmutableList ;
1817import static com .google .common .collect .Iterables .getLast ;
1918import static com .google .common .collect .Iterables .getOnlyElement ;
2019import static com .google .googlejavaformat .Doc .FillMode .INDEPENDENT ;
@@ -1531,8 +1530,7 @@ private boolean handleLogStatement(MethodInvocationTree node) {
15311530 return false ;
15321531 }
15331532 parts .addFirst (curr );
1534- visitDotWithPrefix (
1535- ImmutableList .copyOf (parts ), false , ImmutableList .of (parts .size () - 1 ), INDEPENDENT );
1533+ visitDotWithPrefix (ImmutableList .copyOf (parts ), false , ImmutableList .of (parts .size () - 1 ));
15361534 return true ;
15371535 }
15381536
@@ -1555,17 +1553,16 @@ private boolean handleLogStatement(MethodInvocationTree node) {
15551553 "withCause" ,
15561554 "withStackTrace" );
15571555
1558- private static ImmutableList <Long > handleStream (List <ExpressionTree > parts ) {
1556+ private static Stream <Long > handleStream (List <ExpressionTree > parts ) {
15591557 return indexes (
1560- parts .stream (),
1561- p -> {
1562- if (!(p instanceof MethodInvocationTree )) {
1563- return false ;
1564- }
1565- Name name = getMethodName ((MethodInvocationTree ) p );
1566- return Stream .of ("stream" , "toBuilder" ).anyMatch (name ::contentEquals );
1567- })
1568- .collect (toImmutableList ());
1558+ parts .stream (),
1559+ p -> {
1560+ if (!(p instanceof MethodInvocationTree )) {
1561+ return false ;
1562+ }
1563+ Name name = getMethodName ((MethodInvocationTree ) p );
1564+ return Stream .of ("stream" , "toBuilder" ).anyMatch (name ::contentEquals );
1565+ });
15691566 }
15701567
15711568 private static <T > Stream <Long > indexes (Stream <T > stream , Predicate <T > predicate ) {
@@ -2692,11 +2689,10 @@ void visitDot(ExpressionTree node0) {
26922689 }
26932690 }
26942691
2695- ImmutableList < Long > streamPrefixes = handleStream (items );
2696- streamPrefixes . forEach ( x -> prefixes . add ( x . intValue ()));
2692+ handleStream (items ). forEach ( x -> prefixes . add ( x . intValue ()) );
2693+
26972694 if (!prefixes .isEmpty ()) {
2698- visitDotWithPrefix (
2699- items , needDot , prefixes , streamPrefixes .isEmpty () ? INDEPENDENT : UNIFIED );
2695+ visitDotWithPrefix (items , needDot , prefixes );
27002696 } else {
27012697 visitRegularDot (items , needDot );
27022698 }
@@ -2792,10 +2788,7 @@ private boolean fillFirstArgument(ExpressionTree e, List<ExpressionTree> items,
27922788 * a syntactic unit
27932789 */
27942790 private void visitDotWithPrefix (
2795- List <ExpressionTree > items ,
2796- boolean needDot ,
2797- Collection <Integer > prefixes ,
2798- FillMode prefixFillMode ) {
2791+ List <ExpressionTree > items , boolean needDot , Collection <Integer > prefixes ) {
27992792 // Are there method invocations or field accesses after the prefix?
28002793 boolean trailingDereferences = !prefixes .isEmpty () && getLast (prefixes ) < items .size () - 1 ;
28012794
@@ -2811,7 +2804,7 @@ private void visitDotWithPrefix(
28112804 if (needDot ) {
28122805 FillMode fillMode ;
28132806 if (!unconsumedPrefixes .isEmpty () && i <= unconsumedPrefixes .peekFirst ()) {
2814- fillMode = prefixFillMode ;
2807+ fillMode = FillMode . INDEPENDENT ;
28152808 } else {
28162809 fillMode = FillMode .UNIFIED ;
28172810 }
0 commit comments