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

Side by Side Diff: lib/src/file.dart

Issue 1307123004: Add SourceLocationMixin and SourceLocationBase. (Closed) Base URL: git@github.com:dart-lang/source_span@master
Patch Set: Code review changes 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 | « lib/source_span.dart ('k') | lib/src/location.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 source_span.file; 5 library source_span.file;
6 6
7 import 'dart:math' as math; 7 import 'dart:math' as math;
8 import 'dart:typed_data'; 8 import 'dart:typed_data';
9 9
10 import 'location.dart'; 10 import 'location.dart';
11 import 'location_mixin.dart';
11 import 'span.dart'; 12 import 'span.dart';
12 import 'span_mixin.dart'; 13 import 'span_mixin.dart';
13 import 'span_with_context.dart'; 14 import 'span_with_context.dart';
14 15
15 // Constants to determine end-of-lines. 16 // Constants to determine end-of-lines.
16 const int _LF = 10; 17 const int _LF = 10;
17 const int _CR = 13; 18 const int _CR = 13;
18 19
19 /// A class representing a source file. 20 /// A class representing a source file.
20 /// 21 ///
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 String getText(int start, [int end]) => 206 String getText(int start, [int end]) =>
206 new String.fromCharCodes(_decodedChars.sublist(start, end)); 207 new String.fromCharCodes(_decodedChars.sublist(start, end));
207 } 208 }
208 209
209 /// A [SourceLocation] within a [SourceFile]. 210 /// A [SourceLocation] within a [SourceFile].
210 /// 211 ///
211 /// Unlike the base [SourceLocation], [FileLocation] lazily computes its line 212 /// Unlike the base [SourceLocation], [FileLocation] lazily computes its line
212 /// and column values based on its offset and the contents of [file]. 213 /// and column values based on its offset and the contents of [file].
213 /// 214 ///
214 /// A [FileLocation] can be created using [SourceFile.location]. 215 /// A [FileLocation] can be created using [SourceFile.location].
215 class FileLocation extends SourceLocation { 216 class FileLocation extends SourceLocationMixin implements SourceLocation {
216 /// The [file] that [this] belongs to. 217 /// The [file] that [this] belongs to.
217 final SourceFile file; 218 final SourceFile file;
218 219
220 final int offset;
219 Uri get sourceUrl => file.url; 221 Uri get sourceUrl => file.url;
220 int get line => file.getLine(offset); 222 int get line => file.getLine(offset);
221 int get column => file.getColumn(offset); 223 int get column => file.getColumn(offset);
222 224
223 FileLocation._(this.file, int offset) 225 FileLocation._(this.file, this.offset) {
224 : super(offset) { 226 if (offset < 0) {
225 if (offset > file.length) { 227 throw new RangeError("Offset may not be negative, was $offset.");
228 } else if (offset > file.length) {
226 throw new RangeError("Offset $offset must not be greater than the number " 229 throw new RangeError("Offset $offset must not be greater than the number "
227 "of characters in the file, ${file.length}."); 230 "of characters in the file, ${file.length}.");
228 } 231 }
229 } 232 }
230 233
231 FileSpan pointSpan() => new _FileSpan(file, offset, offset); 234 FileSpan pointSpan() => new _FileSpan(file, offset, offset);
232 } 235 }
233 236
234 /// A [SourceSpan] within a [SourceFile]. 237 /// A [SourceSpan] within a [SourceFile].
235 /// 238 ///
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 var start = math.min(this._start, other._start); 346 var start = math.min(this._start, other._start);
344 var end = math.max(this._end, other._end); 347 var end = math.max(this._end, other._end);
345 return new _FileSpan(file, start, end); 348 return new _FileSpan(file, start, end);
346 } else { 349 } else {
347 var start = math.min(this._start, other.start.offset); 350 var start = math.min(this._start, other.start.offset);
348 var end = math.max(this._end, other.end.offset); 351 var end = math.max(this._end, other.end.offset);
349 return new _FileSpan(file, start, end); 352 return new _FileSpan(file, start, end);
350 } 353 }
351 } 354 }
352 } 355 }
OLDNEW
« no previous file with comments | « lib/source_span.dart ('k') | lib/src/location.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698