Skip to content

Commit

Permalink
Parts. Print 'enclosingElement'.
Browse files Browse the repository at this point in the history
Change-Id: I229cab105eba7d10fce7c4aa74dd53960ebd36a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377300
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed Jul 23, 2024
1 parent bdf3d17 commit 962f78b
Show file tree
Hide file tree
Showing 6 changed files with 11,673 additions and 54 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4752,7 +4752,7 @@ class LibraryElementImpl extends LibraryOrAugmentationElementImpl

static List<PrefixElementImpl> buildPrefixesFromImports(
List<LibraryImportElementImpl> imports) {
var prefixes = HashSet<PrefixElementImpl>();
var prefixes = <PrefixElementImpl>{};
for (var element in imports) {
var prefix = element.prefix?.element;
if (prefix != null) {
Expand Down
15 changes: 13 additions & 2 deletions pkg/analyzer/lib/src/summary2/library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1070,15 +1070,26 @@ class LibraryBuilder with MacroApplicationsContainer {
definingUnit.libraryExports = kind.libraryExports.map((state) {
return _buildExport(state);
}).toFixedList();
container.libraryExports = definingUnit.libraryExports;

// TODO(scheglov): Remove when only parts have exports.
container.libraryExports = kind.libraryExports.map((state) {
return _buildExport(state);
}).toFixedList();

definingUnit.libraryImports = kind.libraryImports.map((state) {
return _buildImport(
container: container,
state: state,
);
}).toFixedList();
container.libraryImports = definingUnit.libraryImports;

// TODO(scheglov): Remove when only parts have imports.
container.libraryImports = kind.libraryImports.map((state) {
return _buildImport(
container: container,
state: state,
);
}).toFixedList();

container.augmentationImports = kind.augmentationImports.map((state) {
return _buildAugmentationImport(
Expand Down
37 changes: 34 additions & 3 deletions pkg/analyzer/test/src/summary/element_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class _ElementWriter {
_elementPrinter = elementPrinter;

void writeLibraryElement(LibraryElementImpl e) {
expect(e.enclosingElement, isNull);

_sink.writelnWithIndent('library');
_sink.withIndent(() {
var name = e.name;
Expand Down Expand Up @@ -341,6 +343,7 @@ class _ElementWriter {

_sink.withIndent(() {
_writeReference(e);
_writeEnclosingElement(e);
_writeDocumentation(e);
_writeMetadata(e);
_writeSinceSdkVersion(e);
Expand Down Expand Up @@ -449,6 +452,13 @@ class _ElementWriter {
}
}

void _writeEnclosingElement(ElementImpl e) {
_elementPrinter.writeNamedElement(
'enclosingElement',
e.enclosingElement,
);
}

void _writeExportedReferences(LibraryElementImpl e) {
var exportedReferences = e.exportedReferences.toList();
exportedReferences.sortBy((e) => e.reference.toString());
Expand All @@ -465,14 +475,15 @@ class _ElementWriter {
}
}

void _writeExportElement(LibraryExportElement e) {
void _writeExportElement(LibraryExportElementImpl e) {
e.location;

_sink.writeIndentedLine(() {
_writeDirectiveUri(e.uri);
});

_sink.withIndent(() {
_writeEnclosingElement(e);
_writeMetadata(e);
_writeNamespaceCombinators(e.combinators);
});
Expand All @@ -496,6 +507,7 @@ class _ElementWriter {

_sink.withIndent(() {
_writeReference(e);
_writeEnclosingElement(e);
_writeDocumentation(e);
_writeMetadata(e);
_writeSinceSdkVersion(e);
Expand Down Expand Up @@ -569,6 +581,7 @@ class _ElementWriter {

_sink.withIndent(() {
_writeReference(e);
_writeEnclosingElement(e);
_writeDocumentation(e);
_writeMetadata(e);
_writeSinceSdkVersion(e);
Expand All @@ -584,7 +597,7 @@ class _ElementWriter {
_assertNonSyntheticElementSelf(e);
}

void _writeImportElement(LibraryImportElement e) {
void _writeImportElement(LibraryImportElementImpl e) {
e.location;

_sink.writeIndentedLine(() {
Expand All @@ -594,12 +607,13 @@ class _ElementWriter {
});

_sink.withIndent(() {
_writeEnclosingElement(e);
_writeMetadata(e);
_writeNamespaceCombinators(e.combinators);
});
}

void _writeImportElementPrefix(ImportElementPrefix? prefix) {
void _writeImportElementPrefix(ImportElementPrefixImpl? prefix) {
if (prefix != null) {
_sink.writeIf(prefix is DeferredImportElementPrefix, ' deferred');
_sink.write(' as ');
Expand Down Expand Up @@ -649,6 +663,7 @@ class _ElementWriter {

_sink.withIndent(() {
_writeReference(e);
_writeEnclosingElement(e);
_writeDocumentation(e);
_writeMetadata(e);
_writeSinceSdkVersion(e);
Expand Down Expand Up @@ -745,6 +760,7 @@ class _ElementWriter {
return configuration.withSyntheticDartCoreImport || !import.isSynthetic;
}).toList();
_writeElements('imports', imports, _writeImportElement);
_writeElements('prefixes', e.prefixes, _writePrefixElement);
}

_writeElements('exports', e.libraryExports, _writeExportElement);
Expand Down Expand Up @@ -1047,6 +1063,7 @@ class _ElementWriter {

_sink.withIndent(() {
_writeReference(e);
_writeEnclosingElement(e);
_writeDocumentation(e);
_writeMetadata(e);
_writeSinceSdkVersion(e);
Expand Down Expand Up @@ -1199,6 +1216,17 @@ class _ElementWriter {
});
}

void _writePrefixElement(PrefixElementImpl e) {
_sink.writeIndentedLine(() {
_writeName(e);
});

_sink.withIndent(() {
_writeReference(e);
_writeEnclosingElement(e);
});
}

void _writePropertyAccessorElement(PropertyAccessorElement e) {
e as PropertyAccessorElementImpl;

Expand Down Expand Up @@ -1252,6 +1280,7 @@ class _ElementWriter {

_sink.withIndent(() {
_writeReference(e);
_writeEnclosingElement(e);
_writeDocumentation(e);
_writeMetadata(e);
_writeSinceSdkVersion(e);
Expand Down Expand Up @@ -1321,6 +1350,7 @@ class _ElementWriter {

_sink.withIndent(() {
_writeReference(e);
_writeEnclosingElement(e);
_writeDocumentation(e);
_writeMetadata(e);
_writeSinceSdkVersion(e);
Expand Down Expand Up @@ -1495,6 +1525,7 @@ class _ElementWriter {

void _writeUnitElement(CompilationUnitElementImpl e) {
_writeReference(e);
_writeEnclosingElement(e);

if (configuration.withImports) {
var imports = e.libraryImports.where((import) {
Expand Down
Loading

0 comments on commit 962f78b

Please sign in to comment.