OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.messages; | 5 library fasta.messages; |
6 | 6 |
7 import 'package:kernel/ast.dart' show Location; | 7 import 'package:kernel/ast.dart' show Library, Location, Program, TreeNode; |
8 | 8 |
9 import 'util/relativize.dart' show relativizeUri; | 9 import 'util/relativize.dart' show relativizeUri; |
10 | 10 |
11 import 'compiler_context.dart' show CompilerContext; | 11 import 'compiler_context.dart' show CompilerContext; |
12 | 12 |
13 import 'errors.dart' show InputError; | 13 import 'errors.dart' show InputError; |
14 | 14 |
15 import 'colors.dart' show cyan, magenta; | 15 import 'colors.dart' show cyan, magenta; |
16 | 16 |
17 const bool hideWarnings = false; | 17 const bool hideWarnings = false; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 if (charOffset == -1) return null; | 85 if (charOffset == -1) return null; |
86 String path = relativizeUri(uri); | 86 String path = relativizeUri(uri); |
87 return getLocation(path, charOffset); | 87 return getLocation(path, charOffset); |
88 } | 88 } |
89 | 89 |
90 String getSourceLine(Location location) { | 90 String getSourceLine(Location location) { |
91 if (location == null) return null; | 91 if (location == null) return null; |
92 return CompilerContext.current.uriToSource[location.file] | 92 return CompilerContext.current.uriToSource[location.file] |
93 ?.getTextLine(location.line); | 93 ?.getTextLine(location.line); |
94 } | 94 } |
95 | |
96 Location getLocationFromNode(TreeNode node) { | |
97 if (node.enclosingProgram == null) { | |
98 TreeNode parent = node; | |
99 while (parent != null && parent is! Library) { | |
100 parent = parent.parent; | |
101 } | |
102 if (parent is Library) { | |
103 // ignore: UNUSED_LOCAL_VARIABLE | |
104 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
| |
105 libraries: <Library>[parent], | |
106 uriToSource: CompilerContext.current.uriToSource); | |
107 Location result = node.location; | |
108 parent.parent = null; | |
109 return result; | |
110 } else { | |
111 return null; | |
112 } | |
113 } else { | |
114 return node.location; | |
115 } | |
116 } | |
OLD | NEW |