Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.source; | 8 library engine.source; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| 11 import 'dart:io'; | |
| 11 import "dart:math" as math; | 12 import "dart:math" as math; |
| 12 | 13 |
| 13 import 'package:analyzer/file_system/file_system.dart'; | 14 import 'package:analyzer/file_system/file_system.dart'; |
| 15 import 'package:analyzer/file_system/physical_file_system.dart'; | |
| 14 import 'package:analyzer/source/package_map_resolver.dart'; | 16 import 'package:analyzer/source/package_map_resolver.dart'; |
| 15 import 'package:analyzer/task/model.dart'; | 17 import 'package:analyzer/task/model.dart'; |
| 18 import 'package:package_config/packages.dart'; | |
| 16 import 'package:path/path.dart' as pathos; | 19 import 'package:path/path.dart' as pathos; |
| 17 | 20 |
| 18 import 'engine.dart'; | 21 import 'engine.dart'; |
| 19 import 'java_core.dart'; | 22 import 'java_core.dart'; |
| 20 import 'java_engine.dart'; | 23 import 'java_engine.dart'; |
| 21 import 'java_io.dart' show JavaFile; | 24 import 'java_io.dart' show JavaFile; |
| 22 import 'sdk.dart' show DartSdk; | 25 import 'sdk.dart' show DartSdk; |
| 23 import 'source_io.dart' show FileBasedSource; | 26 import 'source_io.dart' show FileBasedSource; |
| 24 | 27 |
| 25 /** | 28 /** |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 * Instances of the class `SourceFactory` resolve possibly relative URI's agains t an existing | 571 * Instances of the class `SourceFactory` resolve possibly relative URI's agains t an existing |
| 569 * [Source]. | 572 * [Source]. |
| 570 */ | 573 */ |
| 571 class SourceFactory { | 574 class SourceFactory { |
| 572 /** | 575 /** |
| 573 * The analysis context that this source factory is associated with. | 576 * The analysis context that this source factory is associated with. |
| 574 */ | 577 */ |
| 575 AnalysisContext context; | 578 AnalysisContext context; |
| 576 | 579 |
| 577 /** | 580 /** |
| 581 * URI processor used to find mappings for `package:` URIs found in a `.packag es` config | |
| 582 * file. | |
| 583 */ | |
| 584 final Packages _packages; | |
| 585 | |
| 586 /** | |
| 587 * Resource provider used in working with package maps. | |
| 588 */ | |
| 589 final ResourceProvider _resourceProvider; | |
| 590 | |
| 591 /** | |
| 578 * The resolvers used to resolve absolute URI's. | 592 * The resolvers used to resolve absolute URI's. |
| 579 */ | 593 */ |
| 580 final List<UriResolver> _resolvers; | 594 final List<UriResolver> _resolvers; |
| 581 | 595 |
| 582 /** | 596 /** |
| 583 * The predicate to determine is [Source] is local. | 597 * The predicate to determine is [Source] is local. |
| 584 */ | 598 */ |
| 585 LocalSourcePredicate _localSourcePredicate = LocalSourcePredicate.NOT_SDK; | 599 LocalSourcePredicate _localSourcePredicate = LocalSourcePredicate.NOT_SDK; |
| 586 | 600 |
| 587 /** | 601 /** |
| 588 * Initialize a newly created source factory. | 602 * Initialize a newly created source factory with the given absolute URI [reso lvers] and |
| 589 * | 603 * optional [packages] resolution helper. |
| 590 * @param resolvers the resolvers used to resolve absolute URI's | |
| 591 */ | 604 */ |
| 592 SourceFactory(this._resolvers); | 605 SourceFactory(this._resolvers, |
| 606 [this._packages = Packages.noPackages, ResourceProvider resourceProvider]) | |
| 607 : _resourceProvider = resourceProvider != null | |
| 608 ? resourceProvider | |
| 609 : PhysicalResourceProvider.INSTANCE; | |
| 593 | 610 |
| 594 /** | 611 /** |
| 595 * Return the [DartSdk] associated with this [SourceFactory], or `null` if the re | 612 * Return the [DartSdk] associated with this [SourceFactory], or `null` if the re |
| 596 * is no such SDK. | 613 * is no such SDK. |
| 597 * | 614 * |
| 598 * @return the [DartSdk] associated with this [SourceFactory], or `null` if | 615 * @return the [DartSdk] associated with this [SourceFactory], or `null` if |
| 599 * there is no such SDK | 616 * there is no such SDK |
| 600 */ | 617 */ |
| 601 DartSdk get dartSdk { | 618 DartSdk get dartSdk { |
| 602 for (UriResolver resolver in _resolvers) { | 619 for (UriResolver resolver in _resolvers) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 613 * | 630 * |
| 614 * @param localSourcePredicate the predicate to determine is [Source] is local | 631 * @param localSourcePredicate the predicate to determine is [Source] is local |
| 615 */ | 632 */ |
| 616 void set localSourcePredicate(LocalSourcePredicate localSourcePredicate) { | 633 void set localSourcePredicate(LocalSourcePredicate localSourcePredicate) { |
| 617 this._localSourcePredicate = localSourcePredicate; | 634 this._localSourcePredicate = localSourcePredicate; |
| 618 } | 635 } |
| 619 | 636 |
| 620 /// A table mapping package names to paths of directories containing | 637 /// A table mapping package names to paths of directories containing |
| 621 /// the package (or [null] if there is no registered package URI resolver). | 638 /// the package (or [null] if there is no registered package URI resolver). |
| 622 Map<String, List<Folder>> get packageMap { | 639 Map<String, List<Folder>> get packageMap { |
| 640 // Start by looking in .packages. | |
| 641 if (_packages != Packages.noPackages) { | |
| 642 Map<String, List<Folder>> packageMap = <String, List<Folder>>{}; | |
| 643 _packages.asMap().forEach((String name, Uri uri) { | |
| 644 if (uri.scheme == 'file' || uri.scheme == '' /* unspecified */) { | |
| 645 packageMap[name] = | |
| 646 <Folder>[_resourceProvider.getFolder(uri.toFilePath())]; | |
| 647 } | |
| 648 }); | |
| 649 return packageMap; | |
| 650 } | |
| 651 | |
| 652 // Default to the PackageMapUriResolver. | |
| 623 PackageMapUriResolver resolver = _resolvers.firstWhere( | 653 PackageMapUriResolver resolver = _resolvers.firstWhere( |
| 624 (r) => r is PackageMapUriResolver, orElse: () => null); | 654 (r) => r is PackageMapUriResolver, orElse: () => null); |
| 625 return resolver != null ? resolver.packageMap : null; | 655 return resolver != null ? resolver.packageMap : null; |
| 626 } | 656 } |
| 627 | 657 |
| 628 /** | 658 /** |
| 629 * Return a source object representing the given absolute URI, or `null` if th e URI is not a | 659 * Return a source object representing the given absolute URI, or `null` if th e URI is not a |
| 630 * valid URI or if it is not an absolute URI. | 660 * valid URI or if it is not an absolute URI. |
| 631 * | 661 * |
| 632 * @param absoluteUri the absolute URI to be resolved | 662 * @param absoluteUri the absolute URI to be resolved |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 } | 750 } |
| 721 | 751 |
| 722 /** | 752 /** |
| 723 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot | 753 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot |
| 724 * be computed. | 754 * be computed. |
| 725 * | 755 * |
| 726 * @param source the source to get URI for | 756 * @param source the source to get URI for |
| 727 * @return the absolute URI representing the given source | 757 * @return the absolute URI representing the given source |
| 728 */ | 758 */ |
| 729 Uri restoreUri(Source source) { | 759 Uri restoreUri(Source source) { |
| 760 // First see if a resolver can restore the URI. | |
| 730 for (UriResolver resolver in _resolvers) { | 761 for (UriResolver resolver in _resolvers) { |
| 731 Uri uri = resolver.restoreAbsolute(source); | 762 Uri uri = resolver.restoreAbsolute(source); |
| 732 if (uri != null) { | 763 if (uri != null) { |
| 764 // Now see if there's a package mapping. | |
| 765 Uri packageMappedUri = _getPackageMapping(uri); | |
| 766 if (packageMappedUri != null) { | |
| 767 return packageMappedUri; | |
| 768 } | |
| 769 // Fall back to the resolver's computed URI. | |
| 733 return uri; | 770 return uri; |
| 734 } | 771 } |
| 735 } | 772 } |
| 736 return null; | 773 |
| 774 // In case no resolver can restore the URI, default to a .packages look-up. | |
| 775 return _getPackageMapping(source.uri); | |
|
Paul Berry
2015/07/01 15:55:40
I don't think we want this. The idea of restoreUr
| |
| 776 } | |
| 777 | |
| 778 Uri _getPackageMapping(Uri uri) { | |
|
Paul Berry
2015/07/01 15:55:40
I'm concerned about the algorithm for this functio
| |
| 779 if (uri.scheme != 'file') { | |
| 780 //TODO(pquitslund): add support for non-file URIs. | |
| 781 return null; | |
| 782 } | |
| 783 | |
| 784 String sourcePath = uri.toFilePath(); | |
| 785 Uri packageUri; | |
| 786 _packages.asMap().forEach((String name, Uri uri) { | |
| 787 if (packageUri == null) { | |
| 788 String uriPath = uri.toFilePath(); | |
| 789 if (sourcePath.startsWith(uriPath)) { | |
|
Paul Berry
2015/07/01 15:55:40
Is it guaranteed that "uriPath" will end with a tr
| |
| 790 packageUri = Uri | |
| 791 .parse('package:$name/${sourcePath.substring(uriPath.length)}'); | |
| 792 } | |
| 793 } | |
| 794 }); | |
| 795 return packageUri; | |
| 737 } | 796 } |
| 738 | 797 |
| 739 /** | 798 /** |
| 740 * Return a source object representing the URI that results from resolving the given (possibly | 799 * Return a source object representing the URI that results from resolving the given (possibly |
| 741 * relative) contained URI against the URI associated with an existing source object, or | 800 * relative) contained URI against the URI associated with an existing source object, or |
| 742 * `null` if the URI could not be resolved. | 801 * `null` if the URI could not be resolved. |
| 743 * | 802 * |
| 744 * @param containingSource the source containing the given URI | 803 * @param containingSource the source containing the given URI |
| 745 * @param containedUri the (possibly relative) URI to be resolved against the containing source | 804 * @param containedUri the (possibly relative) URI to be resolved against the containing source |
| 746 * @return the source representing the contained URI | 805 * @return the source representing the contained URI |
| 747 * @throws AnalysisException if either the contained URI is invalid or if it c annot be resolved | 806 * @throws AnalysisException if either the contained URI is invalid or if it c annot be resolved |
| 748 * against the source object's URI | 807 * against the source object's URI |
| 749 */ | 808 */ |
| 750 Source _internalResolveUri(Source containingSource, Uri containedUri) { | 809 Source _internalResolveUri(Source containingSource, Uri containedUri) { |
| 810 // Check .packages first. | |
|
Paul Berry
2015/07/01 15:55:40
This needs to go after the "if (!containedUri.isAb
| |
| 811 if (containedUri.scheme == 'package') { | |
| 812 Uri packageUri = _packages.resolve(containedUri); | |
| 813 //TODO(pquitslund): package_config needs to be updated to set schemes for file URIs. | |
| 814 if (packageUri != null && packageUri.scheme == '') { | |
|
Paul Berry
2015/07/01 15:55:40
To reduce churn once the TODO above is addressed,
| |
| 815 containedUri = new Uri.file(packageUri.toFilePath()); | |
| 816 } | |
| 817 } | |
| 751 if (!containedUri.isAbsolute) { | 818 if (!containedUri.isAbsolute) { |
| 752 if (containingSource == null) { | 819 if (containingSource == null) { |
| 753 throw new AnalysisException( | 820 throw new AnalysisException( |
| 754 "Cannot resolve a relative URI without a containing source: $contain edUri"); | 821 "Cannot resolve a relative URI without a containing source: $contain edUri"); |
| 755 } | 822 } |
| 756 containedUri = containingSource.resolveRelativeUri(containedUri); | 823 containedUri = containingSource.resolveRelativeUri(containedUri); |
| 757 } | 824 } |
| 758 for (UriResolver resolver in _resolvers) { | 825 for (UriResolver resolver in _resolvers) { |
| 759 Source result = resolver.resolveAbsolute(containedUri); | 826 Source result = resolver.resolveAbsolute(containedUri); |
| 760 if (result != null) { | 827 if (result != null) { |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 999 | 1066 |
| 1000 /** | 1067 /** |
| 1001 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot | 1068 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot |
| 1002 * be computed. | 1069 * be computed. |
| 1003 * | 1070 * |
| 1004 * @param source the source to get URI for | 1071 * @param source the source to get URI for |
| 1005 * @return the absolute URI representing the given source | 1072 * @return the absolute URI representing the given source |
| 1006 */ | 1073 */ |
| 1007 Uri restoreAbsolute(Source source) => null; | 1074 Uri restoreAbsolute(Source source) => null; |
| 1008 } | 1075 } |
| OLD | NEW |