| 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 return _transitiveFiles; | 294 return _transitiveFiles; |
| 295 } | 295 } |
| 296 | 296 |
| 297 /** | 297 /** |
| 298 * Return the signature of the file, based on the [transitiveFiles]. | 298 * Return the signature of the file, based on the [transitiveFiles]. |
| 299 */ | 299 */ |
| 300 String get transitiveSignature { | 300 String get transitiveSignature { |
| 301 if (_transitiveSignature == null) { | 301 if (_transitiveSignature == null) { |
| 302 ApiSignature signature = new ApiSignature(); | 302 ApiSignature signature = new ApiSignature(); |
| 303 signature.addUint32List(_fsState._salt); | 303 signature.addUint32List(_fsState._salt); |
| 304 signature.addString(_fsState._sdkApiSignature); | |
| 305 signature.addInt(transitiveFiles.length); | 304 signature.addInt(transitiveFiles.length); |
| 306 transitiveFiles | 305 transitiveFiles |
| 307 .map((file) => file.apiSignature) | 306 .map((file) => file.apiSignature) |
| 308 .forEach(signature.addBytes); | 307 .forEach(signature.addBytes); |
| 309 signature.addString(uri.toString()); | 308 signature.addString(uri.toString()); |
| 310 _transitiveSignature = signature.toHex(); | 309 _transitiveSignature = signature.toHex(); |
| 311 } | 310 } |
| 312 return _transitiveSignature; | 311 return _transitiveSignature; |
| 313 } | 312 } |
| 314 | 313 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 _fsState._partToLibraries[part]?.remove(this); | 428 _fsState._partToLibraries[part]?.remove(this); |
| 430 } | 429 } |
| 431 } | 430 } |
| 432 | 431 |
| 433 // Build the graph. | 432 // Build the graph. |
| 434 _importedFiles = <FileState>[]; | 433 _importedFiles = <FileState>[]; |
| 435 _exportedFiles = <FileState>[]; | 434 _exportedFiles = <FileState>[]; |
| 436 _partedFiles = <FileState>[]; | 435 _partedFiles = <FileState>[]; |
| 437 _exportFilters = <NameFilter>[]; | 436 _exportFilters = <NameFilter>[]; |
| 438 for (UnlinkedImport import in _unlinked.imports) { | 437 for (UnlinkedImport import in _unlinked.imports) { |
| 439 if (!import.isImplicit) { | 438 String uri = import.isImplicit ? 'dart:core' : import.uri; |
| 440 String uri = import.uri; | 439 FileState file = _fileForRelativeUri(uri); |
| 441 if (_isDartFileUri(uri)) { | 440 if (file != null) { |
| 442 FileState file = _fileForRelativeUri(uri); | 441 _importedFiles.add(file); |
| 443 if (file != null) { | |
| 444 _importedFiles.add(file); | |
| 445 } | |
| 446 } | |
| 447 } | 442 } |
| 448 } | 443 } |
| 449 for (UnlinkedExportPublic export in _unlinked.publicNamespace.exports) { | 444 for (UnlinkedExportPublic export in _unlinked.publicNamespace.exports) { |
| 450 String uri = export.uri; | 445 String uri = export.uri; |
| 451 if (_isDartFileUri(uri)) { | 446 FileState file = _fileForRelativeUri(uri); |
| 452 FileState file = _fileForRelativeUri(uri); | 447 if (file != null) { |
| 453 if (file != null) { | 448 _exportedFiles.add(file); |
| 454 _exportedFiles.add(file); | 449 _exportFilters |
| 455 _exportFilters | 450 .add(new NameFilter.forUnlinkedCombinators(export.combinators)); |
| 456 .add(new NameFilter.forUnlinkedCombinators(export.combinators)); | |
| 457 } | |
| 458 } | 451 } |
| 459 } | 452 } |
| 460 for (String uri in _unlinked.publicNamespace.parts) { | 453 for (String uri in _unlinked.publicNamespace.parts) { |
| 461 if (_isDartFileUri(uri)) { | 454 FileState file = _fileForRelativeUri(uri); |
| 462 FileState file = _fileForRelativeUri(uri); | 455 if (file != null) { |
| 463 if (file != null) { | 456 _partedFiles.add(file); |
| 464 _partedFiles.add(file); | 457 // TODO(scheglov) Sort for stable results? |
| 465 // TODO(scheglov) Sort for stable results? | 458 _fsState._partToLibraries |
| 466 _fsState._partToLibraries | 459 .putIfAbsent(file, () => <FileState>[]) |
| 467 .putIfAbsent(file, () => <FileState>[]) | 460 .add(this); |
| 468 .add(this); | |
| 469 } | |
| 470 } | 461 } |
| 471 } | 462 } |
| 472 | 463 |
| 473 // Compute referenced files. | 464 // Compute referenced files. |
| 474 Set<FileState> oldDirectReferencedFiles = _directReferencedFiles; | 465 Set<FileState> oldDirectReferencedFiles = _directReferencedFiles; |
| 475 _directReferencedFiles = new Set<FileState>() | 466 _directReferencedFiles = new Set<FileState>() |
| 476 ..addAll(_importedFiles) | 467 ..addAll(_importedFiles) |
| 477 ..addAll(_exportedFiles) | 468 ..addAll(_exportedFiles) |
| 478 ..addAll(_partedFiles); | 469 ..addAll(_partedFiles); |
| 479 | 470 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 if (a.length != b.length) { | 508 if (a.length != b.length) { |
| 518 return false; | 509 return false; |
| 519 } | 510 } |
| 520 for (int i = 0; i < a.length; i++) { | 511 for (int i = 0; i < a.length; i++) { |
| 521 if (a[i] != b[i]) { | 512 if (a[i] != b[i]) { |
| 522 return false; | 513 return false; |
| 523 } | 514 } |
| 524 } | 515 } |
| 525 return true; | 516 return true; |
| 526 } | 517 } |
| 527 | |
| 528 static bool _isDartFileUri(String uri) { | |
| 529 return !uri.startsWith('dart:'); | |
| 530 } | |
| 531 } | 518 } |
| 532 | 519 |
| 533 /** | 520 /** |
| 534 * Information about known file system state. | 521 * Information about known file system state. |
| 535 */ | 522 */ |
| 536 class FileSystemState { | 523 class FileSystemState { |
| 537 final PerformanceLog _logger; | 524 final PerformanceLog _logger; |
| 538 final ResourceProvider _resourceProvider; | 525 final ResourceProvider _resourceProvider; |
| 539 final ByteStore _byteStore; | 526 final ByteStore _byteStore; |
| 540 final FileContentOverlay _contentOverlay; | 527 final FileContentOverlay _contentOverlay; |
| 541 final SourceFactory _sourceFactory; | 528 final SourceFactory _sourceFactory; |
| 542 final AnalysisOptions _analysisOptions; | 529 final AnalysisOptions _analysisOptions; |
| 543 final Uint32List _salt; | 530 final Uint32List _salt; |
| 544 final String _sdkApiSignature; | |
| 545 | 531 |
| 546 /** | 532 /** |
| 547 * Mapping from a URI to the corresponding [FileState]. | 533 * Mapping from a URI to the corresponding [FileState]. |
| 548 */ | 534 */ |
| 549 final Map<Uri, FileState> _uriToFile = {}; | 535 final Map<Uri, FileState> _uriToFile = {}; |
| 550 | 536 |
| 551 /** | 537 /** |
| 552 * All known file paths. | 538 * All known file paths. |
| 553 */ | 539 */ |
| 554 final Set<String> knownFilePaths = new Set<String>(); | 540 final Set<String> knownFilePaths = new Set<String>(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 570 | 556 |
| 571 FileSystemStateTestView _testView; | 557 FileSystemStateTestView _testView; |
| 572 | 558 |
| 573 FileSystemState( | 559 FileSystemState( |
| 574 this._logger, | 560 this._logger, |
| 575 this._byteStore, | 561 this._byteStore, |
| 576 this._contentOverlay, | 562 this._contentOverlay, |
| 577 this._resourceProvider, | 563 this._resourceProvider, |
| 578 this._sourceFactory, | 564 this._sourceFactory, |
| 579 this._analysisOptions, | 565 this._analysisOptions, |
| 580 this._salt, | 566 this._salt) { |
| 581 this._sdkApiSignature) { | |
| 582 _testView = new FileSystemStateTestView(this); | 567 _testView = new FileSystemStateTestView(this); |
| 583 } | 568 } |
| 584 | 569 |
| 585 /** | 570 /** |
| 586 * Return the known files. | 571 * Return the known files. |
| 587 */ | 572 */ |
| 588 Iterable<FileState> get knownFiles => | 573 Iterable<FileState> get knownFiles => |
| 589 _pathToFiles.values.map((files) => files.first); | 574 _pathToFiles.values.map((files) => files.first); |
| 590 | 575 |
| 591 @visibleForTesting | 576 @visibleForTesting |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 .where((f) => f._transitiveFiles == null) | 680 .where((f) => f._transitiveFiles == null) |
| 696 .toSet(); | 681 .toSet(); |
| 697 } | 682 } |
| 698 | 683 |
| 699 Set<FileState> get filesWithoutTransitiveSignature { | 684 Set<FileState> get filesWithoutTransitiveSignature { |
| 700 return state._uriToFile.values | 685 return state._uriToFile.values |
| 701 .where((f) => f._transitiveSignature == null) | 686 .where((f) => f._transitiveSignature == null) |
| 702 .toSet(); | 687 .toSet(); |
| 703 } | 688 } |
| 704 } | 689 } |
| OLD | NEW |