Chromium Code Reviews| Index: pkg/front_end/lib/src/fasta/messages.dart |
| diff --git a/pkg/front_end/lib/src/fasta/messages.dart b/pkg/front_end/lib/src/fasta/messages.dart |
| index b48926c00e36537e62891a5895b02c633588c8e4..9cdebc20aeb46ea89ff0e59d1d19f5362c60665c 100644 |
| --- a/pkg/front_end/lib/src/fasta/messages.dart |
| +++ b/pkg/front_end/lib/src/fasta/messages.dart |
| @@ -4,7 +4,7 @@ |
| library fasta.messages; |
| -import 'package:kernel/ast.dart' show Location; |
| +import 'package:kernel/ast.dart' show Library, Location, Program, TreeNode; |
| import 'util/relativize.dart' show relativizeUri; |
| @@ -92,3 +92,25 @@ String getSourceLine(Location location) { |
| return CompilerContext.current.uriToSource[location.file] |
| ?.getTextLine(location.line); |
| } |
| + |
| +Location getLocationFromNode(TreeNode node) { |
| + if (node.enclosingProgram == null) { |
| + TreeNode parent = node; |
| + while (parent != null && parent is! Library) { |
| + parent = parent.parent; |
| + } |
| + if (parent is Library) { |
| + // ignore: UNUSED_LOCAL_VARIABLE |
| + Program program = new Program( |
|
Johnni Winther
2017/06/23 10:51:44
Maybe remove `Program program = ` and add a commen
ahe
2017/06/23 12:21:51
I've changed the code to make it more obvious. IMO
|
| + libraries: <Library>[parent], |
| + uriToSource: CompilerContext.current.uriToSource); |
| + Location result = node.location; |
| + parent.parent = null; |
| + return result; |
| + } else { |
| + return null; |
| + } |
| + } else { |
| + return node.location; |
| + } |
| +} |