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

Side by Side Diff: pkg/compiler/lib/src/diagnostics/source_span.dart

Issue 1314973003: Add support for analyzing individual URIs. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comment 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 | « pkg/compiler/lib/src/compiler.dart ('k') | pkg/compiler/lib/src/elements/elements.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart2js.diagnostics.source_span; 5 library dart2js.diagnostics.source_span;
6 6
7 import '../scanner/scannerlib.dart' show 7 import '../scanner/scannerlib.dart' show
8 Token; 8 Token;
9 import '../tree/tree.dart' show
10 Node;
9 import 'spannable.dart' show 11 import 'spannable.dart' show
10 Spannable; 12 Spannable;
11 13
12 class SourceSpan implements Spannable { 14 class SourceSpan implements Spannable {
13 final Uri uri; 15 final Uri uri;
14 final int begin; 16 final int begin;
15 final int end; 17 final int end;
16 18
17 const SourceSpan(this.uri, this.begin, this.end); 19 const SourceSpan(this.uri, this.begin, this.end);
18 20
19 static withCharacterOffsets(Token begin, Token end, 21 factory SourceSpan.fromNode(Uri uri, Node node) {
20 f(int beginOffset, int endOffset)) { 22 return new SourceSpan.fromTokens(
23 uri, node.getBeginToken(), node.getEndToken());
24 }
25
26 factory SourceSpan.fromTokens(Uri uri, Token begin, Token end) {
21 final beginOffset = begin.charOffset; 27 final beginOffset = begin.charOffset;
22 final endOffset = end.charOffset + end.charCount; 28 final endOffset = end.charOffset + end.charCount;
23 29
24 // [begin] and [end] might be the same for the same empty token. This 30 // [begin] and [end] might be the same for the same empty token. This
25 // happens for instance when scanning '$$'. 31 // happens for instance when scanning '$$'.
26 assert(endOffset >= beginOffset); 32 assert(endOffset >= beginOffset);
27 return f(beginOffset, endOffset); 33 return new SourceSpan(uri, beginOffset, endOffset);
28 } 34 }
29 35
30 int get hashCode { 36 int get hashCode {
31 return 13 * uri.hashCode + 37 return 13 * uri.hashCode +
32 17 * begin.hashCode + 38 17 * begin.hashCode +
33 19 * end.hashCode; 39 19 * end.hashCode;
34 } 40 }
35 41
36 bool operator ==(other) { 42 bool operator ==(other) {
37 if (identical(this, other)) return true; 43 if (identical(this, other)) return true;
38 if (other is! SourceSpan) return false; 44 if (other is! SourceSpan) return false;
39 return uri == other.uri && 45 return uri == other.uri &&
40 begin == other.begin && 46 begin == other.begin &&
41 end == other.end; 47 end == other.end;
42 } 48 }
43 49
44 String toString() => 'SourceSpan($uri, $begin, $end)'; 50 String toString() => 'SourceSpan($uri, $begin, $end)';
45 } 51 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/compiler.dart ('k') | pkg/compiler/lib/src/elements/elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698