| OLD | NEW |
| 1 import 'dart:io' as io; | 1 import 'dart:io' as io; |
| 2 | 2 |
| 3 import 'package:analyzer/dart/element/element.dart'; | 3 import 'package:analyzer/dart/element/element.dart'; |
| 4 import 'package:analyzer/file_system/file_system.dart'; | 4 import 'package:analyzer/file_system/file_system.dart'; |
| 5 import 'package:analyzer/src/context/cache.dart'; | 5 import 'package:analyzer/src/context/cache.dart'; |
| 6 import 'package:analyzer/src/context/context.dart'; | 6 import 'package:analyzer/src/context/context.dart'; |
| 7 import 'package:analyzer/src/dart/element/element.dart'; | 7 import 'package:analyzer/src/dart/element/element.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart'; | 8 import 'package:analyzer/src/generated/engine.dart'; |
| 9 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 9 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
| 10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 */ | 341 */ |
| 342 final Map<String, String> uriToSummaryPath = <String, String>{}; | 342 final Map<String, String> uriToSummaryPath = <String, String>{}; |
| 343 | 343 |
| 344 /** | 344 /** |
| 345 * Create a [SummaryDataStore] and populate it with the summaries in | 345 * Create a [SummaryDataStore] and populate it with the summaries in |
| 346 * [summaryPaths]. If [recordDependencyInfo] is `true`, record | 346 * [summaryPaths]. If [recordDependencyInfo] is `true`, record |
| 347 * [PackageDependencyInfo] for each summary, for later access via | 347 * [PackageDependencyInfo] for each summary, for later access via |
| 348 * [dependencies]. | 348 * [dependencies]. |
| 349 */ | 349 */ |
| 350 SummaryDataStore(Iterable<String> summaryPaths, | 350 SummaryDataStore(Iterable<String> summaryPaths, |
| 351 {bool recordDependencyInfo: false}) | 351 {bool recordDependencyInfo: false, ResourceProvider resourceProvider}) |
| 352 : dependencies = | 352 : dependencies = |
| 353 recordDependencyInfo ? <PackageDependencyInfoBuilder>[] : null { | 353 recordDependencyInfo ? <PackageDependencyInfoBuilder>[] : null { |
| 354 summaryPaths.forEach(_fillMaps); | 354 summaryPaths.forEach((String path) => _fillMaps(path, resourceProvider)); |
| 355 } | 355 } |
| 356 | 356 |
| 357 /** | 357 /** |
| 358 * Add the given [bundle] loaded from the file with the given [path]. | 358 * Add the given [bundle] loaded from the file with the given [path]. |
| 359 */ | 359 */ |
| 360 void addBundle(String path, PackageBundle bundle) { | 360 void addBundle(String path, PackageBundle bundle) { |
| 361 bundles.add(bundle); | 361 bundles.add(bundle); |
| 362 if (dependencies != null) { | 362 if (dependencies != null) { |
| 363 Set<String> includedPackageNames = new Set<String>(); | 363 Set<String> includedPackageNames = new Set<String>(); |
| 364 bool includesDartUris = false; | 364 bool includesDartUris = false; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 */ | 405 */ |
| 406 void addUnlinkedUnit(String uri, UnlinkedUnit unlinkedUnit) { | 406 void addUnlinkedUnit(String uri, UnlinkedUnit unlinkedUnit) { |
| 407 unlinkedMap[uri] = unlinkedUnit; | 407 unlinkedMap[uri] = unlinkedUnit; |
| 408 } | 408 } |
| 409 | 409 |
| 410 /** | 410 /** |
| 411 * Return a list of absolute URIs of the libraries that contain the unit with | 411 * Return a list of absolute URIs of the libraries that contain the unit with |
| 412 * the given [unitUriString], or `null` if no such library is in the store. | 412 * the given [unitUriString], or `null` if no such library is in the store. |
| 413 */ | 413 */ |
| 414 List<String> getContainingLibraryUris(String unitUriString) { | 414 List<String> getContainingLibraryUris(String unitUriString) { |
| 415 |
| 415 // The unit is the defining unit of a library. | 416 // The unit is the defining unit of a library. |
| 416 if (linkedMap.containsKey(unitUriString)) { | 417 if (linkedMap.containsKey(unitUriString)) { |
| 417 return <String>[unitUriString]; | 418 return <String>[unitUriString]; |
| 418 } | 419 } |
| 419 // Check every unlinked unit whether it uses [unitUri] as a part. | 420 // Check every unlinked unit whether it uses [unitUri] as a part. |
| 420 List<String> libraryUriStrings = <String>[]; | 421 List<String> libraryUriStrings = <String>[]; |
| 421 unlinkedMap.forEach((unlinkedUnitUriString, unlinkedUnit) { | 422 unlinkedMap.forEach((unlinkedUnitUriString, unlinkedUnit) { |
| 422 Uri libraryUri = Uri.parse(unlinkedUnitUriString); | 423 Uri libraryUri = Uri.parse(unlinkedUnitUriString); |
| 423 for (String partUriString in unlinkedUnit.publicNamespace.parts) { | 424 for (String partUriString in unlinkedUnit.publicNamespace.parts) { |
| 424 Uri partUri = Uri.parse(partUriString); | 425 Uri partUri = Uri.parse(partUriString); |
| 425 String partAbsoluteUriString = | 426 String partAbsoluteUriString = |
| 426 resolveRelativeUri(libraryUri, partUri).toString(); | 427 resolveRelativeUri(libraryUri, partUri).toString(); |
| 427 if (partAbsoluteUriString == unitUriString) { | 428 if (partAbsoluteUriString == unitUriString) { |
| 428 libraryUriStrings.add(unlinkedUnitUriString); | 429 libraryUriStrings.add(unlinkedUnitUriString); |
| 429 } | 430 } |
| 430 } | 431 } |
| 431 }); | 432 }); |
| 432 return libraryUriStrings.isNotEmpty ? libraryUriStrings : null; | 433 return libraryUriStrings.isNotEmpty ? libraryUriStrings : null; |
| 433 } | 434 } |
| 434 | 435 |
| 435 void _fillMaps(String path) { | 436 void _fillMaps(String path, ResourceProvider resourceProvider) { |
| 436 io.File file = new io.File(path); | 437 List<int> buffer; |
| 437 List<int> buffer = file.readAsBytesSync(); | 438 if (resourceProvider != null) { |
| 439 var file = resourceProvider.getFile(path); |
| 440 buffer = file.readAsBytesSync(); |
| 441 } else { |
| 442 io.File file = new io.File(path); |
| 443 buffer = file.readAsBytesSync(); |
| 444 } |
| 438 PackageBundle bundle = new PackageBundle.fromBuffer(buffer); | 445 PackageBundle bundle = new PackageBundle.fromBuffer(buffer); |
| 439 addBundle(path, bundle); | 446 addBundle(path, bundle); |
| 440 } | 447 } |
| 441 } | 448 } |
| OLD | NEW |