@@ -15,6 +15,7 @@ import 'package:analyzer/src/fine/manifest_id.dart';
15
15
import 'package:analyzer/src/fine/manifest_item.dart' ;
16
16
import 'package:analyzer/src/fine/requirement_failure.dart' ;
17
17
import 'package:analyzer/src/summary2/linked_element_factory.dart' ;
18
+ import 'package:analyzer/src/utilities/extensions/string.dart' ;
18
19
import 'package:collection/collection.dart' ;
19
20
import 'package:meta/meta.dart' ;
20
21
@@ -368,6 +369,84 @@ class LibraryExportRequirements {
368
369
declaredTopNames.write (sink);
369
370
sink.writeList (exports, (export) => export.write (sink));
370
371
}
372
+
373
+ static LibraryExportRequirements ? build (LibraryElementImpl libraryElement) {
374
+ var declaredTopNames = libraryElement.children
375
+ .map ((element) => element.lookupName)
376
+ .nonNulls
377
+ .map ((nameStr) => nameStr.asLookupName)
378
+ .toSet ();
379
+
380
+ var fragments = < ExportRequirement > [];
381
+
382
+ for (var fragment in libraryElement.fragments) {
383
+ for (var export in fragment.libraryExports) {
384
+ var exportedLibrary = export.exportedLibrary;
385
+
386
+ // If no library, then there is nothing to re-export.
387
+ if (exportedLibrary == null ) {
388
+ continue ;
389
+ }
390
+
391
+ var combinators = export.combinators.map ((combinator) {
392
+ switch (combinator) {
393
+ case HideElementCombinator ():
394
+ return ExportRequirementHideCombinator (
395
+ hiddenBaseNames: combinator.hiddenNames.toBaseNameSet (),
396
+ );
397
+ case ShowElementCombinator ():
398
+ return ExportRequirementShowCombinator (
399
+ shownBaseNames: combinator.shownNames.toBaseNameSet (),
400
+ );
401
+ }
402
+ }).toList ();
403
+
404
+ // SAFETY: every library has the manifest.
405
+ var manifest = exportedLibrary.manifest! ;
406
+
407
+ var exportMap = globalResultRequirements.untracked (
408
+ reason: 'Recoding requirements' ,
409
+ operation: () {
410
+ return NamespaceBuilder ()
411
+ .createExportNamespaceForDirective2 (export)
412
+ .definedNames2;
413
+ },
414
+ );
415
+
416
+ var exportedIds = < LookupName , ManifestItemId > {};
417
+ for (var entry in exportMap.entries) {
418
+ var lookupName = entry.key.asLookupName;
419
+ if (declaredTopNames.contains (lookupName)) {
420
+ continue ;
421
+ }
422
+ // TODO(scheglov): must always be not null.
423
+ var id = manifest.getExportedId (lookupName);
424
+ if (id != null ) {
425
+ exportedIds[lookupName] = id;
426
+ }
427
+ }
428
+
429
+ fragments.add (
430
+ ExportRequirement (
431
+ fragmentUri: fragment.source.uri,
432
+ exportedUri: exportedLibrary.uri,
433
+ combinators: combinators,
434
+ exportedIds: exportedIds,
435
+ ),
436
+ );
437
+ }
438
+ }
439
+
440
+ if (fragments.isNotEmpty) {
441
+ return LibraryExportRequirements (
442
+ libraryUri: libraryElement.uri,
443
+ declaredTopNames: declaredTopNames,
444
+ exports: fragments,
445
+ );
446
+ } else {
447
+ return null ;
448
+ }
449
+ }
371
450
}
372
451
373
452
class LibraryRequirements {
@@ -670,8 +749,11 @@ class RequirementsManifest {
670
749
required Set <Uri > libraryUriSet,
671
750
}) {
672
751
for (var libraryUri in libraryUriSet) {
673
- var libraryElement = elementFactory.libraryOfUri2 (libraryUri);
674
- _addExports (libraryElement);
752
+ var element = elementFactory.libraryOfUri2 (libraryUri);
753
+ var exports = LibraryExportRequirements .build (element);
754
+ if (exports != null ) {
755
+ exportRequirements.add (exports);
756
+ }
675
757
}
676
758
}
677
759
@@ -1408,6 +1490,11 @@ class RequirementsManifest {
1408
1490
required String id,
1409
1491
}) {
1410
1492
assert (! id.endsWith ('=' ));
1493
+
1494
+ if (_recordingLockLevel != 0 ) {
1495
+ return ;
1496
+ }
1497
+
1411
1498
var getterLookupName = id.asLookupName;
1412
1499
var setterLookupName = '$id =' .asLookupName;
1413
1500
@@ -1720,6 +1807,22 @@ class RequirementsManifest {
1720
1807
);
1721
1808
}
1722
1809
1810
+ void record_library_allExportedTopLevels ({
1811
+ required LibraryElementImpl element,
1812
+ }) {
1813
+ if (_recordingLockLevel != 0 ) {
1814
+ return ;
1815
+ }
1816
+
1817
+ var manifest = element.manifest;
1818
+ if (manifest == null ) {
1819
+ return ;
1820
+ }
1821
+
1822
+ var requirements = _getLibraryRequirements (element);
1823
+ requirements.exportedTopLevels.addAll (manifest.exportedIds);
1824
+ }
1825
+
1723
1826
void record_library_allExtensions ({required LibraryElementImpl element}) {
1724
1827
if (_recordingLockLevel != 0 ) {
1725
1828
return ;
@@ -1882,6 +1985,16 @@ class RequirementsManifest {
1882
1985
requirements.exportedLibraryUris = manifest.exportedLibraryUris;
1883
1986
}
1884
1987
1988
+ void record_library_exportScope_get ({
1989
+ required LibraryElementImpl element,
1990
+ required String name,
1991
+ }) {
1992
+ record_importPrefixScope_lookup (
1993
+ importedLibraries: [element],
1994
+ id: name.removeSuffix ('=' ) ?? name,
1995
+ );
1996
+ }
1997
+
1885
1998
void record_library_featureSet ({required LibraryElementImpl element}) {
1886
1999
if (_recordingLockLevel != 0 ) {
1887
2000
return ;
@@ -2207,78 +2320,6 @@ class RequirementsManifest {
2207
2320
sink.writeList (opaqueApiUses, (usage) => usage.write (sink));
2208
2321
}
2209
2322
2210
- void _addExports (LibraryElementImpl libraryElement) {
2211
- var declaredTopNames = libraryElement.children
2212
- .map ((element) => element.lookupName)
2213
- .nonNulls
2214
- .map ((nameStr) => nameStr.asLookupName)
2215
- .toSet ();
2216
-
2217
- var fragments = < ExportRequirement > [];
2218
-
2219
- for (var fragment in libraryElement.fragments) {
2220
- for (var export in fragment.libraryExports) {
2221
- var exportedLibrary = export.exportedLibrary;
2222
-
2223
- // If no library, then there is nothing to re-export.
2224
- if (exportedLibrary == null ) {
2225
- continue ;
2226
- }
2227
-
2228
- var combinators = export.combinators.map ((combinator) {
2229
- switch (combinator) {
2230
- case HideElementCombinator ():
2231
- return ExportRequirementHideCombinator (
2232
- hiddenBaseNames: combinator.hiddenNames.toBaseNameSet (),
2233
- );
2234
- case ShowElementCombinator ():
2235
- return ExportRequirementShowCombinator (
2236
- shownBaseNames: combinator.shownNames.toBaseNameSet (),
2237
- );
2238
- }
2239
- }).toList ();
2240
-
2241
- // SAFETY: every library has the manifest.
2242
- var manifest = exportedLibrary.manifest! ;
2243
-
2244
- var exportedIds = < LookupName , ManifestItemId > {};
2245
- var exportMap = NamespaceBuilder ().createExportNamespaceForDirective2 (
2246
- export,
2247
- );
2248
- for (var entry in exportMap.definedNames2.entries) {
2249
- var lookupName = entry.key.asLookupName;
2250
- if (declaredTopNames.contains (lookupName)) {
2251
- continue ;
2252
- }
2253
- // TODO(scheglov): must always be not null.
2254
- var id = manifest.getExportedId (lookupName);
2255
- if (id != null ) {
2256
- exportedIds[lookupName] = id;
2257
- }
2258
- }
2259
-
2260
- fragments.add (
2261
- ExportRequirement (
2262
- fragmentUri: fragment.source.uri,
2263
- exportedUri: exportedLibrary.uri,
2264
- combinators: combinators,
2265
- exportedIds: exportedIds,
2266
- ),
2267
- );
2268
- }
2269
- }
2270
-
2271
- if (fragments.isNotEmpty) {
2272
- exportRequirements.add (
2273
- LibraryExportRequirements (
2274
- libraryUri: libraryElement.uri,
2275
- declaredTopNames: declaredTopNames,
2276
- exports: fragments,
2277
- ),
2278
- );
2279
- }
2280
- }
2281
-
2282
2323
_InstanceItemWithRequirements ? _getInstanceItem (InstanceElementImpl element) {
2283
2324
var libraryElement = element.library;
2284
2325
var manifest = libraryElement.manifest;
0 commit comments