union method
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
SourceSpan union(SourceSpan other) {
if (sourceUrl != other.sourceUrl) {
throw new ArgumentError("Source URLs \"${sourceUrl}\" and "
" \"${other.sourceUrl}\" don't match.");
}
var start = min(this.start, other.start);
var end = max(this.end, other.end);
var beginSpan = start == this.start ? this : other;
var endSpan = end == this.end ? this : other;
if (beginSpan.end.compareTo(endSpan.start) < 0) {
throw new ArgumentError("Spans $this and $other are disjoint.");
}
var text = beginSpan.text +
endSpan.text.substring(beginSpan.end.distance(endSpan.start));
return new SourceSpan(start, end, text);
}