Chromium Code Reviews| Index: pkg/kernel/lib/ast.dart |
| diff --git a/pkg/kernel/lib/ast.dart b/pkg/kernel/lib/ast.dart |
| index 0112b5a7286a9cfd651dfbe5f032e6e43bbf8ae5..9b531d7b8b92a6b947a902ec23dd98f4545a909e 100644 |
| --- a/pkg/kernel/lib/ast.dart |
| +++ b/pkg/kernel/lib/ast.dart |
| @@ -50,6 +50,8 @@ |
| /// |
| library kernel.ast; |
| +import 'dart:convert' show UTF8; |
| + |
| import 'visitor.dart'; |
| export 'visitor.dart'; |
| @@ -4228,9 +4230,36 @@ class _ChildReplacer extends Transformer { |
| class Source { |
| final List<int> lineStarts; |
| + |
| final List<int> source; |
| + String cachedText; |
| + |
| Source(this.lineStarts, this.source); |
| + |
| + /// Return the text corresponding to [line] which is a 1-based line number. |
| + String getTextLine(int line) { |
| + RangeError.checkValueInInterval( |
| + line, |
| + 1, |
| + lineStarts.length, |
| + "line", |
| + "The value of 'line' ($line) must be between 1 and " |
| + "${lineStarts.length}."); |
| + if (source == null) return null; |
| + |
| + // -1 as line numbers start at 1. |
| + int index = line - 1; |
| + if (index + 1 == lineStarts.length) { |
| + // Last line. |
| + return cachedText.substring(lineStarts[index]); |
|
asgerf
2017/04/03 08:34:55
cachedText could be null here. The initialization
ahe
2017/04/03 09:26:39
Done.
|
| + } else if (index < lineStarts.length) { |
| + cachedText ??= UTF8.decode(source, allowMalformed: true); |
| + return cachedText.substring(lineStarts[index], lineStarts[index + 1]); |
| + } |
| + // This shouldn't happen: should have been caught by the range check above. |
| + throw "Internal error"; |
| + } |
| } |
| /// Returns the [Reference] object for the given member. |