Chromium Code Reviews| 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.src.summary.summary_sdk; | 5 library analyzer.src.summary.summary_sdk; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/dart/element/type.dart'; | 8 import 'package:analyzer/dart/element/type.dart'; |
| 9 import 'package:analyzer/src/context/cache.dart' show CacheEntry; | 9 import 'package:analyzer/src/context/cache.dart' show CacheEntry; |
| 10 import 'package:analyzer/src/context/context.dart'; | 10 import 'package:analyzer/src/context/context.dart'; |
| 11 import 'package:analyzer/src/dart/element/element.dart'; | 11 import 'package:analyzer/src/dart/element/element.dart'; |
| 12 import 'package:analyzer/src/dart/element/type.dart'; | 12 import 'package:analyzer/src/dart/element/type.dart'; |
| 13 import 'package:analyzer/src/generated/constant.dart'; | 13 import 'package:analyzer/src/generated/constant.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 15 import 'package:analyzer/src/generated/resolver.dart'; | 15 import 'package:analyzer/src/generated/resolver.dart'; |
| 16 import 'package:analyzer/src/generated/sdk.dart'; | |
| 16 import 'package:analyzer/src/generated/source.dart' | 17 import 'package:analyzer/src/generated/source.dart' |
| 17 show Source, SourceFactory, SourceKind; | 18 show DartUriResolver, Source, SourceFactory, SourceKind; |
| 18 import 'package:analyzer/src/summary/idl.dart'; | 19 import 'package:analyzer/src/summary/idl.dart'; |
| 20 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | |
| 19 import 'package:analyzer/src/summary/resynthesize.dart'; | 21 import 'package:analyzer/src/summary/resynthesize.dart'; |
| 20 import 'package:analyzer/src/task/dart.dart'; | 22 import 'package:analyzer/src/task/dart.dart'; |
| 21 import 'package:analyzer/task/dart.dart'; | 23 import 'package:analyzer/task/dart.dart'; |
| 22 import 'package:analyzer/task/model.dart' | 24 import 'package:analyzer/task/model.dart' |
| 23 show AnalysisTarget, ResultDescriptor, TargetedResult; | 25 show AnalysisTarget, ResultDescriptor, TargetedResult; |
| 24 | 26 |
| 25 class SdkSummaryResultProvider implements SummaryResultProvider { | 27 class SdkSummaryResultProvider implements SummaryResultProvider { |
| 26 final InternalAnalysisContext context; | 28 final InternalAnalysisContext context; |
| 27 final PackageBundle bundle; | 29 final PackageBundle bundle; |
| 28 final SummaryTypeProvider typeProvider = new SummaryTypeProvider(); | 30 final SummaryTypeProvider typeProvider = new SummaryTypeProvider(); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 return unlinkedSummaries[uri]; | 185 return unlinkedSummaries[uri]; |
| 184 } | 186 } |
| 185 | 187 |
| 186 @override | 188 @override |
| 187 bool hasLibrarySummary(String uri) { | 189 bool hasLibrarySummary(String uri) { |
| 188 return uri.startsWith('dart:'); | 190 return uri.startsWith('dart:'); |
| 189 } | 191 } |
| 190 } | 192 } |
| 191 | 193 |
| 192 /** | 194 /** |
| 195 * An implementation of [DartSdk] which provides analysis results for `dart:` | |
| 196 * libraries from the given summary file. This implementation is limited and | |
| 197 * suitable only for command-line tools, but not for IDEs. | |
|
Brian Wilkerson
2016/05/13 18:07:59
It would be good to expand this comment by explain
| |
| 198 */ | |
| 199 class SummaryBasedDartSdk implements DartSdk { | |
| 200 SummaryDataStore _dataStore; | |
| 201 InSummaryPackageUriResolver _uriResolver; | |
| 202 PackageBundle _bundle; | |
| 203 | |
| 204 /** | |
| 205 * The [AnalysisContext] which is used for all of the sources in this sdk. | |
| 206 */ | |
| 207 InternalAnalysisContext _analysisContext; | |
| 208 | |
| 209 SummaryBasedDartSdk(String summaryPath) { | |
| 210 _dataStore = new SummaryDataStore(<String>[summaryPath]); | |
| 211 _uriResolver = new InSummaryPackageUriResolver(_dataStore); | |
| 212 _bundle = _dataStore.bundles.single; | |
| 213 } | |
| 214 | |
| 215 /** | |
| 216 * Return the [PackageBundle] for this SDK, not `null`. | |
| 217 */ | |
| 218 PackageBundle get bundle => _bundle; | |
| 219 | |
| 220 @override | |
| 221 AnalysisContext get context { | |
| 222 if (_analysisContext == null) { | |
| 223 _analysisContext = new SdkAnalysisContext(null); | |
| 224 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); | |
| 225 _analysisContext.sourceFactory = factory; | |
| 226 _analysisContext.resultProvider = | |
| 227 new SdkSummaryResultProvider(_analysisContext, _bundle); | |
| 228 } | |
| 229 return _analysisContext; | |
| 230 } | |
| 231 | |
| 232 @override | |
| 233 List<SdkLibrary> get sdkLibraries { | |
| 234 throw new UnimplementedError(); | |
| 235 } | |
| 236 | |
| 237 @override | |
| 238 String get sdkVersion { | |
| 239 throw new UnimplementedError(); | |
| 240 } | |
| 241 | |
| 242 @override | |
| 243 List<String> get uris { | |
| 244 throw new UnimplementedError(); | |
| 245 } | |
| 246 | |
| 247 @override | |
| 248 Source fromFileUri(Uri uri) { | |
| 249 return null; | |
| 250 } | |
| 251 | |
| 252 @override | |
| 253 SdkLibrary getSdkLibrary(String uri) { | |
| 254 // This is not quite correct, but currently it's used only in | |
| 255 // to report errors on importing or exporting of internal libraries. | |
| 256 return null; | |
| 257 } | |
| 258 | |
| 259 @override | |
| 260 Source mapDartUri(String uriStr) { | |
| 261 Uri uri = Uri.parse(uriStr); | |
| 262 return _uriResolver.resolveAbsolute(uri); | |
| 263 } | |
| 264 } | |
| 265 | |
| 266 /** | |
| 193 * Provider for analysis results. | 267 * Provider for analysis results. |
| 194 */ | 268 */ |
| 195 abstract class SummaryResultProvider extends ResultProvider { | 269 abstract class SummaryResultProvider extends ResultProvider { |
| 196 /** | 270 /** |
| 197 * The [SummaryResynthesizer] of this context, maybe `null`. | 271 * The [SummaryResynthesizer] of this context, maybe `null`. |
| 198 */ | 272 */ |
| 199 SummaryResynthesizer get resynthesizer; | 273 SummaryResynthesizer get resynthesizer; |
| 200 } | 274 } |
| 201 | 275 |
| 202 /** | 276 /** |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 * throw a [StateError] if there is no class with the given name. | 501 * throw a [StateError] if there is no class with the given name. |
| 428 */ | 502 */ |
| 429 InterfaceType _getType(LibraryElement library, String name) { | 503 InterfaceType _getType(LibraryElement library, String name) { |
| 430 Element element = library.getType(name); | 504 Element element = library.getType(name); |
| 431 if (element == null) { | 505 if (element == null) { |
| 432 throw new StateError("No definition of type $name"); | 506 throw new StateError("No definition of type $name"); |
| 433 } | 507 } |
| 434 return (element as ClassElement).type; | 508 return (element as ClassElement).type; |
| 435 } | 509 } |
| 436 } | 510 } |
| OLD | NEW |