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