@@ -7,7 +7,6 @@ import '../builder/declaration_builders.dart';
77import '../builder/library_builder.dart' ;
88import '../builder/member_builder.dart' ;
99import '../builder/property_builder.dart' ;
10- import '../dill/dill_library_builder.dart' ;
1110import 'lookup_result.dart' ;
1211import 'scope.dart' ;
1312import 'uris.dart' ;
@@ -375,53 +374,17 @@ final class DillDeclarationNameSpace extends DeclarationNameSpaceBase {
375374 DillDeclarationNameSpace () : super ._();
376375}
377376
378- abstract base class LazyNameSpace extends ComputedMutableNameSpaceImpl {
379- LazyNameSpace () : super ._();
380-
381- /// Override this method to lazily populate the scope before access.
382- void ensureNameSpace ();
383-
384- @override
385- Map <String , LookupResult >? get _content {
386- ensureNameSpace ();
387- return super ._content;
388- }
389-
390- @override
391- Set <ExtensionBuilder >? get _extensions {
392- ensureNameSpace ();
393- return super ._extensions;
394- }
395- }
396-
397- final class DillLibraryNameSpace extends LazyNameSpace {
398- final DillLibraryBuilder _libraryBuilder;
399-
400- DillLibraryNameSpace (this ._libraryBuilder);
401-
402- @override
403- void ensureNameSpace () {
404- _libraryBuilder.ensureLoaded ();
405- }
377+ final class DillLibraryNameSpace extends ComputedMutableNameSpaceImpl {
378+ DillLibraryNameSpace () : super ._();
406379}
407380
408- final class DillExportNameSpace extends LazyNameSpace {
409- final DillLibraryBuilder _libraryBuilder;
410-
411- DillExportNameSpace (this ._libraryBuilder);
412-
413- @override
414- void ensureNameSpace () {
415- _libraryBuilder.ensureLoaded ();
416- }
381+ final class DillExportNameSpace extends ComputedMutableNameSpaceImpl {
382+ DillExportNameSpace () : super ._();
417383
418384 /// Patch up the scope, using the two replacement maps to replace builders in
419385 /// scope. The replacement maps from old LibraryBuilder to map, mapping
420386 /// from name to new (replacement) builder.
421- void patchUpScope (
422- Map <LibraryBuilder , Map <String , NamedBuilder >> replacementMap,
423- Map <LibraryBuilder , Map <String , NamedBuilder >> replacementMapSetters,
424- Map <LibraryBuilder , NameSpace > replacementLookupMap) {
387+ void patchUpScope (Map <LibraryBuilder , NameSpace > replacementNameSpaceMap) {
425388 // In the following we refer to non-setters as 'getters' for brevity.
426389 //
427390 // We have to replace all getters and setters in [_locals] and [_setters]
@@ -435,70 +398,71 @@ final class DillExportNameSpace extends LazyNameSpace {
435398 // For this reason we start by collecting the names of all getters/setters
436399 // that need (some) replacement. Afterwards we go through these names
437400 // handling both getters and setters at the same time.
438- {
439- Set <String > replacedNames = {};
440- _content? .forEach ((String name, LookupResult result) {
441- if (replacementMap.containsKey (result.getable? .parent)) {
442- replacedNames.add (name);
443- }
444- if (replacementMapSetters.containsKey (result.setable? .parent)) {
445- replacedNames.add (name);
446- }
447- });
448- if (replacedNames.isNotEmpty) {
449- for (String name in replacedNames) {
450- // We start be collecting the relation between an existing getter/setter
451- // and the getter/setter that will replace it. This information is used
452- // below to handle all the different cases that can occur.
453- LookupResult existingResult = _content! [name]! ;
454- NamedBuilder ? existingGetter = existingResult.getable;
455- NamedBuilder ? existingSetter = existingResult.setable;
456- LookupResult ? replacementResult;
457- if (existingGetter != null && existingSetter != null ) {
458- if (existingGetter == existingSetter) {
459- replacementResult = replacementLookupMap[existingGetter.parent]!
460- .lookupLocalMember (name);
461- } else {
462- NamedBuilder ? replacementGetter =
463- replacementLookupMap[existingGetter.parent]
464- ? .lookupLocalMember (name)
465- ? .getable;
466- NamedBuilder ? replacementSetter =
467- replacementLookupMap[existingSetter.parent]
468- ? .lookupLocalMember (name)
469- ? .setable;
470- replacementResult = LookupResult .createResult (
471- replacementGetter ?? existingGetter,
472- replacementSetter ?? existingSetter);
473- }
474- } else if (existingGetter != null ) {
475- replacementResult = LookupResult .createResult (
476- replacementLookupMap[existingGetter.parent]
401+
402+ Set <String > replacedNames = {};
403+ _content? .forEach ((String name, LookupResult result) {
404+ if (replacementNameSpaceMap.containsKey (result.getable? .parent)) {
405+ replacedNames.add (name);
406+ }
407+ if (replacementNameSpaceMap.containsKey (result.setable? .parent)) {
408+ replacedNames.add (name);
409+ }
410+ });
411+ if (replacedNames.isNotEmpty) {
412+ for (String name in replacedNames) {
413+ // We start be collecting the relation between an existing getter/setter
414+ // and the getter/setter that will replace it. This information is used
415+ // below to handle all the different cases that can occur.
416+ LookupResult existingResult = _content! [name]! ;
417+ NamedBuilder ? existingGetter = existingResult.getable;
418+ NamedBuilder ? existingSetter = existingResult.setable;
419+ LookupResult ? replacementResult;
420+ if (existingGetter != null && existingSetter != null ) {
421+ if (existingGetter == existingSetter) {
422+ replacementResult = replacementNameSpaceMap[existingGetter.parent]!
423+ .lookupLocalMember (name);
424+ } else {
425+ NamedBuilder ? replacementGetter =
426+ replacementNameSpaceMap[existingGetter.parent]
477427 ? .lookupLocalMember (name)
478- ? .getable,
479- null );
480- } else if (existingSetter != null ) {
481- replacementResult = LookupResult .createResult (
482- null ,
483- replacementLookupMap[existingSetter.parent]
428+ ? .getable;
429+ NamedBuilder ? replacementSetter =
430+ replacementNameSpaceMap[existingSetter.parent]
484431 ? .lookupLocalMember (name)
485- ? .setable);
486- }
487- if (replacementResult != null ) {
488- (_content ?? = // Coverage-ignore(suite): Not run.
489- {})[name] = replacementResult;
490- } else {
491- // Coverage-ignore-block(suite): Not run.
492- _content? .remove (name);
432+ ? .setable;
433+ replacementResult = LookupResult .createResult (
434+ replacementGetter ?? existingGetter,
435+ replacementSetter ?? existingSetter);
493436 }
437+ } else if (existingGetter != null ) {
438+ replacementResult = LookupResult .createResult (
439+ replacementNameSpaceMap[existingGetter.parent]
440+ ? .lookupLocalMember (name)
441+ ? .getable,
442+ null );
443+ } else if (existingSetter != null ) {
444+ replacementResult = LookupResult .createResult (
445+ null ,
446+ replacementNameSpaceMap[existingSetter.parent]
447+ ? .lookupLocalMember (name)
448+ ? .setable);
449+ }
450+ if (replacementResult != null ) {
451+ (_content ?? = // Coverage-ignore(suite): Not run.
452+ {})[name] = replacementResult;
453+ } else {
454+ // Coverage-ignore-block(suite): Not run.
455+ _content? .remove (name);
494456 }
495457 }
496458 }
459+
497460 if (_extensions != null ) {
498461 // Coverage-ignore-block(suite): Not run.
499462 bool needsPatching = false ;
500463 for (ExtensionBuilder extensionBuilder in _extensions! ) {
501- if (replacementMap.containsKey (extensionBuilder.libraryBuilder)) {
464+ if (replacementNameSpaceMap
465+ .containsKey (extensionBuilder.libraryBuilder)) {
502466 needsPatching = true ;
503467 break ;
504468 }
@@ -507,12 +471,16 @@ final class DillExportNameSpace extends LazyNameSpace {
507471 Set <ExtensionBuilder > extensionsReplacement =
508472 new Set <ExtensionBuilder >();
509473 for (ExtensionBuilder extensionBuilder in _extensions! ) {
510- if (replacementMap.containsKey (extensionBuilder.libraryBuilder)) {
511- assert (replacementMap[extensionBuilder.libraryBuilder]! [
512- extensionBuilder.name] !=
474+ if (replacementNameSpaceMap
475+ .containsKey (extensionBuilder.libraryBuilder)) {
476+ assert (replacementNameSpaceMap[extensionBuilder.libraryBuilder]!
477+ .lookupLocalMember (extensionBuilder.name)!
478+ .getable !=
513479 null );
514- extensionsReplacement.add (replacementMap[extensionBuilder
515- .libraryBuilder]! [extensionBuilder.name] as ExtensionBuilder );
480+ extensionsReplacement.add (
481+ replacementNameSpaceMap[extensionBuilder.libraryBuilder]!
482+ .lookupLocalMember (extensionBuilder.name)!
483+ .getable as ExtensionBuilder );
516484 break ;
517485 } else {
518486 extensionsReplacement.add (extensionBuilder);
0 commit comments