Skip to content

Commit 683be87

Browse files
scheglovCommit Queue
authored andcommitted
Fine. Turn BaseName into extension type.
Change-Id: I2367be8648d790ca6bf64960a238d822268e7240 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412120 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 2ad1b56 commit 683be87

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

pkg/analyzer/lib/src/fine/lookup_name.dart

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,36 @@ import 'package:analyzer/src/summary2/data_reader.dart';
66
import 'package:analyzer/src/summary2/data_writer.dart';
77
import 'package:analyzer/src/utilities/extensions/string.dart';
88

9-
typedef BaseName = String;
9+
/// The base name of an element.
10+
///
11+
/// In contrast to [LookupName] there is no `=` at the end.
12+
extension type BaseName(String _it) {
13+
factory BaseName.read(SummaryDataReader reader) {
14+
var str = reader.readStringUtf8();
15+
return BaseName(str);
16+
}
17+
18+
void write(BufferedSink sink) {
19+
sink.writeStringUtf8(_it);
20+
}
1021

22+
static int compare(BaseName left, BaseName right) {
23+
return left._it.compareTo(right._it);
24+
}
25+
}
26+
27+
/// The lookup name of an element.
28+
///
29+
/// Specifically, for setters there is `=` at the end.
1130
extension type LookupName(String _it) {
1231
factory LookupName.read(SummaryDataReader reader) {
1332
var str = reader.readStringUtf8();
1433
return LookupName(str);
1534
}
1635

1736
BaseName get asBaseName {
18-
return _it.removeSuffix('=') ?? _it;
37+
var str = _it.removeSuffix('=') ?? _it;
38+
return str.asBaseName;
1939
}
2040

2141
/// Returns the underlying [String] value, explicitly.
@@ -32,8 +52,43 @@ extension type LookupName(String _it) {
3252
}
3353
}
3454

55+
extension BufferedSinkExtension on BufferedSink {
56+
void writeBaseNameIterable(Iterable<BaseName> names) {
57+
writeUInt30(names.length);
58+
for (var baseName in names) {
59+
baseName.write(this);
60+
}
61+
}
62+
}
63+
64+
extension IterableOfBaseNameExtension on Iterable<BaseName> {
65+
List<BaseName> sorted() => [...this]..sort(BaseName.compare);
66+
}
67+
68+
extension IterableOfStringExtension on Iterable<String> {
69+
Set<BaseName> toBaseNameSet() {
70+
return map((str) => str.asBaseName).toSet();
71+
}
72+
}
73+
3574
extension StringExtension on String {
75+
BaseName get asBaseName {
76+
return BaseName(this);
77+
}
78+
3679
LookupName get asLookupName {
3780
return LookupName(this);
3881
}
3982
}
83+
84+
extension SummaryDataReaderExtension on SummaryDataReader {
85+
Set<BaseName> readBaseNameSet() {
86+
var length = readUInt30();
87+
var result = <BaseName>{};
88+
for (var i = 0; i < length; i++) {
89+
var baseName = BaseName.read(this);
90+
result.add(baseName);
91+
}
92+
return result;
93+
}
94+
}

pkg/analyzer/lib/src/fine/requirements.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ class BundleRequirementsManifest {
9393
switch (combinator) {
9494
case HideElementCombinator():
9595
return ExportRequirementHideCombinator(
96-
hiddenBaseNames: combinator.hiddenNames.toSet(),
96+
hiddenBaseNames: combinator.hiddenNames.toBaseNameSet(),
9797
);
9898
case ShowElementCombinator():
9999
return ExportRequirementShowCombinator(
100-
shownBaseNames: combinator.shownNames.toSet(),
100+
shownBaseNames: combinator.shownNames.toBaseNameSet(),
101101
);
102102
}
103103
}).toList();
@@ -376,14 +376,14 @@ final class ExportRequirementHideCombinator
376376

377377
factory ExportRequirementHideCombinator.read(SummaryDataReader reader) {
378378
return ExportRequirementHideCombinator(
379-
hiddenBaseNames: reader.readStringUtf8Set(),
379+
hiddenBaseNames: reader.readBaseNameSet(),
380380
);
381381
}
382382

383383
@override
384384
void write(BufferedSink sink) {
385385
sink.writeEnum(_ExportRequirementCombinatorKind.hide);
386-
sink.writeStringUtf8Iterable(hiddenBaseNames);
386+
sink.writeBaseNameIterable(hiddenBaseNames);
387387
}
388388
}
389389

@@ -398,14 +398,14 @@ final class ExportRequirementShowCombinator
398398

399399
factory ExportRequirementShowCombinator.read(SummaryDataReader reader) {
400400
return ExportRequirementShowCombinator(
401-
shownBaseNames: reader.readStringUtf8Set(),
401+
shownBaseNames: reader.readBaseNameSet(),
402402
);
403403
}
404404

405405
@override
406406
void write(BufferedSink sink) {
407407
sink.writeEnum(_ExportRequirementCombinatorKind.show);
408-
sink.writeStringUtf8Iterable(shownBaseNames);
408+
sink.writeBaseNameIterable(shownBaseNames);
409409
}
410410
}
411411

0 commit comments

Comments
 (0)