Skip to content

Commit 149ebf6

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Support for 'uri' property of Import/Export/CompilationUnitElement.
_Builder in source_gen uses code like this to check that the generated file is expected in the library. While it is a questionable approach, I don't feel that I have time to fix it, and remove the `uri` property completely. So, we fix in in Analyzer with summary2. `if (!library.parts.map((c) => c.uri).contains(part)) { ...fail... }` R=brianwilkerson@google.com, paulberry@google.com Change-Id: I983f29589cbb2613d5f896b87f6218c31a47afa9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105601 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent 8aa4414 commit 149ebf6

File tree

13 files changed

+225
-120
lines changed

13 files changed

+225
-120
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,24 @@ class LibraryContext {
283283
if (librarySource == null) continue;
284284

285285
var inputUnits = <link2.LinkInputUnit>[];
286+
var partIndex = -1;
286287
for (var file in libraryFile.libraryFiles) {
287288
var isSynthetic = !file.exists;
288289
var unit = file.parse();
290+
291+
String partUriStr;
292+
if (partIndex >= 0) {
293+
partUriStr = libraryFile.unlinked2.parts[partIndex];
294+
}
295+
partIndex++;
296+
289297
inputUnits.add(
290-
link2.LinkInputUnit(file.source, isSynthetic, unit),
298+
link2.LinkInputUnit(
299+
partUriStr,
300+
file.source,
301+
isSynthetic,
302+
unit,
303+
),
291304
);
292305
}
293306

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4851,6 +4851,11 @@ class ExportElementImpl extends UriReferencedElementImpl
48514851

48524852
@override
48534853
String get uri {
4854+
if (linkedNode != null) {
4855+
ExportDirective node = linkedNode;
4856+
return node.uri.stringValue;
4857+
}
4858+
48544859
if (_unlinkedExportPublic != null) {
48554860
return _selectedUri ??= _selectUri(
48564861
_unlinkedExportPublic.uri, _unlinkedExportPublic.configurations);
@@ -6123,6 +6128,11 @@ class ImportElementImpl extends UriReferencedElementImpl
61236128

61246129
@override
61256130
String get uri {
6131+
if (linkedNode != null) {
6132+
ImportDirective node = linkedNode;
6133+
return node.uri.stringValue;
6134+
}
6135+
61266136
if (_unlinkedImport != null) {
61276137
if (_unlinkedImport.isImplicit) {
61286138
return null;

0 commit comments

Comments
 (0)