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

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

Issue 2757753002: Migrate DDC to the new analysis driver.
Patch Set: Created 3 years, 9 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 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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
416 // The unit is the defining unit of a library. 415 // The unit is the defining unit of a library.
417 if (linkedMap.containsKey(unitUriString)) { 416 if (linkedMap.containsKey(unitUriString)) {
418 return <String>[unitUriString]; 417 return <String>[unitUriString];
419 } 418 }
420 // Check every unlinked unit whether it uses [unitUri] as a part. 419 // Check every unlinked unit whether it uses [unitUri] as a part.
421 List<String> libraryUriStrings = <String>[]; 420 List<String> libraryUriStrings = <String>[];
422 unlinkedMap.forEach((unlinkedUnitUriString, unlinkedUnit) { 421 unlinkedMap.forEach((unlinkedUnitUriString, unlinkedUnit) {
423 Uri libraryUri = Uri.parse(unlinkedUnitUriString); 422 Uri libraryUri = Uri.parse(unlinkedUnitUriString);
424 for (String partUriString in unlinkedUnit.publicNamespace.parts) { 423 for (String partUriString in unlinkedUnit.publicNamespace.parts) {
425 Uri partUri = Uri.parse(partUriString); 424 Uri partUri = Uri.parse(partUriString);
426 String partAbsoluteUriString = 425 String partAbsoluteUriString =
427 resolveRelativeUri(libraryUri, partUri).toString(); 426 resolveRelativeUri(libraryUri, partUri).toString();
428 if (partAbsoluteUriString == unitUriString) { 427 if (partAbsoluteUriString == unitUriString) {
429 libraryUriStrings.add(unlinkedUnitUriString); 428 libraryUriStrings.add(unlinkedUnitUriString);
430 } 429 }
431 } 430 }
432 }); 431 });
433 return libraryUriStrings.isNotEmpty ? libraryUriStrings : null; 432 return libraryUriStrings.isNotEmpty ? libraryUriStrings : null;
434 } 433 }
435 434
435 /**
436 * Return `true` if the store contains the unlinked summary for the unit
437 * with the given absolute [uri].
438 */
439 bool hasUnlinkedUnit(String uri) {
440 return unlinkedMap.containsKey(uri);
441 }
442
436 void _fillMaps(String path, ResourceProvider resourceProvider) { 443 void _fillMaps(String path, ResourceProvider resourceProvider) {
437 List<int> buffer; 444 List<int> buffer;
438 if (resourceProvider != null) { 445 if (resourceProvider != null) {
439 var file = resourceProvider.getFile(path); 446 var file = resourceProvider.getFile(path);
440 buffer = file.readAsBytesSync(); 447 buffer = file.readAsBytesSync();
441 } else { 448 } else {
442 io.File file = new io.File(path); 449 io.File file = new io.File(path);
443 buffer = file.readAsBytesSync(); 450 buffer = file.readAsBytesSync();
444 } 451 }
445 PackageBundle bundle = new PackageBundle.fromBuffer(buffer); 452 PackageBundle bundle = new PackageBundle.fromBuffer(buffer);
446 addBundle(path, bundle); 453 addBundle(path, bundle);
447 } 454 }
455
456 /**
457 * TODO(scheglov) document
458 */
459 void addStore(SummaryDataStore other) {
460 unlinkedMap.addAll(other.unlinkedMap);
461 linkedMap.addAll(other.linkedMap);
462 }
448 } 463 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698