OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:convert'; | 5 import 'dart:convert'; |
6 | 6 |
7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
8 import 'package:analyzer/src/generated/engine.dart'; | 8 import 'package:analyzer/src/generated/engine.dart'; |
9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
10 import 'package:analyzer/src/generated/utilities_collection.dart'; | 10 import 'package:analyzer/src/generated/utilities_collection.dart'; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 final PackageBundle sdkBundle; | 103 final PackageBundle sdkBundle; |
104 | 104 |
105 /** | 105 /** |
106 * Mapping from bundle paths to corresponding [Package]s. The packages in | 106 * Mapping from bundle paths to corresponding [Package]s. The packages in |
107 * the map were consistent with their constituent sources at the moment when | 107 * the map were consistent with their constituent sources at the moment when |
108 * they were put into the map. | 108 * they were put into the map. |
109 */ | 109 */ |
110 final Map<Folder, List<Package>> folderToPackagesMap = {}; | 110 final Map<Folder, List<Package>> folderToPackagesMap = {}; |
111 | 111 |
112 /** | 112 /** |
113 * Mapping from [Uri]s to corresponding [_LinkNode]s. | 113 * Mapping from [Uri]s to corresponding [Package]s. |
114 */ | 114 */ |
115 final Map<Uri, _LinkNode> uriToNodeMap = {}; | 115 final Map<Uri, Package> uriToPackageMap = {}; |
| 116 |
| 117 /** |
| 118 * Mapping from [Package]s to corresponding [_LinkNode]s. |
| 119 */ |
| 120 final Map<Package, _LinkNode> packageToNodeMap = {}; |
116 | 121 |
117 SummaryProvider(this.provider, this.getOutputFolder, AnalysisContext context) | 122 SummaryProvider(this.provider, this.getOutputFolder, AnalysisContext context) |
118 : context = context, | 123 : context = context, |
119 sdkBundle = context.sourceFactory.dartSdk?.getLinkedBundle(); | 124 sdkBundle = context.sourceFactory.dartSdk?.getLinkedBundle(); |
120 | 125 |
121 /** | 126 /** |
122 * Return the complete list of [Package]s that are required to provide all | 127 * Return the complete list of [Package]s that are required to provide all |
123 * resolution results for the given [source]. | 128 * resolution results for the given [source]. |
124 * | 129 * |
125 * The same list of packages is returned for the same [Source], i.e. always | 130 * The same list of packages is returned for the same [Source], i.e. always |
(...skipping 29 matching lines...) Expand all Loading... |
155 .where((package) => package.linked != null) | 160 .where((package) => package.linked != null) |
156 .toList(); | 161 .toList(); |
157 } | 162 } |
158 | 163 |
159 /** | 164 /** |
160 * Return the [Package] that contains information about the source with | 165 * Return the [Package] that contains information about the source with |
161 * the given [uri], or `null` if such package does not exist. | 166 * the given [uri], or `null` if such package does not exist. |
162 */ | 167 */ |
163 @visibleForTesting | 168 @visibleForTesting |
164 Package getUnlinkedForUri(Uri uri) { | 169 Package getUnlinkedForUri(Uri uri) { |
165 Folder outputFolder = getOutputFolder(uri); | 170 return uriToPackageMap.putIfAbsent(uri, () { |
166 if (outputFolder != null) { | 171 Folder outputFolder = getOutputFolder(uri); |
167 String uriStr = uri.toString(); | 172 if (outputFolder != null) { |
168 List<Package> packages = _getUnlinkedPackages(outputFolder); | 173 String uriStr = uri.toString(); |
169 for (Package package in packages) { | 174 List<Package> packages = _getUnlinkedPackages(outputFolder); |
170 if (package._unitUris.contains(uriStr)) { | 175 for (Package package in packages) { |
171 return package; | 176 if (package._unitUris.contains(uriStr)) { |
| 177 return package; |
| 178 } |
172 } | 179 } |
173 } | 180 } |
174 } | 181 return null; |
175 return null; | 182 }); |
176 } | 183 } |
177 | 184 |
178 /** | 185 /** |
179 * Return the hexadecimal string of the MD5 hash of the contents of the | 186 * Return the hexadecimal string of the MD5 hash of the contents of the |
180 * given [source] in [context]. | 187 * given [source] in [context]. |
181 */ | 188 */ |
182 String _computeSourceHashHex(Source source) { | 189 String _computeSourceHashHex(Source source) { |
183 String text = context.getContents(source).data; | 190 String text = context.getContents(source).data; |
184 List<int> bytes = UTF8.encode(text); | 191 List<int> bytes = UTF8.encode(text); |
185 List<int> hashBytes = md5.convert(bytes).bytes; | 192 List<int> hashBytes = md5.convert(bytes).bytes; |
186 return hex.encode(hashBytes); | 193 return hex.encode(hashBytes); |
187 } | 194 } |
188 | 195 |
189 /** | 196 /** |
190 * Return the node for the given [uri], or `null` if there is no unlinked | 197 * Return the node for the given [uri], or `null` if there is no unlinked |
191 * bundle that contains [uri]. | 198 * bundle that contains [uri]. |
192 */ | 199 */ |
193 _LinkNode _getLinkNodeForUri(Uri uri) { | 200 _LinkNode _getLinkNodeForUri(Uri uri) { |
194 return uriToNodeMap.putIfAbsent(uri, () { | 201 Package package = getUnlinkedForUri(uri); |
195 Package package = getUnlinkedForUri(uri); | 202 return packageToNodeMap.putIfAbsent(package, () { |
196 if (package == null) { | 203 if (package == null) { |
197 return null; | 204 return null; |
198 } | 205 } |
199 return new _LinkNode(this, package); | 206 return new _LinkNode(this, package); |
200 }); | 207 }); |
201 } | 208 } |
202 | 209 |
203 /** | 210 /** |
204 * Return all consistent unlinked [Package]s in the given [folder]. Some of | 211 * Return all consistent unlinked [Package]s in the given [folder]. Some of |
205 * the returned packages might be already linked. | 212 * the returned packages might be already linked. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 appendDependencies(this); | 409 appendDependencies(this); |
403 if (transitiveDependencies.any((node) => node.failed)) { | 410 if (transitiveDependencies.any((node) => node.failed)) { |
404 failed = true; | 411 failed = true; |
405 } | 412 } |
406 } | 413 } |
407 } | 414 } |
408 | 415 |
409 @override | 416 @override |
410 String toString() => package.toString(); | 417 String toString() => package.toString(); |
411 } | 418 } |
OLD | NEW |