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

Side by Side Diff: pkg/compiler/lib/src/io/source_file.dart

Issue 2788373002: Add Source.getTextLine and use it to display source snippets in error messages. (Closed)
Patch Set: Created 3 years, 8 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 | « no previous file | pkg/front_end/lib/src/fasta/messages.dart » ('j') | pkg/kernel/lib/ast.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart2js.io.source_file; 5 library dart2js.io.source_file;
6 6
7 import 'dart:convert' show UTF8; 7 import 'dart:convert' show UTF8;
8 import 'dart:math'; 8 import 'dart:math';
9 import 'dart:typed_data' show Uint8List; 9 import 'dart:typed_data' show Uint8List;
10 10
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 186 }
187 } 187 }
188 188
189 return buf.toString(); 189 return buf.toString();
190 } 190 }
191 191
192 int get lines => lineStarts.length - 1; 192 int get lines => lineStarts.length - 1;
193 193
194 /// Returns the text of line at the 0-based [index] within this source file. 194 /// Returns the text of line at the 0-based [index] within this source file.
195 String getLineText(int index) { 195 String getLineText(int index) {
196 // TODO(ahe): This functionality can be replaced by `Source.getTextLine` in
197 // [package:kernel/ast.dart](../../../../kernel/lib/ast.dart).
asgerf 2017/04/03 08:34:55 Any reason not to resolve this now?
ahe 2017/04/03 09:26:39 I hadn't realized how easy that was before you ask
198
196 // +1 for 0-indexing, +1 again to avoid the last line of the file 199 // +1 for 0-indexing, +1 again to avoid the last line of the file
197 if ((index + 2) < lineStarts.length) { 200 if ((index + 2) < lineStarts.length) {
198 return slowSubstring(lineStarts[index], lineStarts[index + 1]); 201 return slowSubstring(lineStarts[index], lineStarts[index + 1]);
199 } else if ((index + 1) < lineStarts.length) { 202 } else if ((index + 1) < lineStarts.length) {
200 return '${slowSubstring(lineStarts[index], length)}\n'; 203 return '${slowSubstring(lineStarts[index], length)}\n';
201 } else { 204 } else {
202 throw new ArgumentError("Line index $index is out of bounds."); 205 throw new ArgumentError("Line index $index is out of bounds.");
203 } 206 }
204 } 207 }
205 } 208 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 set length(int v) {} 288 set length(int v) {}
286 289
287 String slowText() => text; 290 String slowText() => text;
288 291
289 List<int> slowUtf8ZeroTerminatedBytes() { 292 List<int> slowUtf8ZeroTerminatedBytes() {
290 return _zeroTerminateIfNecessary(UTF8.encode(text)); 293 return _zeroTerminateIfNecessary(UTF8.encode(text));
291 } 294 }
292 295
293 String slowSubstring(int start, int end) => text.substring(start, end); 296 String slowSubstring(int start, int end) => text.substring(start, end);
294 } 297 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/messages.dart » ('j') | pkg/kernel/lib/ast.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698