OLD | NEW |
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 analyzer.source.sdk_ext; | 5 library analyzer.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 13 matching lines...) Expand all Loading... |
24 /// "dart:sky": "../sdk_ext/dart_sky.dart" | 24 /// "dart:sky": "../sdk_ext/dart_sky.dart" |
25 /// } | 25 /// } |
26 /// | 26 /// |
27 /// If a key doesn't begin with `dart:` it is ignored. | 27 /// If a key doesn't begin with `dart:` it is ignored. |
28 class SdkExtUriResolver extends UriResolver { | 28 class SdkExtUriResolver extends UriResolver { |
29 static const String SDK_EXT_NAME = '_sdkext'; | 29 static const String SDK_EXT_NAME = '_sdkext'; |
30 static const String DART_COLON_PREFIX = 'dart:'; | 30 static const String DART_COLON_PREFIX = 'dart:'; |
31 | 31 |
32 final Map<String, String> _urlMappings = <String, String>{}; | 32 final Map<String, String> _urlMappings = <String, String>{}; |
33 | 33 |
| 34 /** |
| 35 * The absolute paths of the extension files that contributed to the |
| 36 * [_urlMappings]. |
| 37 */ |
| 38 final List<String> extensionFilePaths = <String>[]; |
| 39 |
34 /// Construct a [SdkExtUriResolver] from a package map | 40 /// Construct a [SdkExtUriResolver] from a package map |
35 /// (see [PackageMapProvider]). | 41 /// (see [PackageMapProvider]). |
36 SdkExtUriResolver(Map<String, List<Folder>> packageMap) { | 42 SdkExtUriResolver(Map<String, List<Folder>> packageMap) { |
37 if (packageMap == null) { | 43 if (packageMap == null) { |
38 return; | 44 return; |
39 } | 45 } |
40 packageMap.forEach(_processPackage); | 46 packageMap.forEach(_processPackage); |
41 } | 47 } |
42 | 48 |
43 /// Number of sdk extensions. | 49 /// Number of sdk extensions. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 void _processSdkExt(String sdkExtJSON, Folder libDir) { | 146 void _processSdkExt(String sdkExtJSON, Folder libDir) { |
141 var sdkExt; | 147 var sdkExt; |
142 try { | 148 try { |
143 sdkExt = JSON.decode(sdkExtJSON); | 149 sdkExt = JSON.decode(sdkExtJSON); |
144 } catch (e) { | 150 } catch (e) { |
145 return; | 151 return; |
146 } | 152 } |
147 if ((sdkExt == null) || (sdkExt is! Map)) { | 153 if ((sdkExt == null) || (sdkExt is! Map)) { |
148 return; | 154 return; |
149 } | 155 } |
150 sdkExt.forEach((k, v) => _processSdkExtension(k, v, libDir)); | 156 bool contributed = false; |
| 157 sdkExt.forEach((k, v) { |
| 158 if (_processSdkExtension(k, v, libDir)) { |
| 159 contributed = true; |
| 160 } |
| 161 }); |
| 162 if (contributed) { |
| 163 extensionFilePaths.add(libDir.getChild(SDK_EXT_NAME).path); |
| 164 } |
151 } | 165 } |
152 | 166 |
153 /// Install the mapping from [name] to [libDir]/[file]. | 167 /// Install the mapping from [name] to [libDir]/[file]. |
154 void _processSdkExtension(String name, String file, Folder libDir) { | 168 bool _processSdkExtension(String name, String file, Folder libDir) { |
155 if (!name.startsWith(DART_COLON_PREFIX)) { | 169 if (!name.startsWith(DART_COLON_PREFIX)) { |
156 // SDK extensions must begin with 'dart:'. | 170 // SDK extensions must begin with 'dart:'. |
157 return; | 171 return false; |
158 } | 172 } |
159 var key = name; | 173 var key = name; |
160 var value = libDir.canonicalizePath(file); | 174 var value = libDir.canonicalizePath(file); |
161 _urlMappings[key] = value; | 175 _urlMappings[key] = value; |
| 176 return true; |
162 } | 177 } |
163 | 178 |
164 /// Read the contents of [libDir]/[SDK_EXT_NAME] as a string. | 179 /// Read the contents of [libDir]/[SDK_EXT_NAME] as a string. |
165 /// Returns null if the file doesn't exist. | 180 /// Returns null if the file doesn't exist. |
166 String _readDotSdkExt(Folder libDir) { | 181 String _readDotSdkExt(Folder libDir) { |
167 File file = libDir.getChild(SDK_EXT_NAME); | 182 File file = libDir.getChild(SDK_EXT_NAME); |
168 try { | 183 try { |
169 return file.readAsStringSync(); | 184 return file.readAsStringSync(); |
170 } on FileSystemException { | 185 } on FileSystemException { |
171 // File can't be read. | 186 // File can't be read. |
(...skipping 11 matching lines...) Expand all Loading... |
183 /// Resolve a 'part' statement inside an sdk extension. | 198 /// Resolve a 'part' statement inside an sdk extension. |
184 Source _resolvePart(Uri libraryEntry, String partPath, Uri importUri) { | 199 Source _resolvePart(Uri libraryEntry, String partPath, Uri importUri) { |
185 // Library part. | 200 // Library part. |
186 var directory = pathos.dirname(libraryEntry.path); | 201 var directory = pathos.dirname(libraryEntry.path); |
187 var partUri = new Uri.file(pathos.join(directory, partPath)); | 202 var partUri = new Uri.file(pathos.join(directory, partPath)); |
188 assert(partUri.isAbsolute); | 203 assert(partUri.isAbsolute); |
189 JavaFile javaFile = new JavaFile.fromUri(partUri); | 204 JavaFile javaFile = new JavaFile.fromUri(partUri); |
190 return new FileBasedSource(javaFile, importUri); | 205 return new FileBasedSource(javaFile, importUri); |
191 } | 206 } |
192 } | 207 } |
OLD | NEW |