| OLD | NEW |
| 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 '../tokens/token.dart' show | 7 import '../tokens/token.dart' show Token; |
| 8 Token; | 8 import '../tree/tree.dart' show Node; |
| 9 import '../tree/tree.dart' show | 9 import 'spannable.dart' show Spannable; |
| 10 Node; | |
| 11 import 'spannable.dart' show | |
| 12 Spannable; | |
| 13 | 10 |
| 14 class SourceSpan implements Spannable { | 11 class SourceSpan implements Spannable { |
| 15 final Uri uri; | 12 final Uri uri; |
| 16 final int begin; | 13 final int begin; |
| 17 final int end; | 14 final int end; |
| 18 | 15 |
| 19 const SourceSpan(this.uri, this.begin, this.end); | 16 const SourceSpan(this.uri, this.begin, this.end); |
| 20 | 17 |
| 21 factory SourceSpan.fromNode(Uri uri, Node node) { | 18 factory SourceSpan.fromNode(Uri uri, Node node) { |
| 22 return new SourceSpan.fromTokens( | 19 return new SourceSpan.fromTokens( |
| 23 uri, node.getBeginToken(), node.getPrefixEndToken()); | 20 uri, node.getBeginToken(), node.getPrefixEndToken()); |
| 24 } | 21 } |
| 25 | 22 |
| 26 factory SourceSpan.fromTokens(Uri uri, Token begin, Token end) { | 23 factory SourceSpan.fromTokens(Uri uri, Token begin, Token end) { |
| 27 final beginOffset = begin.charOffset; | 24 final beginOffset = begin.charOffset; |
| 28 final endOffset = end.charOffset + end.charCount; | 25 final endOffset = end.charOffset + end.charCount; |
| 29 | 26 |
| 30 // [begin] and [end] might be the same for the same empty token. This | 27 // [begin] and [end] might be the same for the same empty token. This |
| 31 // happens for instance when scanning '$$'. | 28 // happens for instance when scanning '$$'. |
| 32 assert(endOffset >= beginOffset); | 29 assert(endOffset >= beginOffset); |
| 33 return new SourceSpan(uri, beginOffset, endOffset); | 30 return new SourceSpan(uri, beginOffset, endOffset); |
| 34 } | 31 } |
| 35 | 32 |
| 36 int get hashCode { | 33 int get hashCode { |
| 37 return 13 * uri.hashCode + | 34 return 13 * uri.hashCode + 17 * begin.hashCode + 19 * end.hashCode; |
| 38 17 * begin.hashCode + | |
| 39 19 * end.hashCode; | |
| 40 } | 35 } |
| 41 | 36 |
| 42 bool operator ==(other) { | 37 bool operator ==(other) { |
| 43 if (identical(this, other)) return true; | 38 if (identical(this, other)) return true; |
| 44 if (other is! SourceSpan) return false; | 39 if (other is! SourceSpan) return false; |
| 45 return uri == other.uri && | 40 return uri == other.uri && begin == other.begin && end == other.end; |
| 46 begin == other.begin && | |
| 47 end == other.end; | |
| 48 } | 41 } |
| 49 | 42 |
| 50 String toString() => 'SourceSpan($uri, $begin, $end)'; | 43 String toString() => 'SourceSpan($uri, $begin, $end)'; |
| 51 } | 44 } |
| OLD | NEW |