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

Side by Side Diff: pkg/analyzer/lib/source/sdk_ext.dart

Issue 1294473009: Fix script entry case of SdkExtUriResolver.restoreAbsolute (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 | « no previous file | pkg/analyzer/test/source/sdk_ext_test.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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library source.sdk_ext; 5 library source.sdk_ext;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'dart:core' hide Resource; 8 import 'dart:core' hide Resource;
9 9
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 if (partPath != null) { 70 if (partPath != null) {
71 return _resolvePart(libraryEntry, partPath, importUri); 71 return _resolvePart(libraryEntry, partPath, importUri);
72 } else { 72 } else {
73 return _resolveEntry(libraryEntry, importUri); 73 return _resolveEntry(libraryEntry, importUri);
74 } 74 }
75 } 75 }
76 76
77 @override 77 @override
78 Uri restoreAbsolute(Source source) { 78 Uri restoreAbsolute(Source source) {
79 String libraryName = _libraryName(source.uri); 79 String extensionName = _findExtensionNameFor(source.fullName);
80 if (_registeredSdkExtension(libraryName)) { 80 if (extensionName != null) {
81 return source.uri; 81 return Uri.parse(extensionName);
82 } 82 }
83 // TODO(johnmccutchan): Handle restoring parts.
83 return null; 84 return null;
84 } 85 }
85 86
87 /// Return the extension name for [fullName] or `null`.
88 String _findExtensionNameFor(String fullName) {
89 var result;
90 _urlMappings.forEach((extensionName, pathMapping) {
91 if (pathMapping == fullName) {
92 result = extensionName;
93 }
94 });
95 return result;
96 }
97
86 /// Return the library name of [importUri]. 98 /// Return the library name of [importUri].
87 String _libraryName(Uri importUri) { 99 String _libraryName(Uri importUri) {
88 var uri = importUri.toString(); 100 var uri = importUri.toString();
89 int index = uri.indexOf('/'); 101 int index = uri.indexOf('/');
90 if (index >= 0) { 102 if (index >= 0) {
91 return uri.substring(0, index); 103 return uri.substring(0, index);
92 } 104 }
93 return uri; 105 return uri;
94 } 106 }
95 107
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 String _readDotSdkExt(Folder libDir) { 157 String _readDotSdkExt(Folder libDir) {
146 var file = libDir.getChild(SDK_EXT_NAME); 158 var file = libDir.getChild(SDK_EXT_NAME);
147 try { 159 try {
148 return file.readAsStringSync(); 160 return file.readAsStringSync();
149 } on FileSystemException { 161 } on FileSystemException {
150 // File can't be read. 162 // File can't be read.
151 return null; 163 return null;
152 } 164 }
153 } 165 }
154 166
155 /// Returns true if [libraryName] is a registered sdk extension.
156 bool _registeredSdkExtension(String libraryName) {
157 return _urlMappings[libraryName] != null;
158 }
159
160 /// Resolve an import of an sdk extension. 167 /// Resolve an import of an sdk extension.
161 Source _resolveEntry(Uri libraryEntry, Uri importUri) { 168 Source _resolveEntry(Uri libraryEntry, Uri importUri) {
162 // Library entry. 169 // Library entry.
163 JavaFile javaFile = new JavaFile.fromUri(libraryEntry); 170 JavaFile javaFile = new JavaFile.fromUri(libraryEntry);
164 return new FileBasedSource(javaFile, importUri); 171 return new FileBasedSource(javaFile, importUri);
165 } 172 }
166 173
167 /// Resolve a 'part' statement inside an sdk extension. 174 /// Resolve a 'part' statement inside an sdk extension.
168 Source _resolvePart(Uri libraryEntry, String partPath, Uri importUri) { 175 Source _resolvePart(Uri libraryEntry, String partPath, Uri importUri) {
169 // Library part. 176 // Library part.
170 var directory = pathos.dirname(libraryEntry.path); 177 var directory = pathos.dirname(libraryEntry.path);
171 var partUri = new Uri.file(pathos.join(directory, partPath)); 178 var partUri = new Uri.file(pathos.join(directory, partPath));
172 assert(partUri.isAbsolute); 179 assert(partUri.isAbsolute);
173 JavaFile javaFile = new JavaFile.fromUri(partUri); 180 JavaFile javaFile = new JavaFile.fromUri(partUri);
174 return new FileBasedSource(javaFile, importUri); 181 return new FileBasedSource(javaFile, importUri);
175 } 182 }
176 } 183 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/source/sdk_ext_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698