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

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

Issue 1585843009: Chaining not just element requests but also summaries access. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Check parent in the abstract implementation. Created 4 years, 11 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/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/type.dart'; 11 import 'package:analyzer/src/dart/element/type.dart';
12 import 'package:analyzer/src/generated/constant.dart'; 12 import 'package:analyzer/src/generated/constant.dart';
13 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/resolver.dart'; 14 import 'package:analyzer/src/generated/resolver.dart';
14 import 'package:analyzer/src/generated/source.dart' show Source, SourceKind; 15 import 'package:analyzer/src/generated/source.dart';
15 import 'package:analyzer/src/summary/format.dart'; 16 import 'package:analyzer/src/summary/format.dart';
16 import 'package:analyzer/src/summary/resynthesize.dart'; 17 import 'package:analyzer/src/summary/resynthesize.dart';
17 import 'package:analyzer/src/task/dart.dart' 18 import 'package:analyzer/src/task/dart.dart'
18 show 19 show
19 LIBRARY_ELEMENT1, 20 LIBRARY_ELEMENT1,
20 LIBRARY_ELEMENT2, 21 LIBRARY_ELEMENT2,
21 LIBRARY_ELEMENT3, 22 LIBRARY_ELEMENT3,
22 LIBRARY_ELEMENT4, 23 LIBRARY_ELEMENT4,
23 LIBRARY_ELEMENT5, 24 LIBRARY_ELEMENT5,
24 LIBRARY_ELEMENT6, 25 LIBRARY_ELEMENT6,
25 LIBRARY_ELEMENT7, 26 LIBRARY_ELEMENT7,
26 LIBRARY_ELEMENT8, 27 LIBRARY_ELEMENT8,
27 READY_LIBRARY_ELEMENT2, 28 READY_LIBRARY_ELEMENT2,
28 READY_LIBRARY_ELEMENT5, 29 READY_LIBRARY_ELEMENT5,
29 READY_LIBRARY_ELEMENT6, 30 READY_LIBRARY_ELEMENT6,
30 TYPE_PROVIDER; 31 TYPE_PROVIDER;
31 import 'package:analyzer/task/dart.dart'; 32 import 'package:analyzer/task/dart.dart';
32 import 'package:analyzer/task/model.dart' 33 import 'package:analyzer/task/model.dart'
33 show AnalysisTarget, ResultDescriptor, TargetedResult; 34 show AnalysisTarget, ResultDescriptor, TargetedResult;
34 35
35 /** 36 /**
37 * The implementation of [SummaryResynthesizer] for Dart SDK.
38 */
39 class SdkSummaryResynthesizer extends SummaryResynthesizer {
40 final SdkBundle bundle;
41 final Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{};
42 final Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{};
43
44 SdkSummaryResynthesizer(AnalysisContext context, TypeProvider typeProvider,
45 SourceFactory sourceFactory, this.bundle)
46 : super(null, context, typeProvider, sourceFactory) {
47 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) {
48 unlinkedSummaries[bundle.unlinkedUnitUris[i]] = bundle.unlinkedUnits[i];
49 }
50 for (int i = 0; i < bundle.linkedLibraryUris.length; i++) {
51 linkedSummaries[bundle.linkedLibraryUris[i]] = bundle.linkedLibraries[i];
52 }
53 }
54
55 @override
56 LinkedLibrary getLinkedSummary(String uri) {
57 return linkedSummaries[uri];
58 }
59
60 @override
61 UnlinkedUnit getUnlinkedSummary(String uri) {
62 return unlinkedSummaries[uri];
63 }
64
65 @override
66 bool hasLibrarySummary(String uri) {
67 return uri.startsWith('dart:');
68 }
69 }
70
71 /**
36 * An [SdkAnalysisContext] for Dart SDK with a summary [SdkBundle]. 72 * An [SdkAnalysisContext] for Dart SDK with a summary [SdkBundle].
37 */ 73 */
38 class SummarySdkAnalysisContext extends SdkAnalysisContext { 74 class SummarySdkAnalysisContext extends SdkAnalysisContext {
39 final SdkBundle bundle; 75 final SdkBundle bundle;
40 final SummaryTypeProvider typeProvider = new SummaryTypeProvider(); 76 final SummaryTypeProvider typeProvider = new SummaryTypeProvider();
41 77
42 SummaryResynthesizer resynthesizer; 78 SummaryResynthesizer resynthesizer;
43 79
44 SummarySdkAnalysisContext(this.bundle); 80 SummarySdkAnalysisContext(this.bundle);
45 81
46 @override 82 @override
47 bool aboutToComputeResult(CacheEntry entry, ResultDescriptor result) { 83 bool aboutToComputeResult(CacheEntry entry, ResultDescriptor result) {
48 if (resynthesizer == null) { 84 if (resynthesizer == null) {
49 resynthesizer = new SummaryResynthesizer( 85 resynthesizer = new SdkSummaryResynthesizer(
50 null, 86 this, typeProvider, sourceFactory, bundle);
51 this,
52 typeProvider,
53 (String uri) => uri.startsWith('dart:'),
54 _getLinkedSummary,
55 _getUnlinkedSummary,
56 sourceFactory);
57 _buildCoreLibrary(); 87 _buildCoreLibrary();
58 _buildAsyncLibrary(); 88 _buildAsyncLibrary();
59 } 89 }
60 if (result == TYPE_PROVIDER) { 90 if (result == TYPE_PROVIDER) {
61 entry.setValue(result, typeProvider, TargetedResult.EMPTY_LIST); 91 entry.setValue(result, typeProvider, TargetedResult.EMPTY_LIST);
62 return true; 92 return true;
63 } 93 }
64 AnalysisTarget target = entry.target; 94 AnalysisTarget target = entry.target;
65 // print('SummarySdkAnalysisContext: $result of $target'); 95 // print('SummarySdkAnalysisContext: $result of $target');
66 if (target is Source && target.isInSystemLibrary) { 96 if (target is Source && target.isInSystemLibrary) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 134
105 void _buildAsyncLibrary() { 135 void _buildAsyncLibrary() {
106 LibraryElement library = resynthesizer.getLibraryElement('dart:async'); 136 LibraryElement library = resynthesizer.getLibraryElement('dart:async');
107 typeProvider.initializeAsync(library); 137 typeProvider.initializeAsync(library);
108 } 138 }
109 139
110 void _buildCoreLibrary() { 140 void _buildCoreLibrary() {
111 LibraryElement library = resynthesizer.getLibraryElement('dart:core'); 141 LibraryElement library = resynthesizer.getLibraryElement('dart:core');
112 typeProvider.initializeCore(library); 142 typeProvider.initializeCore(library);
113 } 143 }
114
115 LinkedLibrary _getLinkedSummary(String uri) {
116 for (int i = 0; i < bundle.linkedLibraryUris.length; i++) {
117 if (bundle.linkedLibraryUris[i] == uri) {
118 return bundle.linkedLibraries[i];
119 }
120 }
121 throw new StateError('Unable to find linked summary for $uri');
122 }
123
124 UnlinkedUnit _getUnlinkedSummary(String uri) {
125 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) {
126 if (bundle.unlinkedUnitUris[i] == uri) {
127 return bundle.unlinkedUnits[i];
128 }
129 }
130 throw new StateError('Unable to find unlinked summary for $uri');
131 }
132 } 144 }
133 145
134 /** 146 /**
135 * Implementation of [TypeProvider] which can be initialized separately with 147 * Implementation of [TypeProvider] which can be initialized separately with
136 * `dart:core` and `dart:async` libraries. 148 * `dart:core` and `dart:async` libraries.
137 */ 149 */
138 class SummaryTypeProvider implements TypeProvider { 150 class SummaryTypeProvider implements TypeProvider {
139 bool _isCoreInitialized = false; 151 bool _isCoreInitialized = false;
140 bool _isAsyncInitialized = false; 152 bool _isAsyncInitialized = false;
141 153
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 * throw a [StateError] if there is no class with the given name. 371 * throw a [StateError] if there is no class with the given name.
360 */ 372 */
361 InterfaceType _getType(LibraryElement library, String name) { 373 InterfaceType _getType(LibraryElement library, String name) {
362 Element element = library.getType(name); 374 Element element = library.getType(name);
363 if (element == null) { 375 if (element == null) {
364 throw new StateError("No definition of type $name"); 376 throw new StateError("No definition of type $name");
365 } 377 }
366 return (element as ClassElement).type; 378 return (element as ClassElement).type;
367 } 379 }
368 } 380 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698