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

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

Issue 1206323005: Package map source factory support. (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
« no previous file with comments | « pkg/analyzer/lib/file_system/physical_file_system.dart ('k') | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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: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
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 /**
578 * The resolvers used to resolve absolute URI's. 587 * The resolvers used to resolve absolute URI's.
579 */ 588 */
580 final List<UriResolver> _resolvers; 589 final List<UriResolver> _resolvers;
581 590
582 /** 591 /**
583 * The predicate to determine is [Source] is local. 592 * The predicate to determine is [Source] is local.
584 */ 593 */
585 LocalSourcePredicate _localSourcePredicate = LocalSourcePredicate.NOT_SDK; 594 LocalSourcePredicate _localSourcePredicate = LocalSourcePredicate.NOT_SDK;
586 595
587 /** 596 /**
588 * Initialize a newly created source factory. 597 * Initialize a newly created source factory with the given absolute URI [reso lvers] and
589 * 598 * optional [packages] resolution helper.
590 * @param resolvers the resolvers used to resolve absolute URI's
591 */ 599 */
592 SourceFactory(this._resolvers); 600 SourceFactory(this._resolvers, [this._packages = Packages.noPackages]);
593 601
594 /** 602 /**
595 * Return the [DartSdk] associated with this [SourceFactory], or `null` if the re 603 * Return the [DartSdk] associated with this [SourceFactory], or `null` if the re
596 * is no such SDK. 604 * is no such SDK.
597 * 605 *
598 * @return the [DartSdk] associated with this [SourceFactory], or `null` if 606 * @return the [DartSdk] associated with this [SourceFactory], or `null` if
599 * there is no such SDK 607 * there is no such SDK
600 */ 608 */
601 DartSdk get dartSdk { 609 DartSdk get dartSdk {
602 for (UriResolver resolver in _resolvers) { 610 for (UriResolver resolver in _resolvers) {
(...skipping 10 matching lines...) Expand all
613 * 621 *
614 * @param localSourcePredicate the predicate to determine is [Source] is local 622 * @param localSourcePredicate the predicate to determine is [Source] is local
615 */ 623 */
616 void set localSourcePredicate(LocalSourcePredicate localSourcePredicate) { 624 void set localSourcePredicate(LocalSourcePredicate localSourcePredicate) {
617 this._localSourcePredicate = localSourcePredicate; 625 this._localSourcePredicate = localSourcePredicate;
618 } 626 }
619 627
620 /// A table mapping package names to paths of directories containing 628 /// A table mapping package names to paths of directories containing
621 /// the package (or [null] if there is no registered package URI resolver). 629 /// the package (or [null] if there is no registered package URI resolver).
622 Map<String, List<Folder>> get packageMap { 630 Map<String, List<Folder>> get packageMap {
631 // Start by looking in .packages.
632 if (_packages != Packages.noPackages) {
633 Map<String, List<Folder>> packageMap = <String, List<Folder>>{};
634 _packages.asMap().forEach((String name, Uri uri) {
635 if (uri.scheme == 'file' || uri.scheme == '' /* unspecified */) {
636 packageMap[name] = <Folder>[
637 PhysicalResourceProvider.INSTANCE.getFolder(uri.toFilePath())
638 ];
639 }
640 });
641 return packageMap;
642 }
643
644 // Default to the PackageMapUriResolver.
623 PackageMapUriResolver resolver = _resolvers.firstWhere( 645 PackageMapUriResolver resolver = _resolvers.firstWhere(
624 (r) => r is PackageMapUriResolver, orElse: () => null); 646 (r) => r is PackageMapUriResolver, orElse: () => null);
625 return resolver != null ? resolver.packageMap : null; 647 return resolver != null ? resolver.packageMap : null;
626 } 648 }
627 649
628 /** 650 /**
629 * Return a source object representing the given absolute URI, or `null` if th e URI is not a 651 * 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. 652 * valid URI or if it is not an absolute URI.
631 * 653 *
632 * @param absoluteUri the absolute URI to be resolved 654 * @param absoluteUri the absolute URI to be resolved
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 } 742 }
721 743
722 /** 744 /**
723 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot 745 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot
724 * be computed. 746 * be computed.
725 * 747 *
726 * @param source the source to get URI for 748 * @param source the source to get URI for
727 * @return the absolute URI representing the given source 749 * @return the absolute URI representing the given source
728 */ 750 */
729 Uri restoreUri(Source source) { 751 Uri restoreUri(Source source) {
752 // First see if a resolver can restore the URI.
730 for (UriResolver resolver in _resolvers) { 753 for (UriResolver resolver in _resolvers) {
731 Uri uri = resolver.restoreAbsolute(source); 754 Uri uri = resolver.restoreAbsolute(source);
732 if (uri != null) { 755 if (uri != null) {
756 // Now see if there's a package mapping.
757 Uri packageMappedUri = _getPackageMapping(uri);
758 if (packageMappedUri != null) {
759 return packageMappedUri;
760 }
761 // Fall back to the resolver's computed URI.
733 return uri; 762 return uri;
734 } 763 }
735 } 764 }
736 return null; 765
766 // In case no resolver can restore the URI, default to a .packages look-up.
767 return _getPackageMapping(source.uri);
768 }
769
770 Uri _getPackageMapping(Uri uri) {
771 if (uri.scheme != 'file') {
Brian Wilkerson 2015/06/30 23:29:38 I'm a little concerned that longer term we'll need
pquitslund 2015/06/30 23:46:05 Right. Added TODO.
772 return null;
773 }
774
775 String sourcePath = uri.toFilePath();
776 Uri packageUri;
777 _packages.asMap().forEach((String name, Uri uri) {
778 if (packageUri == null) {
779 String uriPath = uri.toFilePath();
780 if (sourcePath.startsWith(uriPath)) {
781 packageUri = Uri
782 .parse('package:$name/${sourcePath.substring(uriPath.length)}');
783 }
784 }
785 });
786 return packageUri;
737 } 787 }
738 788
739 /** 789 /**
740 * Return a source object representing the URI that results from resolving the given (possibly 790 * 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 791 * relative) contained URI against the URI associated with an existing source object, or
742 * `null` if the URI could not be resolved. 792 * `null` if the URI could not be resolved.
743 * 793 *
744 * @param containingSource the source containing the given URI 794 * @param containingSource the source containing the given URI
745 * @param containedUri the (possibly relative) URI to be resolved against the containing source 795 * @param containedUri the (possibly relative) URI to be resolved against the containing source
746 * @return the source representing the contained URI 796 * @return the source representing the contained URI
747 * @throws AnalysisException if either the contained URI is invalid or if it c annot be resolved 797 * @throws AnalysisException if either the contained URI is invalid or if it c annot be resolved
748 * against the source object's URI 798 * against the source object's URI
749 */ 799 */
750 Source _internalResolveUri(Source containingSource, Uri containedUri) { 800 Source _internalResolveUri(Source containingSource, Uri containedUri) {
801 // Check .packages first.
802 if (containedUri.scheme == 'package') {
803 Uri packageUri = _packages.resolve(containedUri);
804 //TODO(pquitslund): package_config needs to be updated to set schemes for file URIs.
805 if (packageUri != null && packageUri.scheme == '') {
806 containedUri = new Uri.file(packageUri.toFilePath());
807 }
808 }
751 if (!containedUri.isAbsolute) { 809 if (!containedUri.isAbsolute) {
752 if (containingSource == null) { 810 if (containingSource == null) {
753 throw new AnalysisException( 811 throw new AnalysisException(
754 "Cannot resolve a relative URI without a containing source: $contain edUri"); 812 "Cannot resolve a relative URI without a containing source: $contain edUri");
755 } 813 }
756 containedUri = containingSource.resolveRelativeUri(containedUri); 814 containedUri = containingSource.resolveRelativeUri(containedUri);
757 } 815 }
758 for (UriResolver resolver in _resolvers) { 816 for (UriResolver resolver in _resolvers) {
759 Source result = resolver.resolveAbsolute(containedUri); 817 Source result = resolver.resolveAbsolute(containedUri);
760 if (result != null) { 818 if (result != null) {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 1057
1000 /** 1058 /**
1001 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot 1059 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot
1002 * be computed. 1060 * be computed.
1003 * 1061 *
1004 * @param source the source to get URI for 1062 * @param source the source to get URI for
1005 * @return the absolute URI representing the given source 1063 * @return the absolute URI representing the given source
1006 */ 1064 */
1007 Uri restoreAbsolute(Source source) => null; 1065 Uri restoreAbsolute(Source source) => null;
1008 } 1066 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/file_system/physical_file_system.dart ('k') | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698