Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5bf47cb

Browse files
author
Dart CI
committed
Version 2.18.0-159.0.dev
Merge commit 'e1e5cf45810fff6fa43824c713c85001a1b71bdb' into 'dev'
2 parents afc908f + e1e5cf4 commit 5bf47cb

File tree

16 files changed

+964
-68
lines changed

16 files changed

+964
-68
lines changed

pkg/analyzer/lib/src/dart/analysis/driver.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ import 'package:meta/meta.dart';
8686
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
8787
class AnalysisDriver implements AnalysisDriverGeneric {
8888
/// The version of data format, should be incremented on every format change.
89-
static const int DATA_VERSION = 221;
89+
static const int DATA_VERSION = 222;
9090

9191
/// The number of exception contexts allowed to write. Once this field is
9292
/// zero, we stop writing any new exception contexts in this process.

pkg/analyzer/lib/src/dart/analysis/file_state.dart

+199
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,75 @@ class AugmentationUnknownFileStateKind extends AugmentationFileStateKind {
8585
});
8686
}
8787

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+
88157
/// A library from [SummaryDataStore].
89158
class ExternalLibrary {
90159
final InSummarySource source;
@@ -587,6 +656,7 @@ class FileState {
587656
return unit;
588657
}
589658

659+
/// TODO(scheglov) move to _fsState?
590660
String _selectRelativeUri(UnlinkedNamespaceDirective directive) {
591661
for (var configuration in directive.configurations) {
592662
var name = configuration.name;
@@ -805,6 +875,7 @@ class FileState {
805875
imports.add(
806876
UnlinkedNamespaceDirective(
807877
configurations: [],
878+
isSyntheticDartCoreImport: true,
808879
uri: 'dart:core',
809880
),
810881
);
@@ -1193,6 +1264,77 @@ class FileUriProperties {
11931264
bool get isSrc => (_flags & _isSrc) != 0;
11941265
}
11951266

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+
11961338
class LibraryFileStateKind extends LibraryOrAugmentationFileKind {
11971339
/// The name of the library from the `library` directive.
11981340
/// Or `null` if no `library` directive.
@@ -1209,10 +1351,67 @@ class LibraryFileStateKind extends LibraryOrAugmentationFileKind {
12091351
}
12101352

12111353
abstract class LibraryOrAugmentationFileKind extends FileStateKind {
1354+
List<ExportDirectiveState>? _exports;
1355+
List<ImportDirectiveState>? _imports;
1356+
12121357
LibraryOrAugmentationFileKind({
12131358
required super.file,
12141359
});
12151360

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+
12161415
bool hasAugmentation(AugmentationFileStateKind augmentation) {
12171416
return file.augmentationFiles.contains(augmentation.file);
12181417
}

pkg/analyzer/lib/src/dart/analysis/unlinked_data.dart

+5
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,15 @@ class UnlinkedNamespaceDirective {
159159
/// The configurations that control which library will actually be used.
160160
final List<UnlinkedNamespaceDirectiveConfiguration> configurations;
161161

162+
final bool isSyntheticDartCoreImport;
163+
162164
/// The URI referenced by this directive, nad used by default when none
163165
/// of the [configurations] matches.
164166
final String uri;
165167

166168
UnlinkedNamespaceDirective({
167169
required this.configurations,
170+
this.isSyntheticDartCoreImport = false,
168171
required this.uri,
169172
});
170173

@@ -174,6 +177,7 @@ class UnlinkedNamespaceDirective {
174177
() => UnlinkedNamespaceDirectiveConfiguration.read(reader),
175178
),
176179
uri: reader.readStringUtf8(),
180+
isSyntheticDartCoreImport: reader.readBool(),
177181
);
178182
}
179183

@@ -185,6 +189,7 @@ class UnlinkedNamespaceDirective {
185189
},
186190
);
187191
sink.writeStringUtf8(uri);
192+
sink.writeBool(isSyntheticDartCoreImport);
188193
}
189194
}
190195

pkg/analyzer/lib/src/dart/micro/library_graph.dart

+1
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ class _FileStateUnlinked {
975975
imports.add(
976976
UnlinkedNamespaceDirective(
977977
configurations: [],
978+
isSyntheticDartCoreImport: true,
978979
uri: 'dart:core',
979980
),
980981
);

pkg/analyzer/lib/src/summary/package_bundle_reader.dart

+16-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ class InSummarySource extends BasicSource {
6565
/// The summary file where this source was defined.
6666
final String summaryPath;
6767

68-
InSummarySource(super.uri, this.summaryPath);
68+
final InSummarySourceKind kind;
69+
70+
InSummarySource({
71+
required Uri uri,
72+
required this.summaryPath,
73+
required this.kind,
74+
}) : super(uri);
6975

7076
@override
7177
TimestampedData<String> get contents => TimestampedData<String>(0, '');
@@ -77,6 +83,8 @@ class InSummarySource extends BasicSource {
7783
String toString() => uri.toString();
7884
}
7985

86+
enum InSummarySourceKind { library, part }
87+
8088
/// The [UriResolver] that knows about sources that are served from their
8189
/// summaries.
8290
class InSummaryUriResolver extends UriResolver {
@@ -92,7 +100,13 @@ class InSummaryUriResolver extends UriResolver {
92100
String uriString = uri.toString();
93101
String? summaryPath = _dataStore.uriToSummaryPath[uriString];
94102
if (summaryPath != null) {
95-
return InSummarySource(uri, summaryPath);
103+
final isLibrary = _dataStore._libraryUris.contains(uriString);
104+
return InSummarySource(
105+
uri: uri,
106+
summaryPath: summaryPath,
107+
kind:
108+
isLibrary ? InSummarySourceKind.library : InSummarySourceKind.part,
109+
);
96110
}
97111
return null;
98112
}

pkg/analyzer/lib/src/workspace/simple.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ abstract class SimpleWorkspace extends Workspace {
4343
DartSdk? sdk,
4444
SummaryDataStore? summaryData,
4545
) {
46+
List<UriResolver> resolvers = <UriResolver>[];
4647
if (summaryData != null) {
47-
throw UnsupportedError(
48-
'Summary files are not supported in a Pub workspace.');
48+
resolvers.add(InSummaryUriResolver(summaryData));
4949
}
50-
List<UriResolver> resolvers = <UriResolver>[];
5150
if (sdk != null) {
5251
resolvers.add(DartUriResolver(sdk));
5352
}

0 commit comments

Comments
 (0)