Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: lib/src/location_mixin.dart

Issue 1307123004: Add SourceLocationMixin and SourceLocationBase. (Closed) Base URL: git@github.com:dart-lang/source_span@master
Patch Set: Add a missing import. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/location.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library source_span.location_mixin;
6
7 import 'location.dart';
8 import 'span.dart';
9
10 // Note: this class duplicates a lot of functionality of [SourceLocation]. This
11 // is because in order for SourceLocation to use SourceLocationMixin,
12 // SourceLocationMixin couldn't implement SourceLocation. In SourceSpan we
13 // handle this by making the class itself non-extensible, but that would be a
14 // breaking change for SourceLocation. So until we want to endure the pain of
15 // cutting a release with breaking changes, we duplicate the code here.
16
17 /// A mixin for easily implementing [SourceLocation].
18 abstract class SourceLocationMixin implements SourceLocation {
19 String get toolString {
20 var source = sourceUrl == null ? 'unknown source' : sourceUrl;
21 return '$source:${line + 1}:${column + 1}';
22 }
23
24 int distance(SourceLocation other) {
25 if (sourceUrl != other.sourceUrl) {
26 throw new ArgumentError("Source URLs \"${sourceUrl}\" and "
27 "\"${other.sourceUrl}\" don't match.");
28 }
29 return (offset - other.offset).abs();
30 }
31
32 SourceSpan pointSpan() => new SourceSpan(this, this, "");
33
34 int compareTo(SourceLocation other) {
35 if (sourceUrl != other.sourceUrl) {
36 throw new ArgumentError("Source URLs \"${sourceUrl}\" and "
37 "\"${other.sourceUrl}\" don't match.");
38 }
39 return offset - other.offset;
40 }
41
42 bool operator ==(other) =>
43 other is SourceLocation && sourceUrl == other.sourceUrl &&
Bob Nystrom 2015/09/02 19:39:50 Split after the first "&&" too.
nweiz 2015/09/02 20:33:05 Done.
44 offset == other.offset;
45
46 int get hashCode => sourceUrl.hashCode + offset;
47
48 String toString() => '<$runtimeType: $offset $toolString>';
49 }
50
OLDNEW
« no previous file with comments | « lib/src/location.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698