Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1097)

Side by Side Diff: pkg/analyzer/lib/src/generated/source.dart

Issue 1228493003: Revert "Package map source factory support" [TBR]. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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:math" as math; 11 import "dart:math" as math;
12 12
13 import 'package:analyzer/file_system/file_system.dart'; 13 import 'package:analyzer/file_system/file_system.dart';
14 import 'package:analyzer/file_system/physical_file_system.dart';
15 import 'package:analyzer/source/package_map_resolver.dart'; 14 import 'package:analyzer/source/package_map_resolver.dart';
16 import 'package:analyzer/src/generated/utilities_dart.dart' as utils;
17 import 'package:analyzer/task/model.dart'; 15 import 'package:analyzer/task/model.dart';
18 import 'package:package_config/packages.dart';
19 import 'package:path/path.dart' as pathos; 16 import 'package:path/path.dart' as pathos;
20 17
21 import 'engine.dart'; 18 import 'engine.dart';
22 import 'java_core.dart'; 19 import 'java_core.dart';
23 import 'java_engine.dart'; 20 import 'java_engine.dart';
24 import 'java_io.dart' show JavaFile; 21 import 'java_io.dart' show JavaFile;
25 import 'sdk.dart' show DartSdk; 22 import 'sdk.dart' show DartSdk;
26 import 'source_io.dart' show FileBasedSource; 23 import 'source_io.dart' show FileBasedSource;
27 24
28 /** 25 /**
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 * Instances of the class `SourceFactory` resolve possibly relative URI's agains t an existing 568 * Instances of the class `SourceFactory` resolve possibly relative URI's agains t an existing
572 * [Source]. 569 * [Source].
573 */ 570 */
574 class SourceFactory { 571 class SourceFactory {
575 /** 572 /**
576 * The analysis context that this source factory is associated with. 573 * The analysis context that this source factory is associated with.
577 */ 574 */
578 AnalysisContext context; 575 AnalysisContext context;
579 576
580 /** 577 /**
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 /**
592 * The resolvers used to resolve absolute URI's. 578 * The resolvers used to resolve absolute URI's.
593 */ 579 */
594 final List<UriResolver> _resolvers; 580 final List<UriResolver> _resolvers;
595 581
596 /** 582 /**
597 * The predicate to determine is [Source] is local. 583 * The predicate to determine is [Source] is local.
598 */ 584 */
599 LocalSourcePredicate _localSourcePredicate = LocalSourcePredicate.NOT_SDK; 585 LocalSourcePredicate _localSourcePredicate = LocalSourcePredicate.NOT_SDK;
600 586
601 /** 587 /**
602 * Initialize a newly created source factory with the given absolute URI [reso lvers] and 588 * Initialize a newly created source factory.
603 * optional [packages] resolution helper. 589 *
590 * @param resolvers the resolvers used to resolve absolute URI's
604 */ 591 */
605 SourceFactory(this._resolvers, 592 SourceFactory(this._resolvers);
606 [this._packages = Packages.noPackages, ResourceProvider resourceProvider])
607 : _resourceProvider = resourceProvider != null
608 ? resourceProvider
609 : PhysicalResourceProvider.INSTANCE;
610 593
611 /** 594 /**
612 * Return the [DartSdk] associated with this [SourceFactory], or `null` if the re 595 * Return the [DartSdk] associated with this [SourceFactory], or `null` if the re
613 * is no such SDK. 596 * is no such SDK.
614 * 597 *
615 * @return the [DartSdk] associated with this [SourceFactory], or `null` if 598 * @return the [DartSdk] associated with this [SourceFactory], or `null` if
616 * there is no such SDK 599 * there is no such SDK
617 */ 600 */
618 DartSdk get dartSdk { 601 DartSdk get dartSdk {
619 for (UriResolver resolver in _resolvers) { 602 for (UriResolver resolver in _resolvers) {
(...skipping 10 matching lines...) Expand all
630 * 613 *
631 * @param localSourcePredicate the predicate to determine is [Source] is local 614 * @param localSourcePredicate the predicate to determine is [Source] is local
632 */ 615 */
633 void set localSourcePredicate(LocalSourcePredicate localSourcePredicate) { 616 void set localSourcePredicate(LocalSourcePredicate localSourcePredicate) {
634 this._localSourcePredicate = localSourcePredicate; 617 this._localSourcePredicate = localSourcePredicate;
635 } 618 }
636 619
637 /// A table mapping package names to paths of directories containing 620 /// A table mapping package names to paths of directories containing
638 /// the package (or [null] if there is no registered package URI resolver). 621 /// the package (or [null] if there is no registered package URI resolver).
639 Map<String, List<Folder>> get packageMap { 622 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.
653 PackageMapUriResolver resolver = _resolvers.firstWhere( 623 PackageMapUriResolver resolver = _resolvers.firstWhere(
654 (r) => r is PackageMapUriResolver, orElse: () => null); 624 (r) => r is PackageMapUriResolver, orElse: () => null);
655 return resolver != null ? resolver.packageMap : null; 625 return resolver != null ? resolver.packageMap : null;
656 } 626 }
657 627
658 /** 628 /**
659 * Return a source object representing the given absolute URI, or `null` if th e URI is not a 629 * Return a source object representing the given absolute URI, or `null` if th e URI is not a
660 * valid URI or if it is not an absolute URI. 630 * valid URI or if it is not an absolute URI.
661 * 631 *
662 * @param absoluteUri the absolute URI to be resolved 632 * @param absoluteUri the absolute URI to be resolved
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 } 720 }
751 721
752 /** 722 /**
753 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot 723 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot
754 * be computed. 724 * be computed.
755 * 725 *
756 * @param source the source to get URI for 726 * @param source the source to get URI for
757 * @return the absolute URI representing the given source 727 * @return the absolute URI representing the given source
758 */ 728 */
759 Uri restoreUri(Source source) { 729 Uri restoreUri(Source source) {
760 // First see if a resolver can restore the URI.
761 for (UriResolver resolver in _resolvers) { 730 for (UriResolver resolver in _resolvers) {
762 Uri uri = resolver.restoreAbsolute(source); 731 Uri uri = resolver.restoreAbsolute(source);
763 if (uri != null) { 732 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.
770 return uri; 733 return uri;
771 } 734 }
772 } 735 }
773
774 return null; 736 return null;
775 } 737 }
776 738
777 Uri _getPackageMapping(Uri sourceUri) {
778 if (sourceUri.scheme != 'file') {
779 //TODO(pquitslund): verify this works for non-file URIs.
780 return null;
781 }
782
783 Uri packageUri;
784 _packages.asMap().forEach((String name, Uri uri) {
785 if (packageUri == null) {
786 if (utils.startsWith(sourceUri, uri)) {
787 packageUri = Uri.parse(
788 'package:$name/${sourceUri.path.substring(uri.path.length)}');
789 }
790 }
791 });
792 return packageUri;
793 }
794
795 /** 739 /**
796 * Return a source object representing the URI that results from resolving the given (possibly 740 * Return a source object representing the URI that results from resolving the given (possibly
797 * relative) contained URI against the URI associated with an existing source object, or 741 * relative) contained URI against the URI associated with an existing source object, or
798 * `null` if the URI could not be resolved. 742 * `null` if the URI could not be resolved.
799 * 743 *
800 * @param containingSource the source containing the given URI 744 * @param containingSource the source containing the given URI
801 * @param containedUri the (possibly relative) URI to be resolved against the containing source 745 * @param containedUri the (possibly relative) URI to be resolved against the containing source
802 * @return the source representing the contained URI 746 * @return the source representing the contained URI
803 * @throws AnalysisException if either the contained URI is invalid or if it c annot be resolved 747 * @throws AnalysisException if either the contained URI is invalid or if it c annot be resolved
804 * against the source object's URI 748 * against the source object's URI
805 */ 749 */
806 Source _internalResolveUri(Source containingSource, Uri containedUri) { 750 Source _internalResolveUri(Source containingSource, Uri containedUri) {
807 if (!containedUri.isAbsolute) { 751 if (!containedUri.isAbsolute) {
808 if (containingSource == null) { 752 if (containingSource == null) {
809 throw new AnalysisException( 753 throw new AnalysisException(
810 "Cannot resolve a relative URI without a containing source: $contain edUri"); 754 "Cannot resolve a relative URI without a containing source: $contain edUri");
811 } 755 }
812 containedUri = containingSource.resolveRelativeUri(containedUri); 756 containedUri = containingSource.resolveRelativeUri(containedUri);
813 } 757 }
814 // Now check .packages.
815 if (containedUri.scheme == 'package') {
816 Uri packageUri =
817 _packages.resolve(containedUri, notFound: (Uri packageUri) => null);
818 //TODO(pquitslund): package_config needs to be updated to set schemes for file URIs.
819 if (packageUri != null && packageUri.scheme == '') {
820 containedUri = new Uri.file(packageUri.toFilePath());
821 }
822 }
823 for (UriResolver resolver in _resolvers) { 758 for (UriResolver resolver in _resolvers) {
824 Source result = resolver.resolveAbsolute(containedUri); 759 Source result = resolver.resolveAbsolute(containedUri);
825 if (result != null) { 760 if (result != null) {
826 return result; 761 return result;
827 } 762 }
828 } 763 }
829 return null; 764 return null;
830 } 765 }
831 } 766 }
832 767
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 999
1065 /** 1000 /**
1066 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot 1001 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot
1067 * be computed. 1002 * be computed.
1068 * 1003 *
1069 * @param source the source to get URI for 1004 * @param source the source to get URI for
1070 * @return the absolute URI representing the given source 1005 * @return the absolute URI representing the given source
1071 */ 1006 */
1072 Uri restoreAbsolute(Source source) => null; 1007 Uri restoreAbsolute(Source source) => null;
1073 } 1008 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/file_system/physical_file_system.dart ('k') | pkg/analyzer/lib/src/generated/source_io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698