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/defined_names.dart'; | 13 import 'package:analyzer/src/dart/analysis/defined_names.dart'; |
14 import 'package:analyzer/src/dart/analysis/driver.dart'; | 14 import 'package:analyzer/src/dart/analysis/driver.dart'; |
15 import 'package:analyzer/src/dart/analysis/referenced_names.dart'; | 15 import 'package:analyzer/src/dart/analysis/referenced_names.dart'; |
16 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; | 16 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; |
17 import 'package:analyzer/src/dart/scanner/reader.dart'; | 17 import 'package:analyzer/src/dart/scanner/reader.dart'; |
18 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 18 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
19 import 'package:analyzer/src/generated/engine.dart'; | 19 import 'package:analyzer/src/generated/engine.dart'; |
20 import 'package:analyzer/src/generated/parser.dart'; | 20 import 'package:analyzer/src/generated/parser.dart'; |
21 import 'package:analyzer/src/generated/source.dart'; | 21 import 'package:analyzer/src/generated/source.dart'; |
22 import 'package:analyzer/src/generated/utilities_dart.dart'; | 22 import 'package:analyzer/src/generated/utilities_dart.dart'; |
23 import 'package:analyzer/src/source/source_resource.dart'; | 23 import 'package:analyzer/src/source/source_resource.dart'; |
24 import 'package:analyzer/src/summary/api_signature.dart'; | 24 import 'package:analyzer/src/summary/api_signature.dart'; |
25 import 'package:analyzer/src/summary/format.dart'; | 25 import 'package:analyzer/src/summary/format.dart'; |
26 import 'package:analyzer/src/summary/idl.dart'; | 26 import 'package:analyzer/src/summary/idl.dart'; |
27 import 'package:analyzer/src/summary/name_filter.dart'; | 27 import 'package:analyzer/src/summary/name_filter.dart'; |
| 28 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
28 import 'package:analyzer/src/summary/summarize_ast.dart'; | 29 import 'package:analyzer/src/summary/summarize_ast.dart'; |
29 import 'package:convert/convert.dart'; | 30 import 'package:convert/convert.dart'; |
30 import 'package:crypto/crypto.dart'; | 31 import 'package:crypto/crypto.dart'; |
31 import 'package:front_end/src/fasta/analyzer/ast_builder.dart' as fasta; | 32 import 'package:front_end/src/fasta/analyzer/ast_builder.dart' as fasta; |
32 import 'package:front_end/src/fasta/analyzer/element_store.dart' as fasta; | 33 import 'package:front_end/src/fasta/analyzer/element_store.dart' as fasta; |
33 import 'package:front_end/src/fasta/analyzer/mock_element.dart' as fasta; | 34 import 'package:front_end/src/fasta/analyzer/mock_element.dart' as fasta; |
34 import 'package:front_end/src/fasta/builder/builder.dart' as fasta; | 35 import 'package:front_end/src/fasta/builder/builder.dart' as fasta; |
35 import 'package:front_end/src/fasta/builder/scope.dart' as fasta; | 36 import 'package:front_end/src/fasta/builder/scope.dart' as fasta; |
36 import 'package:front_end/src/fasta/parser/parser.dart' as fasta; | 37 import 'package:front_end/src/fasta/parser/parser.dart' as fasta; |
37 import 'package:front_end/src/fasta/scanner.dart' as fasta; | 38 import 'package:front_end/src/fasta/scanner.dart' as fasta; |
(...skipping 550 matching lines...) Loading... |
588 class FileSystemState { | 589 class FileSystemState { |
589 final PerformanceLog _logger; | 590 final PerformanceLog _logger; |
590 final ResourceProvider _resourceProvider; | 591 final ResourceProvider _resourceProvider; |
591 final ByteStore _byteStore; | 592 final ByteStore _byteStore; |
592 final FileContentOverlay _contentOverlay; | 593 final FileContentOverlay _contentOverlay; |
593 final SourceFactory _sourceFactory; | 594 final SourceFactory _sourceFactory; |
594 final AnalysisOptions _analysisOptions; | 595 final AnalysisOptions _analysisOptions; |
595 final Uint32List _salt; | 596 final Uint32List _salt; |
596 | 597 |
597 /** | 598 /** |
| 599 * The optional store with externally provided unlinked and corresponding |
| 600 * linked summaries. These summaries are always added to the store for any |
| 601 * file analysis. |
| 602 * |
| 603 * While walking the file graph, when we reach a file that exists in the |
| 604 * external store, we don't add it. |
| 605 * |
| 606 * TODO(scheglov) document some more |
| 607 */ |
| 608 final SummaryDataStore externalSummaries; |
| 609 |
| 610 /** |
598 * Mapping from a URI to the corresponding [FileState]. | 611 * Mapping from a URI to the corresponding [FileState]. |
599 */ | 612 */ |
600 final Map<Uri, FileState> _uriToFile = {}; | 613 final Map<Uri, FileState> _uriToFile = {}; |
601 | 614 |
602 /** | 615 /** |
603 * All known file paths. | 616 * All known file paths. |
604 */ | 617 */ |
605 final Set<String> knownFilePaths = new Set<String>(); | 618 final Set<String> knownFilePaths = new Set<String>(); |
606 | 619 |
607 /** | 620 /** |
(...skipping 18 matching lines...) Loading... |
626 | 639 |
627 FileSystemStateTestView _testView; | 640 FileSystemStateTestView _testView; |
628 | 641 |
629 FileSystemState( | 642 FileSystemState( |
630 this._logger, | 643 this._logger, |
631 this._byteStore, | 644 this._byteStore, |
632 this._contentOverlay, | 645 this._contentOverlay, |
633 this._resourceProvider, | 646 this._resourceProvider, |
634 this._sourceFactory, | 647 this._sourceFactory, |
635 this._analysisOptions, | 648 this._analysisOptions, |
636 this._salt) { | 649 this._salt, |
| 650 {this.externalSummaries}) { |
637 _testView = new FileSystemStateTestView(this); | 651 _testView = new FileSystemStateTestView(this); |
638 } | 652 } |
639 | 653 |
640 /** | 654 /** |
641 * Return the known files. | 655 * Return the known files. |
642 */ | 656 */ |
643 List<FileState> get knownFiles => | 657 List<FileState> get knownFiles => |
644 _pathToFiles.values.map((files) => files.first).toList(); | 658 _pathToFiles.values.map((files) => files.first).toList(); |
645 | 659 |
646 @visibleForTesting | 660 @visibleForTesting |
(...skipping 31 matching lines...) Loading... |
678 } | 692 } |
679 | 693 |
680 /** | 694 /** |
681 * Return the [FileState] for the given absolute [uri]. May return `null` if | 695 * Return the [FileState] for the given absolute [uri]. May return `null` if |
682 * the [uri] is invalid, e.g. a `package:` URI without a package name. The | 696 * the [uri] is invalid, e.g. a `package:` URI without a package name. The |
683 * returned file has the last known state since if was last refreshed. | 697 * returned file has the last known state since if was last refreshed. |
684 */ | 698 */ |
685 FileState getFileForUri(Uri uri) { | 699 FileState getFileForUri(Uri uri) { |
686 FileState file = _uriToFile[uri]; | 700 FileState file = _uriToFile[uri]; |
687 if (file == null) { | 701 if (file == null) { |
688 Source uriSource = _sourceFactory.resolveUri(null, uri.toString()); | 702 String uriStr = uri.toString(); |
| 703 |
| 704 // If the external store has this URI, don't create the file for it. |
| 705 // We are given all required unlinked and linked summaries for it. |
| 706 if (externalSummaries != null && |
| 707 externalSummaries.hasUnlinkedUnit(uriStr)) { |
| 708 return null; |
| 709 } |
| 710 |
| 711 Source uriSource = _sourceFactory.resolveUri(null, uriStr); |
| 712 |
689 // If the URI is invalid, for example package:/test/d.dart (note the | 713 // If the URI is invalid, for example package:/test/d.dart (note the |
690 // leading '/'), then `null` is returned. We should ignore this URI. | 714 // leading '/'), then `null` is returned. We should ignore this URI. |
691 if (uriSource == null) { | 715 if (uriSource == null) { |
692 return null; | 716 return null; |
693 } | 717 } |
| 718 |
694 String path = uriSource.fullName; | 719 String path = uriSource.fullName; |
695 File resource = _resourceProvider.getFile(path); | 720 File resource = _resourceProvider.getFile(path); |
696 FileSource source = new FileSource(resource, uri); | 721 FileSource source = new FileSource(resource, uri); |
697 file = new FileState._(this, path, uri, source); | 722 file = new FileState._(this, path, uri, source); |
698 _uriToFile[uri] = file; | 723 _uriToFile[uri] = file; |
699 _addFileWithPath(path, file); | 724 _addFileWithPath(path, file); |
700 file.refresh(); | 725 file.refresh(); |
701 } | 726 } |
702 return file; | 727 return file; |
703 } | 728 } |
(...skipping 45 matching lines...) Loading... |
749 } | 774 } |
750 | 775 |
751 void _addFileWithPath(String path, FileState file) { | 776 void _addFileWithPath(String path, FileState file) { |
752 var files = _pathToFiles[path]; | 777 var files = _pathToFiles[path]; |
753 if (files == null) { | 778 if (files == null) { |
754 knownFilePaths.add(path); | 779 knownFilePaths.add(path); |
755 files = <FileState>[]; | 780 files = <FileState>[]; |
756 _pathToFiles[path] = files; | 781 _pathToFiles[path] = files; |
757 } | 782 } |
758 files.add(file); | 783 files.add(file); |
| 784 if (file.uri.scheme != 'package') { |
| 785 _pathToCanonicalFile[path] = file; |
| 786 } |
759 } | 787 } |
760 } | 788 } |
761 | 789 |
762 @visibleForTesting | 790 @visibleForTesting |
763 class FileSystemStateTestView { | 791 class FileSystemStateTestView { |
764 final FileSystemState state; | 792 final FileSystemState state; |
765 | 793 |
766 FileSystemStateTestView(this.state); | 794 FileSystemStateTestView(this.state); |
767 | 795 |
768 Set<FileState> get filesWithoutTransitiveFiles { | 796 Set<FileState> get filesWithoutTransitiveFiles { |
(...skipping 27 matching lines...) Loading... |
796 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 824 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
797 } | 825 } |
798 | 826 |
799 class _FastaEmptyScope extends fasta.Scope { | 827 class _FastaEmptyScope extends fasta.Scope { |
800 _FastaEmptyScope() : super({}, null); | 828 _FastaEmptyScope() : super({}, null); |
801 } | 829 } |
802 | 830 |
803 class _FastaInterfaceTypeProxy implements fasta.KernelInterfaceType { | 831 class _FastaInterfaceTypeProxy implements fasta.KernelInterfaceType { |
804 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 832 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
805 } | 833 } |
OLD | NEW |