union method Null safety

  1. @override
SourceSpan union(
  1. SourceSpan other
)
override

Creates a new span that's the union of this and other.

The two spans must have the same source URL and may not be disjoint. text is computed by combining this.text and other.text.

Implementation

@override
SourceSpan union(SourceSpan other) {
  if (sourceUrl != other.sourceUrl) {
    throw ArgumentError('Source URLs "$sourceUrl" and '
        " \"${other.sourceUrl}\" don't match.");
  }

  final start = min(this.start, other.start);
  final end = max(this.end, other.end);
  final beginSpan = start == this.start ? this : other;
  final endSpan = end == this.end ? this : other;

  if (beginSpan.end.compareTo(endSpan.start) < 0) {
    throw ArgumentError('Spans $this and $other are disjoint.');
  }

  final text = beginSpan.text +
      endSpan.text.substring(beginSpan.end.distance(endSpan.start));
  return SourceSpan(start, end, text);
}