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

Unified Diff: pkg/compiler/lib/src/io/source_information.dart

Issue 2788373002: Add Source.getTextLine and use it to display source snippets in error messages. (Closed)
Patch Set: dartfmt 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/io/source_information.dart
diff --git a/pkg/compiler/lib/src/io/source_information.dart b/pkg/compiler/lib/src/io/source_information.dart
index 2b01ba12b585de0ad27c5f8b65d432c5b816c4ab..a2e1a5f9b4f822fe50d22fc610940e8fccfddefe 100644
--- a/pkg/compiler/lib/src/io/source_information.dart
+++ b/pkg/compiler/lib/src/io/source_information.dart
@@ -4,6 +4,7 @@
library dart2js.source_information;
+import 'package:kernel/ast.dart' show Location;
import '../common.dart';
import '../elements/elements.dart'
show
@@ -202,7 +203,7 @@ abstract class SourceLocation {
/// A location in a source file.
abstract class AbstractSourceLocation extends SourceLocation {
final SourceFile _sourceFile;
- int _line;
+ Location _location;
AbstractSourceLocation(this._sourceFile) {
assert(invariant(new SourceSpan(sourceUri, 0, 0), isValid,
@@ -218,12 +219,15 @@ abstract class AbstractSourceLocation extends SourceLocation {
/// The 0-based line number of the [offset].
int get line {
- if (_line == null) _line = _sourceFile.getLine(offset);
- return _line;
+ _location ??= _sourceFile.getLocation(offset);
+ return _location.line - 1;
}
/// The 0-base column number of the [offset] with its line.
- int get column => _sourceFile.getColumn(line, offset);
+ int get column {
+ _location ??= _sourceFile.getLocation(offset);
+ return _location.column - 1;
+ }
/// The name associated with this source location, if any.
String get sourceName;

Powered by Google App Engine
This is Rietveld 408576698