| 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 analysis_server.src.sdk_ext; | 5 library analysis_server.src.sdk_ext; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:core' hide Resource; | 10 import 'dart:core' hide Resource; |
| 11 | 11 |
| 12 import 'package:analysis_server/uri/resolver_provider.dart'; | |
| 13 import 'package:analyzer/file_system/file_system.dart'; | 12 import 'package:analyzer/file_system/file_system.dart'; |
| 14 import 'package:analyzer/source/package_map_resolver.dart'; | 13 import 'package:analyzer/source/package_map_resolver.dart'; |
| 15 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; | 15 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; |
| 17 import 'package:analyzer/src/generated/source_io.dart' show FileBasedSource; | 16 import 'package:analyzer/src/generated/source_io.dart' show FileBasedSource; |
| 18 import 'package:path/path.dart' as pathos; | 17 import 'package:path/path.dart' as pathos; |
| 19 | 18 |
| 19 class _SdkExtFileBasedSource extends FileBasedSource { |
| 20 _SdkExtFileBasedSource(JavaFile file, Uri uri) |
| 21 : super(file, uri); |
| 22 } |
| 23 |
| 20 /// Given a packageMap (see [PackageMapProvider]), check in each package's lib | 24 /// Given a packageMap (see [PackageMapProvider]), check in each package's lib |
| 21 /// directory for the existence of a `.sdkext` file. This file must contain a | 25 /// directory for the existence of a `.sdkext` file. This file must contain a |
| 22 /// JSON encoded map. Each key in the map is a `dart:` library name. Each value | 26 /// JSON encoded map. Each key in the map is a `dart:` library name. Each value |
| 23 /// is a path (relative to the directory containing `.sdkext`) to a dart script | 27 /// is a path (relative to the directory containing `.sdkext`) to a dart script |
| 24 /// for the given library. For example: | 28 /// for the given library. For example: |
| 25 /// { | 29 /// { |
| 26 /// "dart:sky": "../sdk_ext/dart_sky.dart" | 30 /// "dart:sky": "../sdk_ext/dart_sky.dart" |
| 27 /// } | 31 /// } |
| 28 /// | 32 /// |
| 29 /// If a key doesn't begin with `dart:` it is ignored. | 33 /// If a key doesn't begin with `dart:` it is ignored. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 54 /// Number of sdk extensions. | 58 /// Number of sdk extensions. |
| 55 int get length => _urlMappings.length; | 59 int get length => _urlMappings.length; |
| 56 | 60 |
| 57 /// Resolve a 'part' statement inside an sdk extension. | 61 /// Resolve a 'part' statement inside an sdk extension. |
| 58 Source _resolvePart(Uri libraryEntry, String partPath, Uri importUri) { | 62 Source _resolvePart(Uri libraryEntry, String partPath, Uri importUri) { |
| 59 // Library part. | 63 // Library part. |
| 60 var directory = pathos.dirname(libraryEntry.path); | 64 var directory = pathos.dirname(libraryEntry.path); |
| 61 var partUri = new Uri.file(pathos.join(directory, partPath)); | 65 var partUri = new Uri.file(pathos.join(directory, partPath)); |
| 62 assert(partUri.isAbsolute); | 66 assert(partUri.isAbsolute); |
| 63 JavaFile javaFile = new JavaFile.fromUri(partUri); | 67 JavaFile javaFile = new JavaFile.fromUri(partUri); |
| 64 return new FileBasedSource(javaFile, importUri); | 68 return new _SdkExtFileBasedSource(javaFile, importUri); |
| 65 } | 69 } |
| 66 | 70 |
| 67 /// Resolve an import of an sdk extension. | 71 /// Resolve an import of an sdk extension. |
| 68 Source _resolveEntry(Uri libraryEntry, Uri importUri) { | 72 Source _resolveEntry(Uri libraryEntry, Uri importUri) { |
| 69 // Library entry. | 73 // Library entry. |
| 70 JavaFile javaFile = new JavaFile.fromUri(libraryEntry); | 74 JavaFile javaFile = new JavaFile.fromUri(libraryEntry); |
| 71 return new FileBasedSource(javaFile, importUri); | 75 return new _SdkExtFileBasedSource(javaFile, importUri); |
| 72 } | 76 } |
| 73 | 77 |
| 74 @override | 78 @override |
| 75 Source resolveAbsolute(Uri importUri) { | 79 Source resolveAbsolute(Uri importUri) { |
| 76 // Split import uri into library name and (optionally) a part path. | 80 // Split import uri into library name and (optionally) a part path. |
| 77 var uri = importUri.toString(); | 81 var uri = importUri.toString(); |
| 78 String libraryName; | 82 String libraryName; |
| 79 String partPath; | 83 String partPath; |
| 80 int index = uri.indexOf('/'); | 84 int index = uri.indexOf('/'); |
| 81 if (index >= 0) { | 85 if (index >= 0) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 99 | 103 |
| 100 if (index >= 0) { | 104 if (index >= 0) { |
| 101 return _resolvePart(libraryEntry, partPath, importUri); | 105 return _resolvePart(libraryEntry, partPath, importUri); |
| 102 } else { | 106 } else { |
| 103 return _resolveEntry(libraryEntry, importUri); | 107 return _resolveEntry(libraryEntry, importUri); |
| 104 } | 108 } |
| 105 } | 109 } |
| 106 | 110 |
| 107 @override | 111 @override |
| 108 Uri restoreAbsolute(Source source) { | 112 Uri restoreAbsolute(Source source) { |
| 109 return source.uri; | 113 if (source is _SdkExtFileBasedSource) { |
| 114 return source.uri; |
| 115 } |
| 116 return null; |
| 110 } | 117 } |
| 111 | 118 |
| 112 /// Given a package [name] and a list of folders ([libDirs]), | 119 /// Given a package [name] and a list of folders ([libDirs]), |
| 113 /// add any found sdk extensions. | 120 /// add any found sdk extensions. |
| 114 void _processPackage(String name, List<Folder> libDirs) { | 121 void _processPackage(String name, List<Folder> libDirs) { |
| 115 for (var libDir in libDirs) { | 122 for (var libDir in libDirs) { |
| 116 var sdkExt = _readDotSdkExt(libDir); | 123 var sdkExt = _readDotSdkExt(libDir); |
| 117 if (sdkExt != null) { | 124 if (sdkExt != null) { |
| 118 _processSdkExt(sdkExt, libDir); | 125 _processSdkExt(sdkExt, libDir); |
| 119 } | 126 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 void _processSdkExtension(String name, String file, Folder libDir) { | 158 void _processSdkExtension(String name, String file, Folder libDir) { |
| 152 if (!name.startsWith(DART_COLON_PREFIX)) { | 159 if (!name.startsWith(DART_COLON_PREFIX)) { |
| 153 // SDK extensions must begin with 'dart:'. | 160 // SDK extensions must begin with 'dart:'. |
| 154 return; | 161 return; |
| 155 } | 162 } |
| 156 var key = name; | 163 var key = name; |
| 157 var value = libDir.canonicalizePath(file); | 164 var value = libDir.canonicalizePath(file); |
| 158 _urlMappings[key] = value; | 165 _urlMappings[key] = value; |
| 159 } | 166 } |
| 160 } | 167 } |
| OLD | NEW |