Files
sdk/pkg/kernel/test/text_util_test.dart
Jens Johansen 4d3d70af23 [kernel] Format kernel
Kernel sdk version was bumped from 3.6 to 3.12 in
https://dart-review.googlesource.com/c/sdk/+/487542 (and to `^3.12.0-0`
in https://dart-review.googlesource.com/c/sdk/+/487880) but the source
was never formatted.

This is, if nothing else, bad for reviews, where editing a file changes
the file in lots of places because of new formatting.

This CL is the result of running

```
out/ReleaseX64/dart-sdk/bin/dart format pkg/kernel/
```

but also updates the formatter version used by a source generator
(`pkg/front_end/tool/visitor_generator.dart`) so things agree.

Change-Id: I66e35d4f1e2d08cecc30fb314546cae78b49e99b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490082
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2026-03-24 06:00:44 -07:00

71 lines
2.1 KiB
Dart

// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:kernel/ast.dart';
import 'package:kernel/src/printer.dart';
import "reference_name_test.dart" show createComponent;
void main() {
testQualifiedCanonicalNameToString();
}
void testQualifiedCanonicalNameToString() {
Component component = createComponent();
component.computeCanonicalNames();
NamedNodeCollector namedNodeCollector = new NamedNodeCollector();
component.accept(namedNodeCollector);
bool foundMismatch = false;
for (NamedNode namedNode in namedNodeCollector.namedNodes) {
for (AstTextStrategy strategy in [
const AstTextStrategy(
includeLibraryNamesInMembers: false,
includeLibraryNamesInTypes: false,
),
const AstTextStrategy(includeLibraryNamesInMembers: true),
const AstTextStrategy(includeLibraryNamesInTypes: true),
const AstTextStrategy(
includeLibraryNamesInMembers: true,
includeLibraryNamesInTypes: true,
),
]) {
String throughNode = namedNode.toText(strategy);
String throughReference = namedNode.reference.toText(strategy);
String throughCanonicalName = namedNode.reference.canonicalName!.toText(
strategy,
);
if (throughNode == throughReference &&
throughReference == throughCanonicalName) {
continue;
}
print(
"${namedNode.runtimeType} "
"(${strategy.includeLibraryNamesInMembers},"
"${strategy.includeLibraryNamesInTypes}): "
"$throughNode <--> $throughReference <--> $throughCanonicalName",
);
foundMismatch = true;
}
}
if (foundMismatch) throw "Found mismatch.";
}
class NamedNodeCollector extends RecursiveVisitor {
List<NamedNode> namedNodes = [];
@override
void defaultNode(Node node) {
if (node is NamedNode) {
namedNodes.add(node);
}
if (node is Extension) return;
if (node is Typedef) return;
if (node is Member) return;
super.defaultNode(node);
}
}