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 import 'dart:convert'; | 5 import 'dart:convert'; |
6 import 'dart:typed_data'; | 6 import 'dart:typed_data'; |
7 | 7 |
8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
10 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 | 94 |
95 List<FileState> _importedFiles; | 95 List<FileState> _importedFiles; |
96 List<FileState> _exportedFiles; | 96 List<FileState> _exportedFiles; |
97 List<FileState> _partedFiles; | 97 List<FileState> _partedFiles; |
98 List<NameFilter> _exportFilters; | 98 List<NameFilter> _exportFilters; |
99 | 99 |
100 Set<FileState> _directReferencedFiles = new Set<FileState>(); | 100 Set<FileState> _directReferencedFiles = new Set<FileState>(); |
101 Set<FileState> _transitiveFiles; | 101 Set<FileState> _transitiveFiles; |
102 String _transitiveSignature; | 102 String _transitiveSignature; |
103 | 103 |
104 List<TopLevelDeclaration> _topLevelDeclarations; | 104 Map<String, TopLevelDeclaration> _topLevelDeclarations; |
105 List<TopLevelDeclaration> _exportedTopLevelDeclarations; | 105 Map<String, TopLevelDeclaration> _exportedTopLevelDeclarations; |
106 | 106 |
107 FileState._(this._fsState, this.path, this.uri, this.source); | 107 FileState._(this._fsState, this.path, this.uri, this.source); |
108 | 108 |
109 /** | 109 /** |
110 * The unlinked API signature of the file. | 110 * The unlinked API signature of the file. |
111 */ | 111 */ |
112 List<int> get apiSignature => _apiSignature; | 112 List<int> get apiSignature => _apiSignature; |
113 | 113 |
114 /** | 114 /** |
115 * The content of the file. | 115 * The content of the file. |
(...skipping 10 matching lines...) Expand all Loading... | |
126 * parted. | 126 * parted. |
127 */ | 127 */ |
128 Set<FileState> get directReferencedFiles => _directReferencedFiles; | 128 Set<FileState> get directReferencedFiles => _directReferencedFiles; |
129 | 129 |
130 /** | 130 /** |
131 * The list of files this file exports. | 131 * The list of files this file exports. |
132 */ | 132 */ |
133 List<FileState> get exportedFiles => _exportedFiles; | 133 List<FileState> get exportedFiles => _exportedFiles; |
134 | 134 |
135 /** | 135 /** |
136 * Return [TopLevelDeclaration]s exported from the this library file. | 136 * Return [TopLevelDeclaration]s exported from the this library file. |
Paul Berry
2016/12/02 16:34:42
Can you update this comment to explain that the ke
| |
137 */ | 137 */ |
138 List<TopLevelDeclaration> get exportedTopLevelDeclarations { | 138 Map<String, TopLevelDeclaration> get exportedTopLevelDeclarations { |
139 if (_exportedTopLevelDeclarations == null) { | 139 if (_exportedTopLevelDeclarations == null) { |
140 _exportedTopLevelDeclarations = <TopLevelDeclaration>[]; | 140 _exportedTopLevelDeclarations = <String, TopLevelDeclaration>{}; |
141 | 141 |
142 Set<FileState> seenLibraries = new Set<FileState>(); | 142 Set<FileState> seenLibraries = new Set<FileState>(); |
143 | 143 |
144 /** | 144 /** |
145 * Compute [TopLevelDeclaration]s exported from the [library]. | 145 * Compute [TopLevelDeclaration]s exported from the [library]. |
146 */ | 146 */ |
147 List<TopLevelDeclaration> computeExported(FileState library) { | 147 Map<String, TopLevelDeclaration> computeExported(FileState library) { |
148 var declarations = <String, TopLevelDeclaration>{}; | 148 var declarations = <String, TopLevelDeclaration>{}; |
149 if (seenLibraries.add(library)) { | 149 if (seenLibraries.add(library)) { |
150 // Append the library declarations. | 150 // Append the library declarations. |
151 for (TopLevelDeclaration t in library.topLevelDeclarations) { | 151 declarations.addAll(library.topLevelDeclarations); |
152 declarations[t.name] = t; | |
153 } | |
154 for (FileState part in library.partedFiles) { | 152 for (FileState part in library.partedFiles) { |
155 for (TopLevelDeclaration t in part.topLevelDeclarations) { | 153 declarations.addAll(part.topLevelDeclarations); |
156 declarations[t.name] = t; | |
157 } | |
158 } | 154 } |
159 | 155 |
160 // Append the exported declarations. | 156 // Append the exported declarations. |
161 for (int i = 0; i < library._exportedFiles.length; i++) { | 157 for (int i = 0; i < library._exportedFiles.length; i++) { |
162 List<TopLevelDeclaration> exported = | 158 Map<String, TopLevelDeclaration> exported = |
163 computeExported(library._exportedFiles[i]); | 159 computeExported(library._exportedFiles[i]); |
164 for (TopLevelDeclaration t in exported) { | 160 exported.forEach((String name, TopLevelDeclaration t) { |
165 if (!declarations.containsKey(t.name) && | 161 if (!declarations.containsKey(t.name) && |
Brian Wilkerson
2016/12/02 16:32:17
Somewhat off topic, but if we append the exported
| |
166 library._exportFilters[i].accepts(t.name)) { | 162 library._exportFilters[i].accepts(t.name)) { |
167 declarations[t.name] = t; | 163 declarations[t.name] = t; |
168 } | 164 } |
169 } | 165 }); |
170 } | 166 } |
171 | 167 |
172 // We're done with this library. | 168 // We're done with this library. |
173 seenLibraries.remove(library); | 169 seenLibraries.remove(library); |
174 } | 170 } |
175 | 171 |
176 return declarations.values.toList(); | 172 return declarations; |
177 } | 173 } |
178 | 174 |
179 _exportedTopLevelDeclarations = computeExported(this); | 175 _exportedTopLevelDeclarations = computeExported(this); |
180 } | 176 } |
181 return _exportedTopLevelDeclarations; | 177 return _exportedTopLevelDeclarations; |
182 } | 178 } |
183 | 179 |
184 @override | 180 @override |
185 int get hashCode => uri.hashCode; | 181 int get hashCode => uri.hashCode; |
186 | 182 |
(...skipping 30 matching lines...) Expand all Loading... | |
217 * The list of files this library file references as parts. | 213 * The list of files this library file references as parts. |
218 */ | 214 */ |
219 List<FileState> get partedFiles => _partedFiles; | 215 List<FileState> get partedFiles => _partedFiles; |
220 | 216 |
221 /** | 217 /** |
222 * The external names referenced by the file. | 218 * The external names referenced by the file. |
223 */ | 219 */ |
224 Set<String> get referencedNames => _referencedNames; | 220 Set<String> get referencedNames => _referencedNames; |
225 | 221 |
226 /** | 222 /** |
227 * Return public top-level declarations declared in the file. | 223 * Return public top-level declarations declared in the file. |
Paul Berry
2016/12/02 16:34:42
Ditto
| |
228 */ | 224 */ |
229 List<TopLevelDeclaration> get topLevelDeclarations { | 225 Map<String, TopLevelDeclaration> get topLevelDeclarations { |
230 if (_topLevelDeclarations == null) { | 226 if (_topLevelDeclarations == null) { |
231 _topLevelDeclarations = <TopLevelDeclaration>[]; | 227 _topLevelDeclarations = <String, TopLevelDeclaration>{}; |
232 | 228 |
233 void addDeclaration(TopLevelDeclarationKind kind, String name) { | 229 void addDeclaration(TopLevelDeclarationKind kind, String name) { |
234 if (!name.startsWith('_')) { | 230 if (!name.startsWith('_')) { |
235 _topLevelDeclarations.add(new TopLevelDeclaration(kind, name)); | 231 _topLevelDeclarations[name] = new TopLevelDeclaration(kind, name); |
236 } | 232 } |
237 } | 233 } |
238 | 234 |
239 // Add types. | 235 // Add types. |
240 for (UnlinkedClass type in unlinked.classes) { | 236 for (UnlinkedClass type in unlinked.classes) { |
241 addDeclaration(TopLevelDeclarationKind.type, type.name); | 237 addDeclaration(TopLevelDeclarationKind.type, type.name); |
242 } | 238 } |
243 for (UnlinkedEnum type in unlinked.enums) { | 239 for (UnlinkedEnum type in unlinked.enums) { |
244 addDeclaration(TopLevelDeclarationKind.type, type.name); | 240 addDeclaration(TopLevelDeclarationKind.type, type.name); |
245 } | 241 } |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 .where((f) => f._transitiveFiles == null) | 665 .where((f) => f._transitiveFiles == null) |
670 .toSet(); | 666 .toSet(); |
671 } | 667 } |
672 | 668 |
673 Set<FileState> get filesWithoutTransitiveSignature { | 669 Set<FileState> get filesWithoutTransitiveSignature { |
674 return state._uriToFile.values | 670 return state._uriToFile.values |
675 .where((f) => f._transitiveSignature == null) | 671 .where((f) => f._transitiveSignature == null) |
676 .toSet(); | 672 .toSet(); |
677 } | 673 } |
678 } | 674 } |
OLD | NEW |