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

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

Issue 1245263002: Actual URI support for package URI resolution. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge master (tk2). 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/source/sdk_ext.dart ('k') | pkg/analyzer/lib/src/generated/source_io.dart » ('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';
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 } 103 }
104 } 104 }
105 105
106 class CustomUriResolver extends UriResolver { 106 class CustomUriResolver extends UriResolver {
107 final Map<String, String> _urlMappings; 107 final Map<String, String> _urlMappings;
108 108
109 CustomUriResolver(this._urlMappings); 109 CustomUriResolver(this._urlMappings);
110 110
111 @override 111 @override
112 Source resolveAbsolute(Uri uri) { 112 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
113 String mapping = _urlMappings[uri.toString()]; 113 String mapping = _urlMappings[uri.toString()];
114 if (mapping == null) return null; 114 if (mapping == null) return null;
115 115
116 Uri fileUri = new Uri.file(mapping); 116 Uri fileUri = new Uri.file(mapping);
117 if (!fileUri.isAbsolute) return null; 117 if (!fileUri.isAbsolute) return null;
118 118
119 JavaFile javaFile = new JavaFile.fromUri(fileUri); 119 JavaFile javaFile = new JavaFile.fromUri(fileUri);
120 return new FileBasedSource(javaFile); 120 return new FileBasedSource(javaFile, actualUri);
121 } 121 }
122 } 122 }
123 123
124 /** 124 /**
125 * Instances of the class `DartUriResolver` resolve `dart` URI's. 125 * Instances of the class `DartUriResolver` resolve `dart` URI's.
126 */ 126 */
127 class DartUriResolver extends UriResolver { 127 class DartUriResolver extends UriResolver {
128 /** 128 /**
129 * The name of the `dart` scheme. 129 * The name of the `dart` scheme.
130 */ 130 */
(...skipping 18 matching lines...) Expand all
149 DartUriResolver(this._sdk); 149 DartUriResolver(this._sdk);
150 150
151 /** 151 /**
152 * Return the [DartSdk] against which URIs are to be resolved. 152 * Return the [DartSdk] against which URIs are to be resolved.
153 * 153 *
154 * @return the [DartSdk] against which URIs are to be resolved. 154 * @return the [DartSdk] against which URIs are to be resolved.
155 */ 155 */
156 DartSdk get dartSdk => _sdk; 156 DartSdk get dartSdk => _sdk;
157 157
158 @override 158 @override
159 Source resolveAbsolute(Uri uri) { 159 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
160 if (!isDartUri(uri)) { 160 if (!isDartUri(uri)) {
161 return null; 161 return null;
162 } 162 }
163 return _sdk.mapDartUri(uri.toString()); 163 return _sdk.mapDartUri(uri.toString());
164 } 164 }
165 165
166 /** 166 /**
167 * Return `true` if the given URI is a `dart-ext:` URI. 167 * Return `true` if the given URI is a `dart-ext:` URI.
168 * 168 *
169 * @param uriContent the textual representation of the URI being tested 169 * @param uriContent the textual representation of the URI being tested
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 * against the source object's URI 807 * against the source object's URI
808 */ 808 */
809 Source _internalResolveUri(Source containingSource, Uri containedUri) { 809 Source _internalResolveUri(Source containingSource, Uri containedUri) {
810 if (!containedUri.isAbsolute) { 810 if (!containedUri.isAbsolute) {
811 if (containingSource == null) { 811 if (containingSource == null) {
812 throw new AnalysisException( 812 throw new AnalysisException(
813 "Cannot resolve a relative URI without a containing source: $contain edUri"); 813 "Cannot resolve a relative URI without a containing source: $contain edUri");
814 } 814 }
815 containedUri = containingSource.resolveRelativeUri(containedUri); 815 containedUri = containingSource.resolveRelativeUri(containedUri);
816 } 816 }
817 // Now check .packages. 817
818 Uri actualUri = containedUri;
819
820 // Check .packages and update target and actual URIs as appropriate.
818 if (_packages != null && containedUri.scheme == 'package') { 821 if (_packages != null && containedUri.scheme == 'package') {
819 Uri packageUri = 822 Uri packageUri =
820 _packages.resolve(containedUri, notFound: (Uri packageUri) => null); 823 _packages.resolve(containedUri, notFound: (Uri packageUri) => null);
821 // Ensure scheme is set. 824
822 if (packageUri != null && packageUri.scheme == '') { 825 if (packageUri != null) {
823 packageUri = packageUri.replace(scheme: 'file'); 826 // Ensure scheme is set.
827 if (packageUri.scheme == '') {
828 packageUri = packageUri.replace(scheme: 'file');
829 }
830 containedUri = packageUri;
824 } 831 }
825 containedUri = packageUri;
826 } 832 }
833
827 for (UriResolver resolver in _resolvers) { 834 for (UriResolver resolver in _resolvers) {
828 Source result = resolver.resolveAbsolute(containedUri); 835 Source result = resolver.resolveAbsolute(containedUri, actualUri);
829 if (result != null) { 836 if (result != null) {
830 return result; 837 return result;
831 } 838 }
832 } 839 }
840
833 return null; 841 return null;
834 } 842 }
835 } 843 }
836 844
837 /** 845 /**
838 * The enumeration `SourceKind` defines the different kinds of sources that are known to the 846 * The enumeration `SourceKind` defines the different kinds of sources that are known to the
839 * analysis engine. 847 * analysis engine.
840 */ 848 */
841 class SourceKind extends Enum<SourceKind> { 849 class SourceKind extends Enum<SourceKind> {
842 /** 850 /**
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 * URI's for a source factory. Subclasses of this class are expected to resolve a single scheme of 1063 * URI's for a source factory. Subclasses of this class are expected to resolve a single scheme of
1056 * absolute URI. 1064 * absolute URI.
1057 */ 1065 */
1058 abstract class UriResolver { 1066 abstract class UriResolver {
1059 /** 1067 /**
1060 * Resolve the given absolute URI. Return a [Source] representing the file to which 1068 * Resolve the given absolute URI. Return a [Source] representing the file to which
1061 * it was resolved, whether or not the resulting source exists, or `null` if i t could not be 1069 * it was resolved, whether or not the resulting source exists, or `null` if i t could not be
1062 * resolved because the URI is invalid. 1070 * resolved because the URI is invalid.
1063 * 1071 *
1064 * @param uri the URI to be resolved 1072 * @param uri the URI to be resolved
1073 * @param actualUri the actual uri for this source -- if `null`, the value of [uri] will be used
1065 * @return a [Source] representing the file to which given URI was resolved 1074 * @return a [Source] representing the file to which given URI was resolved
1066 */ 1075 */
1067 Source resolveAbsolute(Uri uri); 1076 Source resolveAbsolute(Uri uri, [Uri actualUri]);
1068 1077
1069 /** 1078 /**
1070 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot 1079 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot
1071 * be computed. 1080 * be computed.
1072 * 1081 *
1073 * @param source the source to get URI for 1082 * @param source the source to get URI for
1074 * @return the absolute URI representing the given source 1083 * @return the absolute URI representing the given source
1075 */ 1084 */
1076 Uri restoreAbsolute(Source source) => null; 1085 Uri restoreAbsolute(Source source) => null;
1077 } 1086 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/source/sdk_ext.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