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/file_system/file_system.dart' show ResourceProvider; | 9 import 'package:analyzer/file_system/file_system.dart' show ResourceProvider; |
10 import 'package:analyzer/src/context/cache.dart' show CacheEntry; | |
11 import 'package:analyzer/src/context/context.dart'; | 10 import 'package:analyzer/src/context/context.dart'; |
12 import 'package:analyzer/src/dart/element/type.dart'; | 11 import 'package:analyzer/src/dart/element/type.dart'; |
13 import 'package:analyzer/src/generated/constant.dart'; | 12 import 'package:analyzer/src/generated/constant.dart'; |
14 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
15 import 'package:analyzer/src/generated/resolver.dart'; | 14 import 'package:analyzer/src/generated/resolver.dart'; |
16 import 'package:analyzer/src/generated/sdk.dart'; | 15 import 'package:analyzer/src/generated/sdk.dart'; |
17 import 'package:analyzer/src/generated/source.dart' | 16 import 'package:analyzer/src/generated/source.dart' |
18 show DartUriResolver, Source, SourceFactory; | 17 show DartUriResolver, Source, SourceFactory; |
19 import 'package:analyzer/src/summary/idl.dart'; | 18 import 'package:analyzer/src/summary/idl.dart'; |
20 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 19 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
21 import 'package:analyzer/src/summary/resynthesize.dart'; | |
22 import 'package:analyzer/src/task/dart.dart'; | |
23 import 'package:analyzer/task/model.dart' show ResultDescriptor, TargetedResult; | |
24 | |
25 class SdkSummaryResultProvider extends ResynthesizerResultProvider { | |
26 final SummaryTypeProvider typeProvider = new SummaryTypeProvider(); | |
27 | |
28 SdkSummaryResultProvider( | |
29 InternalAnalysisContext context, PackageBundle bundle, bool strongMode) | |
30 : super(context, new SummaryDataStore(const <String>[])) { | |
31 addBundle(null, bundle); | |
32 createResynthesizer(null, typeProvider); | |
33 _buildCoreLibrary(); | |
34 _buildAsyncLibrary(); | |
35 resynthesizer.finalizeCoreAsyncLibraries(); | |
36 context.typeProvider = typeProvider; | |
37 } | |
38 | |
39 @override | |
40 bool compute(CacheEntry entry, ResultDescriptor result) { | |
41 if (result == TYPE_PROVIDER) { | |
42 entry.setValue(result as ResultDescriptor<TypeProvider>, typeProvider, | |
43 TargetedResult.EMPTY_LIST); | |
44 return true; | |
45 } | |
46 return super.compute(entry, result); | |
47 } | |
48 | |
49 @override | |
50 bool hasResultsForSource(Source source) { | |
51 return source != null && source.isInSystemLibrary; | |
52 } | |
53 | |
54 void _buildAsyncLibrary() { | |
55 LibraryElement library = resynthesizer.getLibraryElement('dart:async'); | |
56 typeProvider.initializeAsync(library); | |
57 } | |
58 | |
59 void _buildCoreLibrary() { | |
60 LibraryElement library = resynthesizer.getLibraryElement('dart:core'); | |
61 typeProvider.initializeCore(library); | |
62 } | |
63 } | |
64 | |
65 /** | |
66 * The implementation of [SummaryResynthesizer] for Dart SDK. | |
67 */ | |
68 class SdkSummaryResynthesizer extends SummaryResynthesizer { | |
69 final PackageBundle bundle; | |
70 final Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{}; | |
71 final Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{}; | |
72 | |
73 SdkSummaryResynthesizer(AnalysisContext context, TypeProvider typeProvider, | |
74 SourceFactory sourceFactory, this.bundle, bool strongMode) | |
75 : super(null, context, typeProvider, sourceFactory, strongMode) { | |
76 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) { | |
77 unlinkedSummaries[bundle.unlinkedUnitUris[i]] = bundle.unlinkedUnits[i]; | |
78 } | |
79 for (int i = 0; i < bundle.linkedLibraryUris.length; i++) { | |
80 linkedSummaries[bundle.linkedLibraryUris[i]] = bundle.linkedLibraries[i]; | |
81 } | |
82 } | |
83 | |
84 @override | |
85 LinkedLibrary getLinkedSummary(String uri) { | |
86 return linkedSummaries[uri]; | |
87 } | |
88 | |
89 @override | |
90 UnlinkedUnit getUnlinkedSummary(String uri) { | |
91 return unlinkedSummaries[uri]; | |
92 } | |
93 | |
94 @override | |
95 bool hasLibrarySummary(String uri) { | |
96 return uri.startsWith('dart:'); | |
97 } | |
98 } | |
99 | 20 |
100 /** | 21 /** |
101 * An implementation of [DartSdk] which provides analysis results for `dart:` | 22 * An implementation of [DartSdk] which provides analysis results for `dart:` |
102 * libraries from the given summary file. This implementation is limited and | 23 * libraries from the given summary file. This implementation is limited and |
103 * suitable only for command-line tools, but not for IDEs - it does not | 24 * suitable only for command-line tools, but not for IDEs - it does not |
104 * implement [sdkLibraries], [sdkVersion], [uris] and [fromFileUri]. | 25 * implement [sdkLibraries], [sdkVersion], [uris] and [fromFileUri]. |
105 */ | 26 */ |
106 class SummaryBasedDartSdk implements DartSdk { | 27 class SummaryBasedDartSdk implements DartSdk { |
107 final bool strongMode; | 28 final bool strongMode; |
108 SummaryDataStore _dataStore; | 29 SummaryDataStore _dataStore; |
(...skipping 27 matching lines...) Expand all Loading... |
136 | 57 |
137 @override | 58 @override |
138 AnalysisContext get context { | 59 AnalysisContext get context { |
139 if (_analysisContext == null) { | 60 if (_analysisContext == null) { |
140 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl() | 61 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl() |
141 ..strongMode = strongMode; | 62 ..strongMode = strongMode; |
142 _analysisContext = new SdkAnalysisContext(analysisOptions); | 63 _analysisContext = new SdkAnalysisContext(analysisOptions); |
143 SourceFactory factory = new SourceFactory( | 64 SourceFactory factory = new SourceFactory( |
144 [new DartUriResolver(this)], null, resourceProvider); | 65 [new DartUriResolver(this)], null, resourceProvider); |
145 _analysisContext.sourceFactory = factory; | 66 _analysisContext.sourceFactory = factory; |
| 67 SummaryDataStore dataStore = new SummaryDataStore([]); |
| 68 dataStore.addBundle(null, _bundle); |
146 _analysisContext.resultProvider = | 69 _analysisContext.resultProvider = |
147 new SdkSummaryResultProvider(_analysisContext, _bundle, strongMode); | 70 new InputPackagesResultProvider(_analysisContext, dataStore); |
148 } | 71 } |
149 return _analysisContext; | 72 return _analysisContext; |
150 } | 73 } |
151 | 74 |
152 @override | 75 @override |
153 List<SdkLibrary> get sdkLibraries { | 76 List<SdkLibrary> get sdkLibraries { |
154 throw new UnimplementedError(); | 77 throw new UnimplementedError(); |
155 } | 78 } |
156 | 79 |
157 @override | 80 @override |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 * throw a [StateError] if there is no class with the given name. | 335 * throw a [StateError] if there is no class with the given name. |
413 */ | 336 */ |
414 InterfaceType _getType(LibraryElement library, String name) { | 337 InterfaceType _getType(LibraryElement library, String name) { |
415 Element element = library.getType(name); | 338 Element element = library.getType(name); |
416 if (element == null) { | 339 if (element == null) { |
417 throw new StateError("No definition of type $name"); | 340 throw new StateError("No definition of type $name"); |
418 } | 341 } |
419 return (element as ClassElement).type; | 342 return (element as ClassElement).type; |
420 } | 343 } |
421 } | 344 } |
OLD | NEW |