Test that augmentations are listed in the depth-first pre-order.

Change-Id: I7ade7b101c3c7895c1e8a68ca336ac83fa2b1348
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312341
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2023-07-05 03:01:40 +00:00 committed by Commit Queue
parent 636abe3ab7
commit 03e6d8d758
3 changed files with 69 additions and 3 deletions

View file

@ -133,6 +133,7 @@ class ElementTextConfiguration {
bool withExportScope = false;
bool withFunctionTypeParameters = false;
bool withImports = true;
bool withLibraryAugmentations = false;
bool withMetadata = true;
bool withNonSynthetic = false;
bool withPropertyLinking = false;
@ -262,7 +263,7 @@ class _ElementWriter {
return components.join(';');
}
void _writeAugmentationElement(LibraryAugmentationElement e) {
void _writeAugmentationElement(LibraryAugmentationElementImpl e) {
_writeLibraryOrAugmentationElement(e);
}
@ -274,7 +275,7 @@ class _ElementWriter {
_sink.withIndent(() {
_writeMetadata(e);
if (uri is DirectiveUriWithAugmentation) {
if (uri is DirectiveUriWithAugmentationImpl) {
_writeAugmentationElement(uri.augmentation);
}
});
@ -644,7 +645,22 @@ class _ElementWriter {
}
}
void _writeLibraryOrAugmentationElement(LibraryOrAugmentationElement e) {
void _writeLibraryAugmentations(LibraryElementImpl e) {
if (configuration.withLibraryAugmentations) {
final augmentations = e.augmentations;
if (augmentations.isNotEmpty) {
_sink.writelnWithIndent('augmentations');
_sink.withIndent(() {
for (final element in augmentations) {
_sink.writeIndent();
_elementPrinter.writeElement0(element);
}
});
}
}
}
void _writeLibraryOrAugmentationElement(LibraryOrAugmentationElementImpl e) {
_writeDocumentation(e);
_writeMetadata(e);
_writeSinceSdkVersion(e);
@ -665,6 +681,10 @@ class _ElementWriter {
_sink.withIndent(() {
_writeUnitElement(e.definingCompilationUnit);
});
if (e is LibraryElementImpl) {
_writeLibraryAugmentations(e);
}
}
void _writeMetadata(Element element) {

View file

@ -29073,6 +29073,48 @@ library
expect(augmentation.enclosingElement2, same(library));
}
test_library_augmentationImports_depthFirst() async {
newFile('$testPackageLibPath/a.dart', r'''
library augment 'test.dart';
import augment 'b.dart';
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'a.dart';
''');
newFile('$testPackageLibPath/c.dart', r'''
library augment 'test.dart';
''');
final library = await buildLibrary(r'''
import augment 'a.dart';
import augment 'c.dart';
''');
configuration.withLibraryAugmentations = true;
checkElementText(library, r'''
library
augmentationImports
package:test/a.dart
augmentationImports
package:test/b.dart
definingUnit
definingUnit
package:test/c.dart
definingUnit
definingUnit
augmentations
self::@augmentation::package:test/a.dart
self::@augmentation::package:test/b.dart
self::@augmentation::package:test/c.dart
''');
final import_0 = library.augmentationImports[0];
final augmentation = import_0.importedAugmentation!;
expect(augmentation.enclosingElement2, same(library));
}
test_library_augmentationImports_noRelativeUriStr() async {
final library = await buildLibrary(r'''
import augment '${'foo'}.dart';

View file

@ -69,7 +69,11 @@ class ElementPrinter {
void writeElement(String name, Element? element) {
_sink.writeWithIndent('$name: ');
writeElement0(element);
}
/// TODO(scheglov) rename [writeElement] to `writeNamedElement`, and this.
void writeElement0(Element? element) {
switch (element) {
case null:
_sink.writeln('<null>');