48
48
import com.google.common.collect.Iterables;
49
49
import com.google.common.collect.ListMultimap;
50
50
import com.google.common.collect.Multimaps;
51
+ import com.google.common.collect.Range;
52
+ import com.google.common.collect.RangeSet;
51
53
import com.google.common.collect.Streams;
54
+ import com.google.common.collect.TreeRangeSet;
52
55
import com.google.errorprone.BugPattern;
53
56
import com.google.errorprone.ErrorProneFlags;
54
57
import com.google.errorprone.VisitorState;
@@ -475,9 +478,10 @@ private static ImmutableList<SuggestedFix> buildUnusedParameterFixes(
475
478
Symbol varSymbol, List<TreePath> usagePaths, VisitorState state) {
476
479
MethodSymbol methodSymbol = (MethodSymbol) varSymbol.owner;
477
480
int index = methodSymbol.params.indexOf(varSymbol);
478
- SuggestedFix.Builder fix = SuggestedFix.builder ();
481
+ RangeSet<Integer> deletions = TreeRangeSet.create ();
479
482
for (TreePath path : usagePaths) {
480
- fix.delete(path.getLeaf());
483
+ deletions.add(
484
+ Range.closed(getStartPosition(path.getLeaf()), state.getEndPosition(path.getLeaf())));
481
485
}
482
486
new TreePathScanner<Void, Void>() {
483
487
@Override
@@ -507,7 +511,7 @@ private void removeByIndex(List<? extends Tree> trees) {
507
511
// TODO(b/118437729): handle bogus source positions in enum declarations
508
512
return;
509
513
}
510
- fix.delete( tree);
514
+ deletions.add(Range.closed(getStartPosition( tree), state.getEndPosition(tree)) );
511
515
return;
512
516
}
513
517
int startPos;
@@ -526,9 +530,11 @@ private void removeByIndex(List<? extends Tree> trees) {
526
530
// TODO(b/118437729): handle bogus source positions in enum declarations
527
531
return;
528
532
}
529
- fix.replace( startPos, endPos, "" );
533
+ deletions.add(Range.closed( startPos, endPos) );
530
534
}
531
535
}.scan(state.getPath().getCompilationUnit(), null);
536
+ SuggestedFix.Builder fix = SuggestedFix.builder();
537
+ deletions.asRanges().forEach(x -> fix.replace(x.lowerEndpoint(), x.upperEndpoint(), ""));
532
538
return ImmutableList.of(fix.build());
533
539
}
534
540
0 commit comments