OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Dart classes representing the souce spans and source files. | 5 /// Dart classes representing the souce spans and source files. |
6 library source_maps.span; | 6 library source_maps.span; |
7 | 7 |
8 import 'dart:math' show min, max; | 8 import 'dart:math' show min, max; |
9 | 9 |
| 10 import 'package:path/path.dart' as p; |
| 11 |
10 import 'src/utils.dart'; | 12 import 'src/utils.dart'; |
11 | 13 |
12 /// A simple class that describe a segment of source text. | 14 /// A simple class that describe a segment of source text. |
13 abstract class Span implements Comparable { | 15 abstract class Span implements Comparable { |
14 /// The start location of this span. | 16 /// The start location of this span. |
15 final Location start; | 17 final Location start; |
16 | 18 |
17 /// The end location of this span, exclusive. | 19 /// The end location of this span, exclusive. |
18 final Location end; | 20 final Location end; |
19 | 21 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 new String.fromCharCodes(_decodedChars.sublist(max(start, 0), end)); | 247 new String.fromCharCodes(_decodedChars.sublist(max(start, 0), end)); |
246 | 248 |
247 /// Create a pretty string representation from a span. | 249 /// Create a pretty string representation from a span. |
248 String getLocationMessage(String message, int start, int end, | 250 String getLocationMessage(String message, int start, int end, |
249 {bool useColors: false, String color}) { | 251 {bool useColors: false, String color}) { |
250 // TODO(jmesserly): it would be more useful to pass in an object that | 252 // TODO(jmesserly): it would be more useful to pass in an object that |
251 // controls how the errors are printed. This method is a bit too smart. | 253 // controls how the errors are printed. This method is a bit too smart. |
252 var line = getLine(start); | 254 var line = getLine(start); |
253 var column = getColumn(line, start); | 255 var column = getColumn(line, start); |
254 | 256 |
255 var src = url == null ? '' : url; | 257 var source = url == null ? '' : ' of ${p.prettyUri(url)}'; |
256 var msg = '$src:${line + 1}:${column + 1}: $message'; | 258 var msg = 'line ${line + 1}, column ${column + 1}$source: $message'; |
257 | 259 |
258 if (_decodedChars == null) { | 260 if (_decodedChars == null) { |
259 // We don't have any text to include, so exit. | 261 // We don't have any text to include, so exit. |
260 return msg; | 262 return msg; |
261 } | 263 } |
262 | 264 |
263 var buf = new StringBuffer(msg); | 265 var buf = new StringBuffer(msg); |
264 buf.write('\n'); | 266 buf.write('\n'); |
265 | 267 |
266 // +1 for 0-indexing, +1 again to avoid the last line | 268 // +1 for 0-indexing, +1 again to avoid the last line |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 int getOffset(int line, int column) => | 353 int getOffset(int line, int column) => |
352 super.getOffset(line - _baseLine, | 354 super.getOffset(line - _baseLine, |
353 line == _baseLine ? column - _baseColumn : column) + _baseOffset; | 355 line == _baseLine ? column - _baseColumn : column) + _baseOffset; |
354 | 356 |
355 /// Retrieve the text associated with the specified range. This method | 357 /// Retrieve the text associated with the specified range. This method |
356 /// operates on the real offsets from the original file, so that error | 358 /// operates on the real offsets from the original file, so that error |
357 /// messages can be reported accurately. | 359 /// messages can be reported accurately. |
358 String getText(int start, [int end]) => | 360 String getText(int start, [int end]) => |
359 super.getText(start - _baseOffset, end == null ? null : end - _baseOffset); | 361 super.getText(start - _baseOffset, end == null ? null : end - _baseOffset); |
360 } | 362 } |
OLD | NEW |