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'; |
11 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
12 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 12 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
13 import 'package:analyzer/src/dart/analysis/driver.dart'; | 13 import 'package:analyzer/src/dart/analysis/driver.dart'; |
14 import 'package:analyzer/src/dart/analysis/referenced_names.dart'; | 14 import 'package:analyzer/src/dart/analysis/referenced_names.dart'; |
| 15 import 'package:analyzer/src/dart/analysis/top_level_declarations.dart'; |
15 import 'package:analyzer/src/dart/scanner/reader.dart'; | 16 import 'package:analyzer/src/dart/scanner/reader.dart'; |
16 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 17 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
17 import 'package:analyzer/src/generated/engine.dart'; | 18 import 'package:analyzer/src/generated/engine.dart'; |
18 import 'package:analyzer/src/generated/parser.dart'; | 19 import 'package:analyzer/src/generated/parser.dart'; |
19 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
20 import 'package:analyzer/src/generated/utilities_dart.dart'; | 21 import 'package:analyzer/src/generated/utilities_dart.dart'; |
21 import 'package:analyzer/src/source/source_resource.dart'; | 22 import 'package:analyzer/src/source/source_resource.dart'; |
22 import 'package:analyzer/src/summary/api_signature.dart'; | 23 import 'package:analyzer/src/summary/api_signature.dart'; |
23 import 'package:analyzer/src/summary/format.dart'; | 24 import 'package:analyzer/src/summary/format.dart'; |
24 import 'package:analyzer/src/summary/idl.dart'; | 25 import 'package:analyzer/src/summary/idl.dart'; |
| 26 import 'package:analyzer/src/summary/name_filter.dart'; |
25 import 'package:analyzer/src/summary/summarize_ast.dart'; | 27 import 'package:analyzer/src/summary/summarize_ast.dart'; |
26 import 'package:analyzer/src/util/fast_uri.dart'; | 28 import 'package:analyzer/src/util/fast_uri.dart'; |
27 import 'package:convert/convert.dart'; | 29 import 'package:convert/convert.dart'; |
28 import 'package:crypto/crypto.dart'; | 30 import 'package:crypto/crypto.dart'; |
29 import 'package:meta/meta.dart'; | 31 import 'package:meta/meta.dart'; |
30 | 32 |
31 /** | 33 /** |
32 * [FileContentOverlay] is used to temporary override content of files. | 34 * [FileContentOverlay] is used to temporary override content of files. |
33 */ | 35 */ |
34 class FileContentOverlay { | 36 class FileContentOverlay { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 String _content; | 88 String _content; |
87 String _contentHash; | 89 String _contentHash; |
88 LineInfo _lineInfo; | 90 LineInfo _lineInfo; |
89 Set<String> _referencedNames; | 91 Set<String> _referencedNames; |
90 UnlinkedUnit _unlinked; | 92 UnlinkedUnit _unlinked; |
91 List<int> _apiSignature; | 93 List<int> _apiSignature; |
92 | 94 |
93 List<FileState> _importedFiles; | 95 List<FileState> _importedFiles; |
94 List<FileState> _exportedFiles; | 96 List<FileState> _exportedFiles; |
95 List<FileState> _partedFiles; | 97 List<FileState> _partedFiles; |
| 98 List<NameFilter> _exportFilters; |
| 99 |
96 Set<FileState> _directReferencedFiles = new Set<FileState>(); | 100 Set<FileState> _directReferencedFiles = new Set<FileState>(); |
97 Set<FileState> _transitiveFiles; | 101 Set<FileState> _transitiveFiles; |
98 String _transitiveSignature; | 102 String _transitiveSignature; |
99 | 103 |
| 104 List<TopLevelDeclaration> _topLevelDeclarations; |
| 105 |
100 FileState._(this._fsState, this.path, this.uri, this.source); | 106 FileState._(this._fsState, this.path, this.uri, this.source); |
101 | 107 |
102 /** | 108 /** |
103 * The unlinked API signature of the file. | 109 * The unlinked API signature of the file. |
104 */ | 110 */ |
105 List<int> get apiSignature => _apiSignature; | 111 List<int> get apiSignature => _apiSignature; |
106 | 112 |
107 /** | 113 /** |
108 * The content of the file. | 114 * The content of the file. |
109 */ | 115 */ |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 * The list of files this library file references as parts. | 167 * The list of files this library file references as parts. |
162 */ | 168 */ |
163 List<FileState> get partedFiles => _partedFiles; | 169 List<FileState> get partedFiles => _partedFiles; |
164 | 170 |
165 /** | 171 /** |
166 * The external names referenced by the file. | 172 * The external names referenced by the file. |
167 */ | 173 */ |
168 Set<String> get referencedNames => _referencedNames; | 174 Set<String> get referencedNames => _referencedNames; |
169 | 175 |
170 /** | 176 /** |
| 177 * Return top-level declarations declared in the file. |
| 178 */ |
| 179 List<TopLevelDeclaration> get topLevelDeclarations { |
| 180 if (_topLevelDeclarations == null) { |
| 181 _topLevelDeclarations = <TopLevelDeclaration>[]; |
| 182 // Add types. |
| 183 for (UnlinkedClass type in unlinked.classes) { |
| 184 _topLevelDeclarations.add( |
| 185 new TopLevelDeclaration(TopLevelDeclarationKind.type, type.name)); |
| 186 } |
| 187 for (UnlinkedEnum type in unlinked.enums) { |
| 188 _topLevelDeclarations.add( |
| 189 new TopLevelDeclaration(TopLevelDeclarationKind.type, type.name)); |
| 190 } |
| 191 for (UnlinkedTypedef type in unlinked.typedefs) { |
| 192 _topLevelDeclarations.add( |
| 193 new TopLevelDeclaration(TopLevelDeclarationKind.type, type.name)); |
| 194 } |
| 195 // Add functions and variables. |
| 196 Set<String> addedVariableNames = new Set<String>(); |
| 197 for (UnlinkedExecutable executable in unlinked.executables) { |
| 198 String name = executable.name; |
| 199 if (executable.kind == UnlinkedExecutableKind.functionOrMethod) { |
| 200 _topLevelDeclarations.add( |
| 201 new TopLevelDeclaration(TopLevelDeclarationKind.function, name)); |
| 202 } else if (executable.kind == UnlinkedExecutableKind.getter || |
| 203 executable.kind == UnlinkedExecutableKind.setter) { |
| 204 if (executable.kind == UnlinkedExecutableKind.setter) { |
| 205 name = name.substring(0, name.length - 1); |
| 206 } |
| 207 if (addedVariableNames.add(name)) { |
| 208 _topLevelDeclarations.add(new TopLevelDeclaration( |
| 209 TopLevelDeclarationKind.variable, name)); |
| 210 } |
| 211 } |
| 212 } |
| 213 for (UnlinkedVariable variable in unlinked.variables) { |
| 214 String name = variable.name; |
| 215 if (addedVariableNames.add(name)) { |
| 216 _topLevelDeclarations.add( |
| 217 new TopLevelDeclaration(TopLevelDeclarationKind.variable, name)); |
| 218 } |
| 219 } |
| 220 } |
| 221 return _topLevelDeclarations; |
| 222 } |
| 223 |
| 224 /** |
171 * Return the set of transitive files - the file itself and all of the | 225 * Return the set of transitive files - the file itself and all of the |
172 * directly or indirectly referenced files. | 226 * directly or indirectly referenced files. |
173 */ | 227 */ |
174 Set<FileState> get transitiveFiles { | 228 Set<FileState> get transitiveFiles { |
175 if (_transitiveFiles == null) { | 229 if (_transitiveFiles == null) { |
176 _transitiveFiles = new Set<FileState>(); | 230 _transitiveFiles = new Set<FileState>(); |
177 | 231 |
178 void appendReferenced(FileState file) { | 232 void appendReferenced(FileState file) { |
179 if (_transitiveFiles.add(file)) { | 233 if (_transitiveFiles.add(file)) { |
180 file._directReferencedFiles.forEach(appendReferenced); | 234 file._directReferencedFiles.forEach(appendReferenced); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 if (_partedFiles != null) { | 371 if (_partedFiles != null) { |
318 for (FileState part in _partedFiles) { | 372 for (FileState part in _partedFiles) { |
319 _fsState._partToLibraries[part]?.remove(this); | 373 _fsState._partToLibraries[part]?.remove(this); |
320 } | 374 } |
321 } | 375 } |
322 | 376 |
323 // Build the graph. | 377 // Build the graph. |
324 _importedFiles = <FileState>[]; | 378 _importedFiles = <FileState>[]; |
325 _exportedFiles = <FileState>[]; | 379 _exportedFiles = <FileState>[]; |
326 _partedFiles = <FileState>[]; | 380 _partedFiles = <FileState>[]; |
| 381 _exportFilters = <NameFilter>[]; |
327 for (UnlinkedImport import in _unlinked.imports) { | 382 for (UnlinkedImport import in _unlinked.imports) { |
328 if (!import.isImplicit) { | 383 if (!import.isImplicit) { |
329 String uri = import.uri; | 384 String uri = import.uri; |
330 if (!_isDartUri(uri)) { | 385 if (!_isDartUri(uri)) { |
331 FileState file = _fileForRelativeUri(uri); | 386 FileState file = _fileForRelativeUri(uri); |
332 if (file != null) { | 387 if (file != null) { |
333 _importedFiles.add(file); | 388 _importedFiles.add(file); |
334 } | 389 } |
335 } | 390 } |
336 } | 391 } |
337 } | 392 } |
338 for (UnlinkedExportPublic export in _unlinked.publicNamespace.exports) { | 393 for (UnlinkedExportPublic export in _unlinked.publicNamespace.exports) { |
339 String uri = export.uri; | 394 String uri = export.uri; |
340 if (!_isDartUri(uri)) { | 395 if (!_isDartUri(uri)) { |
341 FileState file = _fileForRelativeUri(uri); | 396 FileState file = _fileForRelativeUri(uri); |
342 if (file != null) { | 397 if (file != null) { |
343 _exportedFiles.add(file); | 398 _exportedFiles.add(file); |
| 399 _exportFilters |
| 400 .add(new NameFilter.forUnlinkedCombinators(export.combinators)); |
344 } | 401 } |
345 } | 402 } |
346 } | 403 } |
347 for (String uri in _unlinked.publicNamespace.parts) { | 404 for (String uri in _unlinked.publicNamespace.parts) { |
348 if (!_isDartUri(uri)) { | 405 if (!_isDartUri(uri)) { |
349 FileState file = _fileForRelativeUri(uri); | 406 FileState file = _fileForRelativeUri(uri); |
350 if (file != null) { | 407 if (file != null) { |
351 _partedFiles.add(file); | 408 _partedFiles.add(file); |
352 // TODO(scheglov) Sort for stable results? | 409 // TODO(scheglov) Sort for stable results? |
353 _fsState._partToLibraries | 410 _fsState._partToLibraries |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 .where((f) => f._transitiveFiles == null) | 612 .where((f) => f._transitiveFiles == null) |
556 .toSet(); | 613 .toSet(); |
557 } | 614 } |
558 | 615 |
559 Set<FileState> get filesWithoutTransitiveSignature { | 616 Set<FileState> get filesWithoutTransitiveSignature { |
560 return state._uriToFile.values | 617 return state._uriToFile.values |
561 .where((f) => f._transitiveSignature == null) | 618 .where((f) => f._transitiveSignature == null) |
562 .toSet(); | 619 .toSet(); |
563 } | 620 } |
564 } | 621 } |
OLD | NEW |