Skip to content

Commit cb9fdee

Browse files
committed
Fine. Extract shared _addMatchingElementItem()
Change-Id: Icf467266a2b36788e2fa2fb152e500724c1b9e10 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421962 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 12a32f4 commit cb9fdee

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

pkg/analyzer/lib/src/fine/library_manifest.dart

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,15 @@ class LibraryManifestBuilder {
8080
final Map<Uri, LibraryManifest> inputManifests;
8181

8282
/// Key: an element from [inputLibraries].
83-
/// Value: the item from [inputManifests].
83+
/// Value: the item from [inputManifests], or newly build.
8484
///
85-
/// We attempt to reuse the same item, mostly importantly its ID.
85+
/// We attempt to reuse the same item, most importantly its ID.
8686
///
8787
/// It is filled initially during matching element structures.
8888
/// 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.
8992
final Map<Element2, ManifestItem> declaredItems = Map.identity();
9093

9194
/// The new manifests for libraries.
@@ -123,16 +126,15 @@ class LibraryManifestBuilder {
123126
required ClassElementImpl2 element,
124127
required LookupName lookupName,
125128
}) {
126-
var item = _getOrBuildElementItem(element, () {
129+
var classItem = _getOrBuildElementItem(element, () {
127130
return ClassItem.fromElement(
128131
id: ManifestItemId.generate(),
129132
context: encodingContext,
130133
element: element,
131134
);
132135
});
133-
newItems[lookupName] = item;
136+
newItems[lookupName] = classItem;
134137

135-
var classItem = item;
136138
encodingContext.withTypeParameters(
137139
element.typeParameters2,
138140
(typeParameters) {
@@ -645,7 +647,7 @@ class LibraryManifestBuilder {
645647
var item = declaredItems[element] as Item?;
646648
if (item == null) {
647649
item = build();
648-
// To reuse items for inherited members.
650+
// To find IDs of inherited members.
649651
declaredItems[element] = item;
650652
}
651653
return item;
@@ -721,6 +723,19 @@ class _LibraryMatch {
721723
}
722724
}
723725

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+
724739
bool _matchClass({
725740
required LookupName? name,
726741
required ClassElementImpl2 element,
@@ -735,15 +750,14 @@ class _LibraryMatch {
735750
return false;
736751
}
737752

738-
itemMap[element] = item;
739-
refElementsMap[element] = matchContext.elementList;
740-
refExternalIds.addAll(matchContext.externalIds);
753+
_addMatchingElementItem(element, item, matchContext);
741754

742755
_matchInterfaceConstructors(
743756
matchContext: matchContext,
744757
interfaceElement: element,
745758
item: item,
746759
);
760+
747761
_matchStaticExecutables(
748762
matchContext: matchContext,
749763
element: element,
@@ -778,9 +792,7 @@ class _LibraryMatch {
778792
return false;
779793
}
780794

781-
itemMap[executable] = item;
782-
refElementsMap[executable] = matchContext.elementList;
783-
refExternalIds.addAll(matchContext.externalIds);
795+
_addMatchingElementItem(executable, item, matchContext);
784796
return true;
785797
case MethodElementImpl2():
786798
if (item is! InstanceItemMethodItem) {
@@ -792,9 +804,7 @@ class _LibraryMatch {
792804
return false;
793805
}
794806

795-
itemMap[executable] = item;
796-
refElementsMap[executable] = matchContext.elementList;
797-
refExternalIds.addAll(matchContext.externalIds);
807+
_addMatchingElementItem(executable, item, matchContext);
798808
return true;
799809
case SetterElementImpl():
800810
if (item is! InstanceItemSetterItem) {
@@ -806,9 +816,7 @@ class _LibraryMatch {
806816
return false;
807817
}
808818

809-
itemMap[executable] = item;
810-
refElementsMap[executable] = matchContext.elementList;
811-
refExternalIds.addAll(matchContext.externalIds);
819+
_addMatchingElementItem(executable, item, matchContext);
812820
return true;
813821
default:
814822
// SAFETY: the cases above handle all expected executables.
@@ -860,9 +868,7 @@ class _LibraryMatch {
860868
return false;
861869
}
862870

863-
itemMap[element] = item;
864-
refElementsMap[element] = matchContext.elementList;
865-
refExternalIds.addAll(matchContext.externalIds);
871+
_addMatchingElementItem(element, item, matchContext);
866872
return true;
867873
}
868874

@@ -952,10 +958,7 @@ class _LibraryMatch {
952958
return false;
953959
}
954960

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);
959962
return true;
960963
}
961964

@@ -973,9 +976,7 @@ class _LibraryMatch {
973976
return false;
974977
}
975978

976-
itemMap[element] = item;
977-
refElementsMap[element] = matchContext.elementList;
978-
refExternalIds.addAll(matchContext.externalIds);
979+
_addMatchingElementItem(element, item, matchContext);
979980
return true;
980981
}
981982

@@ -993,9 +994,7 @@ class _LibraryMatch {
993994
return false;
994995
}
995996

996-
itemMap[element] = item;
997-
refElementsMap[element] = matchContext.elementList;
998-
refExternalIds.addAll(matchContext.externalIds);
997+
_addMatchingElementItem(element, item, matchContext);
999998
return true;
1000999
}
10011000
}

0 commit comments

Comments
 (0)