@@ -26,12 +26,44 @@ Uint8List writeUnitInformative(CompilationUnit unit) {
2626}
2727
2828class InformativeDataApplier {
29- final LinkedElementFactory _elementFactory;
30- final Map <Uri , Uint8List > _unitsInformativeBytes2;
29+ void applyFromNode (LibraryFragmentImpl fragment, CompilationUnit node) {
30+ var unitInfo = _InfoBuilder ().build (node);
31+ _applyFromInfo (fragment, unitInfo);
3132
32- InformativeDataApplier (this ._elementFactory, this ._unitsInformativeBytes2);
33+ // TODO(scheglov): generalize
34+ for (var classFragment in fragment.classes) {
35+ classFragment.applyMembersConstantOffsets? .call ();
36+ classFragment.applyMembersConstantOffsets = null ;
37+ }
38+ }
39+
40+ void applyToLibrary (
41+ LinkedElementFactory elementFactory,
42+ LibraryElementImpl libraryElement,
43+ Map <Uri , Uint8List > unitsInformativeBytes,
44+ ) {
45+ if (elementFactory.isApplyingInformativeData) {
46+ throw StateError ('Unexpected recursion.' );
47+ }
48+ elementFactory.isApplyingInformativeData = true ;
3349
34- void applyFromInfoUnit (LibraryFragmentImpl unitElement, _InfoUnit unitInfo) {
50+ for (var unitElement in libraryElement.units) {
51+ var uri = unitElement.source.uri;
52+ if (unitsInformativeBytes[uri] case var infoBytes? ) {
53+ _applyFromBytes (unitElement, infoBytes);
54+ }
55+ }
56+
57+ elementFactory.isApplyingInformativeData = false ;
58+ }
59+
60+ void _applyFromBytes (LibraryFragmentImpl unitElement, Uint8List infoBytes) {
61+ var unitReader = SummaryDataReader (infoBytes);
62+ var unitInfo = _InfoUnit .read (unitReader);
63+ _applyFromInfo (unitElement, unitInfo);
64+ }
65+
66+ void _applyFromInfo (LibraryFragmentImpl unitElement, _InfoUnit unitInfo) {
3567 var libraryElement = unitElement.library;
3668 if (identical (libraryElement.definingCompilationUnit, unitElement)) {
3769 _applyToLibrary (libraryElement, unitInfo);
@@ -131,43 +163,6 @@ class InformativeDataApplier {
131163 );
132164 }
133165
134- void applyFromUnit (LibraryFragmentImpl unitElement, CompilationUnit unit) {
135- var unitInfo = _InfoBuilder ().build (unit);
136- applyFromInfoUnit (unitElement, unitInfo);
137-
138- // TODO(scheglov): generalize
139- for (var classFragment in unitElement.classes) {
140- classFragment.applyMembersConstantOffsets? .call ();
141- classFragment.applyMembersConstantOffsets = null ;
142- }
143- }
144-
145- void applyTo (LibraryElementImpl libraryElement) {
146- if (_elementFactory.isApplyingInformativeData) {
147- throw StateError ('Unexpected recursion.' );
148- }
149- _elementFactory.isApplyingInformativeData = true ;
150-
151- var unitElements = libraryElement.units;
152- for (var i = 0 ; i < unitElements.length; i++ ) {
153- var unitElement = unitElements[i];
154- var unitInfoBytes = _getInfoUnitBytes (unitElement);
155- if (unitInfoBytes != null ) {
156- applyToUnit (unitElement, unitInfoBytes);
157- } else {
158- unitElement.lineInfo = LineInfo ([0 ]);
159- }
160- }
161-
162- _elementFactory.isApplyingInformativeData = false ;
163- }
164-
165- void applyToUnit (LibraryFragmentImpl unitElement, Uint8List unitInfoBytes) {
166- var unitReader = SummaryDataReader (unitInfoBytes);
167- var unitInfo = _InfoUnit .read (unitReader);
168- applyFromInfoUnit (unitElement, unitInfo);
169- }
170-
171166 void _applyToAccessors (
172167 List <PropertyAccessorFragmentImpl > elementList,
173168 List <_InfoExecutableDeclaration > infoList,
@@ -617,11 +612,6 @@ class InformativeDataApplier {
617612 }
618613 }
619614
620- Uint8List ? _getInfoUnitBytes (LibraryFragmentImpl element) {
621- var uri = element.source.uri;
622- return _unitsInformativeBytes2[uri];
623- }
624-
625615 void _setupApplyConstantOffsetsForTypeAlias (
626616 TypeAliasFragmentImpl element,
627617 Uint32List constantOffsets, {
0 commit comments