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

Side by Side Diff: pkg/source_maps/lib/span.dart

Issue 402843003: Deprecate the source_maps span classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add -dev to version Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « pkg/source_maps/lib/refactor.dart ('k') | pkg/source_maps/lib/src/span_wrapper.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) 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; 10 import 'package:path/path.dart' as p;
11 11
12 import 'src/utils.dart'; 12 import 'src/utils.dart';
13 13
14 /// A simple class that describe a segment of source text. 14 /// A simple class that describe a segment of source text.
15 @Deprecated("Use the source_span package instead.")
15 abstract class Span implements Comparable { 16 abstract class Span implements Comparable {
16 /// The start location of this span. 17 /// The start location of this span.
17 final Location start; 18 final Location start;
18 19
19 /// The end location of this span, exclusive. 20 /// The end location of this span, exclusive.
20 final Location end; 21 final Location end;
21 22
22 /// Url of the source (typically a file) containing this span. 23 /// Url of the source (typically a file) containing this span.
23 String get sourceUrl => start.sourceUrl; 24 String get sourceUrl => start.sourceUrl;
24 25
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 73
73 bool operator ==(Span other) => 74 bool operator ==(Span other) =>
74 sourceUrl == other.sourceUrl && start == other.start && end == other.end; 75 sourceUrl == other.sourceUrl && start == other.start && end == other.end;
75 76
76 int get hashCode => sourceUrl.hashCode + start.offset + (31 * length); 77 int get hashCode => sourceUrl.hashCode + start.offset + (31 * length);
77 78
78 String toString() => '<$runtimeType: $start $end $formatLocation $text>'; 79 String toString() => '<$runtimeType: $start $end $formatLocation $text>';
79 } 80 }
80 81
81 /// A location in the source text 82 /// A location in the source text
83 @Deprecated("Use the source_span package instead.")
82 abstract class Location implements Comparable { 84 abstract class Location implements Comparable {
83 /// Url of the source containing this span. 85 /// Url of the source containing this span.
84 String get sourceUrl; 86 String get sourceUrl;
85 87
86 /// The offset of this location, 0-based. 88 /// The offset of this location, 0-based.
87 final int offset; 89 final int offset;
88 90
89 /// The 0-based line in the source of this location. 91 /// The 0-based line in the source of this location.
90 int get line; 92 int get line;
91 93
(...skipping 14 matching lines...) Expand all
106 bool operator ==(Location other) => 108 bool operator ==(Location other) =>
107 sourceUrl == other.sourceUrl && offset == other.offset; 109 sourceUrl == other.sourceUrl && offset == other.offset;
108 110
109 int get hashCode => sourceUrl.hashCode + offset; 111 int get hashCode => sourceUrl.hashCode + offset;
110 112
111 String toString() => '(Location $offset)'; 113 String toString() => '(Location $offset)';
112 String get formatString => '$sourceUrl:${line + 1}:${column + 1}'; 114 String get formatString => '$sourceUrl:${line + 1}:${column + 1}';
113 } 115 }
114 116
115 /// Implementation of [Location] with fixed values given at allocation time. 117 /// Implementation of [Location] with fixed values given at allocation time.
118 @Deprecated("Use the source_span package instead.")
116 class FixedLocation extends Location { 119 class FixedLocation extends Location {
117 final String sourceUrl; 120 final String sourceUrl;
118 final int line; 121 final int line;
119 final int column; 122 final int column;
120 123
121 FixedLocation(int offset, this.sourceUrl, this.line, this.column) 124 FixedLocation(int offset, this.sourceUrl, this.line, this.column)
122 : super(offset); 125 : super(offset);
123 } 126 }
124 127
125 /// Implementation of [Span] where all the values are given at allocation time. 128 /// Implementation of [Span] where all the values are given at allocation time.
129 @Deprecated("Use the source_span package instead.")
126 class FixedSpan extends Span { 130 class FixedSpan extends Span {
127 /// The source text for this span, if available. 131 /// The source text for this span, if available.
128 final String text; 132 final String text;
129 133
130 /// Creates a span which starts and end in the same line. 134 /// Creates a span which starts and end in the same line.
131 FixedSpan(String sourceUrl, int start, int line, int column, 135 FixedSpan(String sourceUrl, int start, int line, int column,
132 {String text: '', bool isIdentifier: false}) 136 {String text: '', bool isIdentifier: false})
133 : text = text, super(new FixedLocation(start, sourceUrl, line, column), 137 : text = text, super(new FixedLocation(start, sourceUrl, line, column),
134 new FixedLocation(start + text.length, sourceUrl, line, 138 new FixedLocation(start + text.length, sourceUrl, line,
135 column + text.length), 139 column + text.length),
136 isIdentifier); 140 isIdentifier);
137 } 141 }
138 142
139 /// [Location] with values computed from an underling [SourceFile]. 143 /// [Location] with values computed from an underling [SourceFile].
144 @Deprecated("Use the source_span package instead.")
140 class FileLocation extends Location { 145 class FileLocation extends Location {
141 /// The source file containing this location. 146 /// The source file containing this location.
142 final SourceFile file; 147 final SourceFile file;
143 148
144 String get sourceUrl => file.url; 149 String get sourceUrl => file.url;
145 int get line => file.getLine(offset); 150 int get line => file.getLine(offset);
146 int get column => file.getColumn(line, offset); 151 int get column => file.getColumn(line, offset);
147 152
148 FileLocation(this.file, int offset): super(offset); 153 FileLocation(this.file, int offset): super(offset);
149 } 154 }
150 155
151 /// [Span] where values are computed from an underling [SourceFile]. 156 /// [Span] where values are computed from an underling [SourceFile].
157 @Deprecated("Use the source_span package instead.")
152 class FileSpan extends Span { 158 class FileSpan extends Span {
153 /// The source file containing this span. 159 /// The source file containing this span.
154 final SourceFile file; 160 final SourceFile file;
155 161
156 /// The source text for this span, if available. 162 /// The source text for this span, if available.
157 String get text => file.getText(start.offset, end.offset); 163 String get text => file.getText(start.offset, end.offset);
158 164
159 factory FileSpan(SourceFile file, int start, 165 factory FileSpan(SourceFile file, int start,
160 [int end, bool isIdentifier = false]) { 166 [int end, bool isIdentifier = false]) {
161 var startLoc = new FileLocation(file, start); 167 var startLoc = new FileLocation(file, start);
(...skipping 26 matching lines...) Expand all
188 const int _LF = 10; 194 const int _LF = 10;
189 const int _CR = 13; 195 const int _CR = 13;
190 196
191 // Color constants used for generating messages. 197 // Color constants used for generating messages.
192 const String _RED_COLOR = '\u001b[31m'; 198 const String _RED_COLOR = '\u001b[31m';
193 const String _NO_COLOR = '\u001b[0m'; 199 const String _NO_COLOR = '\u001b[0m';
194 200
195 /// Stores information about a source file, to permit computation of the line 201 /// Stores information about a source file, to permit computation of the line
196 /// and column. Also contains a nice default error message highlighting the code 202 /// and column. Also contains a nice default error message highlighting the code
197 /// location. 203 /// location.
204 @Deprecated("Use the source_span package instead.")
198 class SourceFile { 205 class SourceFile {
199 /// Url where the source file is located. 206 /// Url where the source file is located.
200 final String url; 207 final String url;
201 final List<int> _lineStarts; 208 final List<int> _lineStarts;
202 final List<int> _decodedChars; 209 final List<int> _decodedChars;
203 210
204 SourceFile(this.url, this._lineStarts, this._decodedChars); 211 SourceFile(this.url, this._lineStarts, this._decodedChars);
205 212
206 SourceFile.text(this.url, String text) 213 SourceFile.text(this.url, String text)
207 : _lineStarts = <int>[0], 214 : _lineStarts = <int>[0],
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 if (useColors) buf.write(_NO_COLOR); 306 if (useColors) buf.write(_NO_COLOR);
300 return buf.toString(); 307 return buf.toString();
301 } 308 }
302 } 309 }
303 310
304 /// A convenience type to treat a code segment as if it were a separate 311 /// A convenience type to treat a code segment as if it were a separate
305 /// [SourceFile]. A [SourceFileSegment] shifts all locations by an offset, which 312 /// [SourceFile]. A [SourceFileSegment] shifts all locations by an offset, which
306 /// allows you to set source-map locations based on the locations relative to 313 /// allows you to set source-map locations based on the locations relative to
307 /// the start of the segment, but that get translated to absolute locations in 314 /// the start of the segment, but that get translated to absolute locations in
308 /// the original source file. 315 /// the original source file.
316 @Deprecated("Use the source_span package instead.")
309 class SourceFileSegment extends SourceFile { 317 class SourceFileSegment extends SourceFile {
310 final int _baseOffset; 318 final int _baseOffset;
311 final int _baseLine; 319 final int _baseLine;
312 final int _baseColumn; 320 final int _baseColumn;
313 final int _maxOffset; 321 final int _maxOffset;
314 322
315 SourceFileSegment(String url, String textSegment, Location startOffset) 323 SourceFileSegment(String url, String textSegment, Location startOffset)
316 : _baseOffset = startOffset.offset, 324 : _baseOffset = startOffset.offset,
317 _baseLine = startOffset.line, 325 _baseLine = startOffset.line,
318 _baseColumn = startOffset.column, 326 _baseColumn = startOffset.column,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 line == _baseLine ? column - _baseColumn : column) + _baseOffset; 366 line == _baseLine ? column - _baseColumn : column) + _baseOffset;
359 367
360 /// Retrieve the text associated with the specified range. This method 368 /// Retrieve the text associated with the specified range. This method
361 /// operates on the real offsets from the original file, so that error 369 /// operates on the real offsets from the original file, so that error
362 /// messages can be reported accurately. 370 /// messages can be reported accurately.
363 String getText(int start, [int end]) => 371 String getText(int start, [int end]) =>
364 super.getText(start - _baseOffset, end == null ? null : end - _baseOffset); 372 super.getText(start - _baseOffset, end == null ? null : end - _baseOffset);
365 } 373 }
366 374
367 /// A class for exceptions that have source span information attached. 375 /// A class for exceptions that have source span information attached.
376 @Deprecated("Use the source_span package instead.")
368 class SpanException implements Exception { 377 class SpanException implements Exception {
369 /// A message describing the exception. 378 /// A message describing the exception.
370 final String message; 379 final String message;
371 380
372 /// The span associated with this exception. 381 /// The span associated with this exception.
373 /// 382 ///
374 /// This may be `null` if the source location can't be determined. 383 /// This may be `null` if the source location can't be determined.
375 final Span span; 384 final Span span;
376 385
377 SpanException(this.message, this.span); 386 SpanException(this.message, this.span);
378 387
379 String toString({bool useColors: false, String color}) { 388 String toString({bool useColors: false, String color}) {
380 if (span == null) return message; 389 if (span == null) return message;
381 return "Error on " + span.getLocationMessage(message, 390 return "Error on " + span.getLocationMessage(message,
382 useColors: useColors, color: color); 391 useColors: useColors, color: color);
383 } 392 }
384 } 393 }
385 394
386 /// A [SpanException] that's also a [FormatException]. 395 /// A [SpanException] that's also a [FormatException].
396 @Deprecated("Use the source_span package instead.")
387 class SpanFormatException extends SpanException implements FormatException { 397 class SpanFormatException extends SpanException implements FormatException {
388 final source; 398 final source;
389 399
390 SpanFormatException(String message, Span span, [this.source]) 400 SpanFormatException(String message, Span span, [this.source])
391 : super(message, span); 401 : super(message, span);
392 402
393 int get offset => span == null ? null : span.start.offset; 403 int get offset => span == null ? null : span.start.offset;
394 } 404 }
OLDNEW
« no previous file with comments | « pkg/source_maps/lib/refactor.dart ('k') | pkg/source_maps/lib/src/span_wrapper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698