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

Side by Side Diff: pkg/analyzer/lib/src/summary/summary_sdk.dart

Issue 2648213007: Revert "Use single InputPackagesResultProvider, without SdkSummaryResultProvider." (Closed)
Patch Set: Created 3 years, 10 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
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 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;
10 import 'package:analyzer/src/context/context.dart'; 11 import 'package:analyzer/src/context/context.dart';
11 import 'package:analyzer/src/dart/element/type.dart'; 12 import 'package:analyzer/src/dart/element/type.dart';
12 import 'package:analyzer/src/generated/constant.dart'; 13 import 'package:analyzer/src/generated/constant.dart';
13 import 'package:analyzer/src/generated/engine.dart'; 14 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/resolver.dart'; 15 import 'package:analyzer/src/generated/resolver.dart';
15 import 'package:analyzer/src/generated/sdk.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 DartUriResolver, Source, SourceFactory; 18 show DartUriResolver, Source, SourceFactory;
18 import 'package:analyzer/src/summary/idl.dart'; 19 import 'package:analyzer/src/summary/idl.dart';
19 import 'package:analyzer/src/summary/package_bundle_reader.dart'; 20 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 }
20 99
21 /** 100 /**
22 * An implementation of [DartSdk] which provides analysis results for `dart:` 101 * An implementation of [DartSdk] which provides analysis results for `dart:`
23 * libraries from the given summary file. This implementation is limited and 102 * libraries from the given summary file. This implementation is limited and
24 * suitable only for command-line tools, but not for IDEs - it does not 103 * suitable only for command-line tools, but not for IDEs - it does not
25 * implement [sdkLibraries], [sdkVersion], [uris] and [fromFileUri]. 104 * implement [sdkLibraries], [sdkVersion], [uris] and [fromFileUri].
26 */ 105 */
27 class SummaryBasedDartSdk implements DartSdk { 106 class SummaryBasedDartSdk implements DartSdk {
28 final bool strongMode; 107 final bool strongMode;
29 SummaryDataStore _dataStore; 108 SummaryDataStore _dataStore;
(...skipping 27 matching lines...) Expand all
57 136
58 @override 137 @override
59 AnalysisContext get context { 138 AnalysisContext get context {
60 if (_analysisContext == null) { 139 if (_analysisContext == null) {
61 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl() 140 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl()
62 ..strongMode = strongMode; 141 ..strongMode = strongMode;
63 _analysisContext = new SdkAnalysisContext(analysisOptions); 142 _analysisContext = new SdkAnalysisContext(analysisOptions);
64 SourceFactory factory = new SourceFactory( 143 SourceFactory factory = new SourceFactory(
65 [new DartUriResolver(this)], null, resourceProvider); 144 [new DartUriResolver(this)], null, resourceProvider);
66 _analysisContext.sourceFactory = factory; 145 _analysisContext.sourceFactory = factory;
67 SummaryDataStore dataStore = new SummaryDataStore([]);
68 dataStore.addBundle(null, _bundle);
69 _analysisContext.resultProvider = 146 _analysisContext.resultProvider =
70 new InputPackagesResultProvider(_analysisContext, dataStore); 147 new SdkSummaryResultProvider(_analysisContext, _bundle, strongMode);
71 } 148 }
72 return _analysisContext; 149 return _analysisContext;
73 } 150 }
74 151
75 @override 152 @override
76 List<SdkLibrary> get sdkLibraries { 153 List<SdkLibrary> get sdkLibraries {
77 throw new UnimplementedError(); 154 throw new UnimplementedError();
78 } 155 }
79 156
80 @override 157 @override
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 * throw a [StateError] if there is no class with the given name. 412 * throw a [StateError] if there is no class with the given name.
336 */ 413 */
337 InterfaceType _getType(LibraryElement library, String name) { 414 InterfaceType _getType(LibraryElement library, String name) {
338 Element element = library.getType(name); 415 Element element = library.getType(name);
339 if (element == null) { 416 if (element == null) {
340 throw new StateError("No definition of type $name"); 417 throw new StateError("No definition of type $name");
341 } 418 }
342 return (element as ClassElement).type; 419 return (element as ClassElement).type;
343 } 420 }
344 } 421 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_ast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698