@@ -85,6 +85,75 @@ class AugmentationUnknownFileStateKind extends AugmentationFileStateKind {
85
85
});
86
86
}
87
87
88
+ /// Information about a single `import` directive.
89
+ class ExportDirectiveState {
90
+ final UnlinkedNamespaceDirective directive;
91
+
92
+ ExportDirectiveState ({
93
+ required this .directive,
94
+ });
95
+
96
+ /// If [exportedSource] corresponds to a library, returns it.
97
+ Source ? get exportedLibrarySource => null ;
98
+
99
+ /// Returns a [Source] that is referenced by this directive. If the are
100
+ /// configurations, selects the one which satisfies the conditions.
101
+ ///
102
+ /// Returns `null` if the selected URI is not valid, or cannot be resolved
103
+ /// into a [Source] .
104
+ Source ? get exportedSource => null ;
105
+ }
106
+
107
+ /// [ExportDirectiveState] that has a valid URI that references a file.
108
+ class ExportDirectiveWithFile extends ExportDirectiveState {
109
+ final FileState exportedFile;
110
+
111
+ ExportDirectiveWithFile ({
112
+ required super .directive,
113
+ required this .exportedFile,
114
+ });
115
+
116
+ /// Returns [exportedFile] if it is a library.
117
+ LibraryFileStateKind ? get exportedLibrary {
118
+ final kind = exportedFile.kind;
119
+ if (kind is LibraryFileStateKind ) {
120
+ return kind;
121
+ }
122
+ return null ;
123
+ }
124
+
125
+ @override
126
+ Source ? get exportedLibrarySource {
127
+ if (exportedFile.kind is LibraryFileStateKind ) {
128
+ return exportedSource;
129
+ }
130
+ return null ;
131
+ }
132
+
133
+ @override
134
+ Source get exportedSource => exportedFile.source;
135
+ }
136
+
137
+ /// [ExportDirectiveState] with a URI that resolves to [InSummarySource] .
138
+ class ExportDirectiveWithInSummarySource extends ExportDirectiveState {
139
+ @override
140
+ final InSummarySource exportedSource;
141
+
142
+ ExportDirectiveWithInSummarySource ({
143
+ required super .directive,
144
+ required this .exportedSource,
145
+ });
146
+
147
+ @override
148
+ Source ? get exportedLibrarySource {
149
+ if (exportedSource.kind == InSummarySourceKind .library) {
150
+ return exportedSource;
151
+ } else {
152
+ return null ;
153
+ }
154
+ }
155
+ }
156
+
88
157
/// A library from [SummaryDataStore] .
89
158
class ExternalLibrary {
90
159
final InSummarySource source;
@@ -587,6 +656,7 @@ class FileState {
587
656
return unit;
588
657
}
589
658
659
+ /// TODO(scheglov) move to _fsState?
590
660
String _selectRelativeUri (UnlinkedNamespaceDirective directive) {
591
661
for (var configuration in directive.configurations) {
592
662
var name = configuration.name;
@@ -805,6 +875,7 @@ class FileState {
805
875
imports.add (
806
876
UnlinkedNamespaceDirective (
807
877
configurations: [],
878
+ isSyntheticDartCoreImport: true ,
808
879
uri: 'dart:core' ,
809
880
),
810
881
);
@@ -1193,6 +1264,77 @@ class FileUriProperties {
1193
1264
bool get isSrc => (_flags & _isSrc) != 0 ;
1194
1265
}
1195
1266
1267
+ /// Information about a single `import` directive.
1268
+ class ImportDirectiveState {
1269
+ final UnlinkedNamespaceDirective directive;
1270
+
1271
+ ImportDirectiveState ({
1272
+ required this .directive,
1273
+ });
1274
+
1275
+ /// If [importedSource] corresponds to a library, returns it.
1276
+ Source ? get importedLibrarySource => null ;
1277
+
1278
+ /// Returns a [Source] that is referenced by this directive. If the are
1279
+ /// configurations, selects the one which satisfies the conditions.
1280
+ ///
1281
+ /// Returns `null` if the selected URI is not valid, or cannot be resolved
1282
+ /// into a [Source] .
1283
+ Source ? get importedSource => null ;
1284
+
1285
+ bool get isSyntheticDartCoreImport => directive.isSyntheticDartCoreImport;
1286
+ }
1287
+
1288
+ /// [ImportDirectiveState] that has a valid URI that references a file.
1289
+ class ImportDirectiveWithFile extends ImportDirectiveState {
1290
+ final FileState importedFile;
1291
+
1292
+ ImportDirectiveWithFile ({
1293
+ required super .directive,
1294
+ required this .importedFile,
1295
+ });
1296
+
1297
+ /// Returns [importedFile] if it is a library.
1298
+ LibraryFileStateKind ? get importedLibrary {
1299
+ final kind = importedFile.kind;
1300
+ if (kind is LibraryFileStateKind ) {
1301
+ return kind;
1302
+ }
1303
+ return null ;
1304
+ }
1305
+
1306
+ @override
1307
+ Source ? get importedLibrarySource {
1308
+ if (importedFile.kind is LibraryFileStateKind ) {
1309
+ return importedSource;
1310
+ }
1311
+ return null ;
1312
+ }
1313
+
1314
+ @override
1315
+ Source get importedSource => importedFile.source;
1316
+ }
1317
+
1318
+ /// [ImportDirectiveState] with a URI that resolves to [InSummarySource] .
1319
+ class ImportDirectiveWithInSummarySource extends ImportDirectiveState {
1320
+ @override
1321
+ final InSummarySource importedSource;
1322
+
1323
+ ImportDirectiveWithInSummarySource ({
1324
+ required super .directive,
1325
+ required this .importedSource,
1326
+ });
1327
+
1328
+ @override
1329
+ Source ? get importedLibrarySource {
1330
+ if (importedSource.kind == InSummarySourceKind .library) {
1331
+ return importedSource;
1332
+ } else {
1333
+ return null ;
1334
+ }
1335
+ }
1336
+ }
1337
+
1196
1338
class LibraryFileStateKind extends LibraryOrAugmentationFileKind {
1197
1339
/// The name of the library from the `library` directive.
1198
1340
/// Or `null` if no `library` directive.
@@ -1209,10 +1351,67 @@ class LibraryFileStateKind extends LibraryOrAugmentationFileKind {
1209
1351
}
1210
1352
1211
1353
abstract class LibraryOrAugmentationFileKind extends FileStateKind {
1354
+ List <ExportDirectiveState >? _exports;
1355
+ List <ImportDirectiveState >? _imports;
1356
+
1212
1357
LibraryOrAugmentationFileKind ({
1213
1358
required super .file,
1214
1359
});
1215
1360
1361
+ List <ExportDirectiveState > get exports {
1362
+ return _exports ?? = file.unlinked2.exports.map ((directive) {
1363
+ final uriStr = file._selectRelativeUri (directive);
1364
+ return file._fileForRelativeUri (uriStr).map (
1365
+ (refFile) {
1366
+ if (refFile != null ) {
1367
+ refFile.referencingFiles.add (file);
1368
+ return ExportDirectiveWithFile (
1369
+ directive: directive,
1370
+ exportedFile: refFile,
1371
+ );
1372
+ } else {
1373
+ return ExportDirectiveState (
1374
+ directive: directive,
1375
+ );
1376
+ }
1377
+ },
1378
+ (externalLibrary) {
1379
+ return ExportDirectiveWithInSummarySource (
1380
+ directive: directive,
1381
+ exportedSource: externalLibrary.source,
1382
+ );
1383
+ },
1384
+ );
1385
+ }).toList ();
1386
+ }
1387
+
1388
+ List <ImportDirectiveState > get imports {
1389
+ return _imports ?? = file.unlinked2.imports.map ((directive) {
1390
+ final uriStr = file._selectRelativeUri (directive);
1391
+ return file._fileForRelativeUri (uriStr).map (
1392
+ (refFile) {
1393
+ if (refFile != null ) {
1394
+ refFile.referencingFiles.add (file);
1395
+ return ImportDirectiveWithFile (
1396
+ directive: directive,
1397
+ importedFile: refFile,
1398
+ );
1399
+ } else {
1400
+ return ImportDirectiveState (
1401
+ directive: directive,
1402
+ );
1403
+ }
1404
+ },
1405
+ (externalLibrary) {
1406
+ return ImportDirectiveWithInSummarySource (
1407
+ directive: directive,
1408
+ importedSource: externalLibrary.source,
1409
+ );
1410
+ },
1411
+ );
1412
+ }).toList ();
1413
+ }
1414
+
1216
1415
bool hasAugmentation (AugmentationFileStateKind augmentation) {
1217
1416
return file.augmentationFiles.contains (augmentation.file);
1218
1417
}
0 commit comments