@@ -80,12 +80,15 @@ class LibraryManifestBuilder {
80
80
final Map <Uri , LibraryManifest > inputManifests;
81
81
82
82
/// Key: an element from [inputLibraries] .
83
- /// Value: the item from [inputManifests] .
83
+ /// Value: the item from [inputManifests] , or newly build .
84
84
///
85
- /// We attempt to reuse the same item, mostly importantly its ID.
85
+ /// We attempt to reuse the same item, most importantly its ID.
86
86
///
87
87
/// It is filled initially during matching element structures.
88
88
/// Then we remove those that affected by changed elements.
89
+ ///
90
+ /// Then we iterate over the elements in [libraryElements] , and build new
91
+ /// items for declared elements that don't have items in this map.
89
92
final Map <Element2 , ManifestItem > declaredItems = Map .identity ();
90
93
91
94
/// The new manifests for libraries.
@@ -123,16 +126,15 @@ class LibraryManifestBuilder {
123
126
required ClassElementImpl2 element,
124
127
required LookupName lookupName,
125
128
}) {
126
- var item = _getOrBuildElementItem (element, () {
129
+ var classItem = _getOrBuildElementItem (element, () {
127
130
return ClassItem .fromElement (
128
131
id: ManifestItemId .generate (),
129
132
context: encodingContext,
130
133
element: element,
131
134
);
132
135
});
133
- newItems[lookupName] = item ;
136
+ newItems[lookupName] = classItem ;
134
137
135
- var classItem = item;
136
138
encodingContext.withTypeParameters (
137
139
element.typeParameters2,
138
140
(typeParameters) {
@@ -645,7 +647,7 @@ class LibraryManifestBuilder {
645
647
var item = declaredItems[element] as Item ? ;
646
648
if (item == null ) {
647
649
item = build ();
648
- // To reuse items for inherited members.
650
+ // To find IDs of inherited members.
649
651
declaredItems[element] = item;
650
652
}
651
653
return item;
@@ -721,6 +723,19 @@ class _LibraryMatch {
721
723
}
722
724
}
723
725
726
+ /// Records [item] as matching [element] , and stores dependencies.
727
+ ///
728
+ /// The fact that it does match is checked outside.
729
+ void _addMatchingElementItem (
730
+ ElementImpl2 element,
731
+ ManifestItem item,
732
+ MatchContext matchContext,
733
+ ) {
734
+ itemMap[element] = item;
735
+ refElementsMap[element] = matchContext.elementList;
736
+ refExternalIds.addAll (matchContext.externalIds);
737
+ }
738
+
724
739
bool _matchClass ({
725
740
required LookupName ? name,
726
741
required ClassElementImpl2 element,
@@ -735,15 +750,14 @@ class _LibraryMatch {
735
750
return false ;
736
751
}
737
752
738
- itemMap[element] = item;
739
- refElementsMap[element] = matchContext.elementList;
740
- refExternalIds.addAll (matchContext.externalIds);
753
+ _addMatchingElementItem (element, item, matchContext);
741
754
742
755
_matchInterfaceConstructors (
743
756
matchContext: matchContext,
744
757
interfaceElement: element,
745
758
item: item,
746
759
);
760
+
747
761
_matchStaticExecutables (
748
762
matchContext: matchContext,
749
763
element: element,
@@ -778,9 +792,7 @@ class _LibraryMatch {
778
792
return false ;
779
793
}
780
794
781
- itemMap[executable] = item;
782
- refElementsMap[executable] = matchContext.elementList;
783
- refExternalIds.addAll (matchContext.externalIds);
795
+ _addMatchingElementItem (executable, item, matchContext);
784
796
return true ;
785
797
case MethodElementImpl2 ():
786
798
if (item is ! InstanceItemMethodItem ) {
@@ -792,9 +804,7 @@ class _LibraryMatch {
792
804
return false ;
793
805
}
794
806
795
- itemMap[executable] = item;
796
- refElementsMap[executable] = matchContext.elementList;
797
- refExternalIds.addAll (matchContext.externalIds);
807
+ _addMatchingElementItem (executable, item, matchContext);
798
808
return true ;
799
809
case SetterElementImpl ():
800
810
if (item is ! InstanceItemSetterItem ) {
@@ -806,9 +816,7 @@ class _LibraryMatch {
806
816
return false ;
807
817
}
808
818
809
- itemMap[executable] = item;
810
- refElementsMap[executable] = matchContext.elementList;
811
- refExternalIds.addAll (matchContext.externalIds);
819
+ _addMatchingElementItem (executable, item, matchContext);
812
820
return true ;
813
821
default :
814
822
// SAFETY: the cases above handle all expected executables.
@@ -860,9 +868,7 @@ class _LibraryMatch {
860
868
return false ;
861
869
}
862
870
863
- itemMap[element] = item;
864
- refElementsMap[element] = matchContext.elementList;
865
- refExternalIds.addAll (matchContext.externalIds);
871
+ _addMatchingElementItem (element, item, matchContext);
866
872
return true ;
867
873
}
868
874
@@ -952,10 +958,7 @@ class _LibraryMatch {
952
958
return false ;
953
959
}
954
960
955
- // TODO(scheglov): it looks that this code is repeating
956
- itemMap[element] = item;
957
- refElementsMap[element] = matchContext.elementList;
958
- refExternalIds.addAll (matchContext.externalIds);
961
+ _addMatchingElementItem (element, item, matchContext);
959
962
return true ;
960
963
}
961
964
@@ -973,9 +976,7 @@ class _LibraryMatch {
973
976
return false ;
974
977
}
975
978
976
- itemMap[element] = item;
977
- refElementsMap[element] = matchContext.elementList;
978
- refExternalIds.addAll (matchContext.externalIds);
979
+ _addMatchingElementItem (element, item, matchContext);
979
980
return true ;
980
981
}
981
982
@@ -993,9 +994,7 @@ class _LibraryMatch {
993
994
return false ;
994
995
}
995
996
996
- itemMap[element] = item;
997
- refElementsMap[element] = matchContext.elementList;
998
- refExternalIds.addAll (matchContext.externalIds);
997
+ _addMatchingElementItem (element, item, matchContext);
999
998
return true ;
1000
999
}
1001
1000
}
0 commit comments