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

Side by Side Diff: pkg/analyzer/lib/src/generated/source.dart

Issue 1625783002: Rework recent changes to LineInfo to be backward compatible. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 | « pkg/analysis_server/lib/src/status/get_handler.dart ('k') | no next file » | 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 analyzer.src.generated.source; 5 library analyzer.src.generated.source;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 /** 190 /**
191 * The zero-based [_lineStarts] index resulting from the last call to 191 * The zero-based [_lineStarts] index resulting from the last call to
192 * [getLocation]. 192 * [getLocation].
193 */ 193 */
194 int _previousLine = 0; 194 int _previousLine = 0;
195 195
196 /** 196 /**
197 * Initialize a newly created set of line information to represent the data 197 * Initialize a newly created set of line information to represent the data
198 * encoded in the given list of [_lineStarts]. 198 * encoded in the given list of [_lineStarts].
199 */ 199 */
200 LineInfo(this._lineStarts) { 200 factory LineInfo(List<int> _lineStarts) => new LineInfoWithCount(_lineStarts);
201
202 /**
203 * Initialize a newly created set of line information to represent the data
204 * encoded in the given list of [_lineStarts].
205 */
206 LineInfo._(this._lineStarts) {
201 if (_lineStarts == null) { 207 if (_lineStarts == null) {
202 throw new IllegalArgumentException("lineStarts must be non-null"); 208 throw new IllegalArgumentException("lineStarts must be non-null");
203 } else if (_lineStarts.length < 1) { 209 } else if (_lineStarts.length < 1) {
204 throw new IllegalArgumentException("lineStarts must be non-empty"); 210 throw new IllegalArgumentException("lineStarts must be non-empty");
205 } 211 }
206 } 212 }
207 213
208 /** 214 /**
209 * Return the number of lines in the file.
210 */
211 int get lineCount => _lineStarts.length;
212
213 /**
214 * Return the location information for the character at the given [offset]. 215 * Return the location information for the character at the given [offset].
215 */ 216 */
216 LineInfo_Location getLocation(int offset) { 217 LineInfo_Location getLocation(int offset) {
217 var min = 0; 218 var min = 0;
218 var max = _lineStarts.length - 1; 219 var max = _lineStarts.length - 1;
219 220
220 // Subsequent calls to [getLocation] are often for offsets near each other. 221 // Subsequent calls to [getLocation] are often for offsets near each other.
221 // To take advantage of that, we cache the index of the line start we found 222 // To take advantage of that, we cache the index of the line start we found
222 // when this was last called. If the current offset is on that line or 223 // when this was last called. If the current offset is on that line or
223 // later, we'll skip those early indices completely when searching. 224 // later, we'll skip those early indices completely when searching.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 * @param lineNumber the one-based index of the line containing the character 282 * @param lineNumber the one-based index of the line containing the character
282 * @param columnNumber the one-based index of the column containing the charac ter 283 * @param columnNumber the one-based index of the column containing the charac ter
283 */ 284 */
284 LineInfo_Location(this.lineNumber, this.columnNumber); 285 LineInfo_Location(this.lineNumber, this.columnNumber);
285 286
286 @override 287 @override
287 String toString() => '$lineNumber:$columnNumber'; 288 String toString() => '$lineNumber:$columnNumber';
288 } 289 }
289 290
290 /** 291 /**
292 * Information about line and column information within a source file,
293 * including a count of the total number of lines.
294 *
295 * TODO(paulberry): in the next major version roll of analyzer, merge this
296 * class into [LineInfo].
297 */
298 class LineInfoWithCount extends LineInfo {
299 /**
300 * Initialize a newly created set of line information to represent the data
301 * encoded in the given list of [_lineStarts].
302 */
303 LineInfoWithCount(List<int> _lineStarts) : super._(_lineStarts);
304
305 /**
306 * Return the number of lines in the file.
307 */
308 int get lineCount => _lineStarts.length;
309 }
310
311 /**
291 * Instances of interface `LocalSourcePredicate` are used to determine if the gi ven 312 * Instances of interface `LocalSourcePredicate` are used to determine if the gi ven
292 * [Source] is "local" in some sense, so can be updated. 313 * [Source] is "local" in some sense, so can be updated.
293 */ 314 */
294 abstract class LocalSourcePredicate { 315 abstract class LocalSourcePredicate {
295 /** 316 /**
296 * Instance of [LocalSourcePredicate] that always returns `false`. 317 * Instance of [LocalSourcePredicate] that always returns `false`.
297 */ 318 */
298 static final LocalSourcePredicate FALSE = new LocalSourcePredicate_FALSE(); 319 static final LocalSourcePredicate FALSE = new LocalSourcePredicate_FALSE();
299 320
300 /** 321 /**
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 Source resolveAbsolute(Uri uri, [Uri actualUri]); 1117 Source resolveAbsolute(Uri uri, [Uri actualUri]);
1097 1118
1098 /** 1119 /**
1099 * Return an absolute URI that represents the given [source], or `null` if a 1120 * Return an absolute URI that represents the given [source], or `null` if a
1100 * valid URI cannot be computed. 1121 * valid URI cannot be computed.
1101 * 1122 *
1102 * The computation should be based solely on [source.fullName]. 1123 * The computation should be based solely on [source.fullName].
1103 */ 1124 */
1104 Uri restoreAbsolute(Source source) => null; 1125 Uri restoreAbsolute(Source source) => null;
1105 } 1126 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/status/get_handler.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698