| 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/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' |
| 16 show DartUriResolver, Source, SourceFactory, SourceKind; |
| 15 import 'package:analyzer/src/summary/format.dart'; | 17 import 'package:analyzer/src/summary/format.dart'; |
| 16 import 'package:analyzer/src/summary/resynthesize.dart'; | 18 import 'package:analyzer/src/summary/resynthesize.dart'; |
| 17 import 'package:analyzer/src/task/dart.dart' | 19 import 'package:analyzer/src/task/dart.dart' |
| 18 show | 20 show |
| 19 LIBRARY_ELEMENT1, | 21 LIBRARY_ELEMENT1, |
| 20 LIBRARY_ELEMENT2, | 22 LIBRARY_ELEMENT2, |
| 21 LIBRARY_ELEMENT3, | 23 LIBRARY_ELEMENT3, |
| 22 LIBRARY_ELEMENT4, | 24 LIBRARY_ELEMENT4, |
| 23 LIBRARY_ELEMENT5, | 25 LIBRARY_ELEMENT5, |
| 24 LIBRARY_ELEMENT6, | 26 LIBRARY_ELEMENT6, |
| 25 LIBRARY_ELEMENT7, | 27 LIBRARY_ELEMENT7, |
| 26 LIBRARY_ELEMENT8, | 28 LIBRARY_ELEMENT8, |
| 27 READY_LIBRARY_ELEMENT2, | 29 READY_LIBRARY_ELEMENT2, |
| 28 READY_LIBRARY_ELEMENT5, | 30 READY_LIBRARY_ELEMENT5, |
| 29 READY_LIBRARY_ELEMENT6, | 31 READY_LIBRARY_ELEMENT6, |
| 30 TYPE_PROVIDER; | 32 TYPE_PROVIDER; |
| 31 import 'package:analyzer/task/dart.dart'; | 33 import 'package:analyzer/task/dart.dart'; |
| 32 import 'package:analyzer/task/model.dart' | 34 import 'package:analyzer/task/model.dart' |
| 33 show AnalysisTarget, ResultDescriptor, TargetedResult; | 35 show AnalysisTarget, ResultDescriptor, TargetedResult; |
| 34 | 36 |
| 35 /** | 37 class SdkSummaryResultProvider extends AboutToComputeResultHelper { |
| 36 * An [SdkAnalysisContext] for Dart SDK with a summary [SdkBundle]. | |
| 37 */ | |
| 38 class SummarySdkAnalysisContext extends SdkAnalysisContext { | |
| 39 final SdkBundle bundle; | 38 final SdkBundle bundle; |
| 40 final SummaryTypeProvider typeProvider = new SummaryTypeProvider(); | 39 final SummaryTypeProvider typeProvider = new SummaryTypeProvider(); |
| 40 SummaryResynthesizer summaryResynthesizer; |
| 41 | 41 |
| 42 SummaryResynthesizer resynthesizer; | 42 SdkSummaryResultProvider(InternalAnalysisContext context, this.bundle) |
| 43 | 43 : super(context) { |
| 44 SummarySdkAnalysisContext(this.bundle); | 44 summaryResynthesizer = new SummaryResynthesizer(context, typeProvider, |
| 45 _getPrelinkedSummary, _getUnlinkedSummary, context.sourceFactory); |
| 46 _buildCoreLibrary(); |
| 47 _buildAsyncLibrary(); |
| 48 summaryResynthesizer.finalizeCoreAsyncLibraries(); |
| 49 } |
| 45 | 50 |
| 46 @override | 51 @override |
| 47 bool aboutToComputeResult(CacheEntry entry, ResultDescriptor result) { | 52 bool compute(CacheEntry entry, ResultDescriptor result) { |
| 48 if (resynthesizer == null) { | |
| 49 resynthesizer = new SummaryResynthesizer(this, typeProvider, | |
| 50 _getPrelinkedSummary, _getUnlinkedSummary, sourceFactory); | |
| 51 _buildCoreLibrary(); | |
| 52 _buildAsyncLibrary(); | |
| 53 } | |
| 54 if (result == TYPE_PROVIDER) { | 53 if (result == TYPE_PROVIDER) { |
| 54 // print('SummarySdkAnalysisContext: $result'); |
| 55 entry.setValue(result, typeProvider, TargetedResult.EMPTY_LIST); | 55 entry.setValue(result, typeProvider, TargetedResult.EMPTY_LIST); |
| 56 return true; | 56 return true; |
| 57 } | 57 } |
| 58 AnalysisTarget target = entry.target; | 58 AnalysisTarget target = entry.target; |
| 59 // print('SummarySdkAnalysisContext: $result of $target'); | |
| 60 if (target is Source && target.isInSystemLibrary) { | 59 if (target is Source && target.isInSystemLibrary) { |
| 60 // print('SummarySdkAnalysisContext: $result of $target'); |
| 61 if (result == LIBRARY_ELEMENT1 || | 61 if (result == LIBRARY_ELEMENT1 || |
| 62 result == LIBRARY_ELEMENT2 || | 62 result == LIBRARY_ELEMENT2 || |
| 63 result == LIBRARY_ELEMENT3 || | 63 result == LIBRARY_ELEMENT3 || |
| 64 result == LIBRARY_ELEMENT4 || | 64 result == LIBRARY_ELEMENT4 || |
| 65 result == LIBRARY_ELEMENT5 || | 65 result == LIBRARY_ELEMENT5 || |
| 66 result == LIBRARY_ELEMENT6 || | 66 result == LIBRARY_ELEMENT6 || |
| 67 result == LIBRARY_ELEMENT7 || | 67 result == LIBRARY_ELEMENT7 || |
| 68 result == LIBRARY_ELEMENT8 || | 68 result == LIBRARY_ELEMENT8 || |
| 69 result == LIBRARY_ELEMENT) { | 69 result == LIBRARY_ELEMENT) { |
| 70 // TODO(scheglov) try to find a way to avoid listing every result | 70 // TODO(scheglov) try to find a way to avoid listing every result |
| 71 // e.g. "result.whenComplete == LIBRARY_ELEMENT" | 71 // e.g. "result.whenComplete == LIBRARY_ELEMENT" |
| 72 String uri = target.uri.toString(); | 72 String uri = target.uri.toString(); |
| 73 LibraryElement libraryElement = resynthesizer.getLibraryElement(uri); | 73 LibraryElement libraryElement = |
| 74 summaryResynthesizer.getLibraryElement(uri); |
| 74 entry.setValue(result, libraryElement, TargetedResult.EMPTY_LIST); | 75 entry.setValue(result, libraryElement, TargetedResult.EMPTY_LIST); |
| 75 return true; | 76 return true; |
| 76 } else if (result == READY_LIBRARY_ELEMENT2 || | 77 } else if (result == READY_LIBRARY_ELEMENT2 || |
| 77 result == READY_LIBRARY_ELEMENT5 || | 78 result == READY_LIBRARY_ELEMENT5 || |
| 78 result == READY_LIBRARY_ELEMENT6) { | 79 result == READY_LIBRARY_ELEMENT6) { |
| 79 entry.setValue(result, true, TargetedResult.EMPTY_LIST); | 80 entry.setValue(result, true, TargetedResult.EMPTY_LIST); |
| 80 return true; | 81 return true; |
| 81 } else if (result == SOURCE_KIND) { | 82 } else if (result == SOURCE_KIND) { |
| 82 String uri = target.uri.toString(); | 83 String uri = target.uri.toString(); |
| 83 if (bundle.prelinkedLibraryUris.contains(uri)) { | 84 SourceKind kind = _getSourceKind(uri); |
| 84 entry.setValue(result, SourceKind.LIBRARY, TargetedResult.EMPTY_LIST); | 85 if (kind != null) { |
| 85 return true; | 86 entry.setValue(result, kind, TargetedResult.EMPTY_LIST); |
| 86 } | |
| 87 if (bundle.unlinkedUnitUris.contains(uri)) { | |
| 88 entry.setValue(result, SourceKind.PART, TargetedResult.EMPTY_LIST); | |
| 89 return true; | 87 return true; |
| 90 } | 88 } |
| 91 return false; | 89 return false; |
| 92 } else { | 90 } else { |
| 93 // throw new UnimplementedError('$result of $target'); | 91 // throw new UnimplementedError('$result of $target'); |
| 94 } | 92 } |
| 95 } | 93 } |
| 96 return false; | 94 return false; |
| 97 } | 95 } |
| 98 | 96 |
| 99 void _buildAsyncLibrary() { | 97 void _buildAsyncLibrary() { |
| 100 LibraryElement library = resynthesizer.getLibraryElement('dart:async'); | 98 LibraryElement library = |
| 99 summaryResynthesizer.getLibraryElement('dart:async'); |
| 101 typeProvider.initializeAsync(library); | 100 typeProvider.initializeAsync(library); |
| 102 } | 101 } |
| 103 | 102 |
| 104 void _buildCoreLibrary() { | 103 void _buildCoreLibrary() { |
| 105 LibraryElement library = resynthesizer.getLibraryElement('dart:core'); | 104 LibraryElement library = |
| 105 summaryResynthesizer.getLibraryElement('dart:core'); |
| 106 typeProvider.initializeCore(library); | 106 typeProvider.initializeCore(library); |
| 107 } | 107 } |
| 108 | 108 |
| 109 /** |
| 110 * Return the [PrelinkedLibrary] for the given [uri] or throw [StateError]. |
| 111 */ |
| 109 PrelinkedLibrary _getPrelinkedSummary(String uri) { | 112 PrelinkedLibrary _getPrelinkedSummary(String uri) { |
| 110 for (int i = 0; i < bundle.prelinkedLibraryUris.length; i++) { | 113 for (int i = 0; i < bundle.prelinkedLibraryUris.length; i++) { |
| 111 if (bundle.prelinkedLibraryUris[i] == uri) { | 114 if (bundle.prelinkedLibraryUris[i] == uri) { |
| 112 return bundle.prelinkedLibraries[i]; | 115 return bundle.prelinkedLibraries[i]; |
| 113 } | 116 } |
| 114 } | 117 } |
| 115 throw new StateError('Unable to find prelinked summary for $uri'); | 118 throw new StateError('Unable to find prelinked summary for $uri'); |
| 116 } | 119 } |
| 117 | 120 |
| 121 /** |
| 122 * Return the [SourceKind] of the given [uri] or `null` if it is unknown. |
| 123 */ |
| 124 SourceKind _getSourceKind(String uri) { |
| 125 if (bundle.prelinkedLibraryUris.contains(uri)) { |
| 126 return SourceKind.LIBRARY; |
| 127 } |
| 128 if (bundle.unlinkedUnitUris.contains(uri)) { |
| 129 return SourceKind.PART; |
| 130 } |
| 131 return null; |
| 132 } |
| 133 |
| 134 /** |
| 135 * Return the [UnlinkedUnit] for the given [uri] or throw [StateError]. |
| 136 */ |
| 118 UnlinkedUnit _getUnlinkedSummary(String uri) { | 137 UnlinkedUnit _getUnlinkedSummary(String uri) { |
| 119 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) { | 138 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) { |
| 120 if (bundle.unlinkedUnitUris[i] == uri) { | 139 if (bundle.unlinkedUnitUris[i] == uri) { |
| 121 return bundle.unlinkedUnits[i]; | 140 return bundle.unlinkedUnits[i]; |
| 122 } | 141 } |
| 123 } | 142 } |
| 124 throw new StateError('Unable to find unlinked summary for $uri'); | 143 throw new StateError('Unable to find unlinked summary for $uri'); |
| 125 } | 144 } |
| 126 } | 145 } |
| 127 | 146 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 * throw a [StateError] if there is no class with the given name. | 372 * throw a [StateError] if there is no class with the given name. |
| 354 */ | 373 */ |
| 355 InterfaceType _getType(LibraryElement library, String name) { | 374 InterfaceType _getType(LibraryElement library, String name) { |
| 356 Element element = library.getType(name); | 375 Element element = library.getType(name); |
| 357 if (element == null) { | 376 if (element == null) { |
| 358 throw new StateError("No definition of type $name"); | 377 throw new StateError("No definition of type $name"); |
| 359 } | 378 } |
| 360 return (element as ClassElement).type; | 379 return (element as ClassElement).type; |
| 361 } | 380 } |
| 362 } | 381 } |
| OLD | NEW |