Skip to content

Commit cf5dfd1

Browse files
author
Dart CI
committed
Version 2.18.0-222.0.dev
Merge commit '3c793774c34877d1b18aa62066e2ac0288257be8' into 'dev'
2 parents ed99d70 + 3c79377 commit cf5dfd1

File tree

7 files changed

+853
-27
lines changed

7 files changed

+853
-27
lines changed

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ class FileState {
663663

664664
/// Return the unlinked unit, from bytes or new.
665665
AnalysisDriverUnlinkedUnit _getUnlinkedUnit() {
666-
final testData = _fsState.testData?.forFile(resource);
666+
final testData = _fsState.testData?.forFile(resource, uri);
667667

668668
var bytes = _fsState._byteStore.get(_unlinkedKey!);
669669
if (bytes != null && bytes.isNotEmpty) {
@@ -1262,7 +1262,7 @@ class FileSystemState {
12621262
}
12631263

12641264
@visibleForTesting
1265-
FileState? getExistingFileForResource(File file) {
1265+
FileState? getExisting(File file) {
12661266
return _pathToFile[file.path];
12671267
}
12681268

@@ -1460,21 +1460,22 @@ class FileSystemStateTestView {
14601460
class FileSystemTestData {
14611461
final Map<File, FileTestData> files = {};
14621462

1463-
FileTestData forFile(File file) {
1464-
return files[file] ??= FileTestData._(file);
1463+
FileTestData forFile(File file, Uri uri) {
1464+
return files[file] ??= FileTestData._(file, uri);
14651465
}
14661466
}
14671467

14681468
class FileTestData {
14691469
final File file;
1470+
final Uri uri;
14701471

14711472
/// We add the key every time we get unlinked data from the byte store.
14721473
final List<String> unlinkedKeyGet = [];
14731474

14741475
/// We add the key every time we put unlinked data into the byte store.
14751476
final List<String> unlinkedKeyPut = [];
14761477

1477-
FileTestData._(this.file);
1478+
FileTestData._(this.file, this.uri);
14781479
}
14791480

14801481
/// Precomputed properties of a file URI, used because [Uri] is relatively
@@ -1608,7 +1609,7 @@ class LibraryFileStateKind extends LibraryOrAugmentationFileKind {
16081609
});
16091610

16101611
@override
1611-
LibraryFileStateKind? get library => this;
1612+
LibraryFileStateKind get library => this;
16121613

16131614
bool hasPart(PartFileStateKind part) {
16141615
return file.partedFiles.contains(part.file);

pkg/analyzer/test/src/dart/analysis/analyzer_state_printer.dart

+78-9
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import 'package:analyzer/src/dart/analysis/library_context.dart';
1010
import 'package:analyzer/src/dart/micro/resolve_file.dart';
1111
import 'package:collection/collection.dart';
1212
import 'package:path/path.dart';
13+
import 'package:test/test.dart';
1314

1415
class AnalyzerStatePrinter {
1516
final MemoryByteStore byteStore;
17+
final FileStateIdProvider fileStateIdProvider;
1618
final KeyShorter keyShorter;
1719
final LibraryContext libraryContext;
1820
final ResourceProvider resourceProvider;
@@ -22,6 +24,7 @@ class AnalyzerStatePrinter {
2224

2325
AnalyzerStatePrinter({
2426
required this.byteStore,
27+
required this.fileStateIdProvider,
2528
required this.keyShorter,
2629
required this.libraryContext,
2730
required this.resourceProvider,
@@ -93,35 +96,88 @@ class AnalyzerStatePrinter {
9396
});
9497
}
9598

99+
void _writeFile(FileState file) {
100+
_withIndent(() {
101+
_writelnWithIndent('id: ${fileStateIdProvider[file]}');
102+
_writeFileKind(file);
103+
_writeFileUnlinkedKey(file);
104+
});
105+
}
106+
107+
void _writeFileKind(FileState file) {
108+
final kind = file.kind;
109+
if (kind is LibraryFileStateKind) {
110+
_writelnWithIndent('kind: library');
111+
expect(kind.library.file, same(file));
112+
} else if (kind is PartOfNameFileStateKind) {
113+
_writelnWithIndent('kind: partOfName');
114+
_withIndent(() {
115+
final library = kind.library;
116+
if (library != null) {
117+
final id = fileStateIdProvider[library.file];
118+
_writelnWithIndent('library: $id');
119+
} else {
120+
_writelnWithIndent('name: ${kind.directive.name}');
121+
}
122+
});
123+
} else if (kind is PartOfUriKnownFileStateKind) {
124+
_writelnWithIndent('kind: partOfUriKnown');
125+
_withIndent(() {
126+
final library = kind.library;
127+
if (library != null) {
128+
final id = fileStateIdProvider[library.file];
129+
_writelnWithIndent('library: $id');
130+
} else {
131+
final id = fileStateIdProvider[kind.uriFile];
132+
_writelnWithIndent('uriFile: $id');
133+
}
134+
});
135+
} else {
136+
throw UnimplementedError('${kind.runtimeType}');
137+
}
138+
}
139+
96140
void _writeFiles(FileSystemTestData testData) {
141+
final fileMap = testData.files;
142+
final fileDataList = fileMap.values.toList();
143+
fileDataList.sortBy((fileData) => fileData.file.path);
144+
145+
// Ask ID for every file in the sorted order, so that IDs are nice.
146+
for (final fileData in fileDataList) {
147+
final current = fileSystemState.getExisting(fileData.file);
148+
if (current != null) {
149+
fileStateIdProvider[current];
150+
}
151+
}
152+
97153
_writelnWithIndent('files');
98154
_withIndent(() {
99-
final fileMap = testData.files;
100-
final fileDataList = fileMap.values.toList();
101-
fileDataList.sortBy((fileData) => fileData.file.path);
102-
103155
for (final fileData in fileDataList) {
104156
final file = fileData.file;
105157
_writelnWithIndent(_posixPath(file));
106158
_withIndent(() {
107-
final current = fileSystemState.getExistingFileForResource(file);
159+
final current = fileSystemState.getExisting(file);
108160
if (current != null) {
109161
_writelnWithIndent('current');
110-
_withIndent(() {
111-
final unlinkedShort = keyShorter.shortKey(current.unlinkedKey);
112-
_writelnWithIndent('unlinkedKey: $unlinkedShort');
113-
});
162+
_writeFile(current);
114163
}
115164

116165
final shortGets = keyShorter.shortKeys(fileData.unlinkedKeyGet);
117166
final shortPuts = keyShorter.shortKeys(fileData.unlinkedKeyPut);
118167
_writelnWithIndent('unlinkedGet: $shortGets');
119168
_writelnWithIndent('unlinkedPut: $shortPuts');
169+
170+
_writelnWithIndent('uri: ${fileData.uri}');
120171
});
121172
}
122173
});
123174
}
124175

176+
void _writeFileUnlinkedKey(FileState file) {
177+
final unlinkedShort = keyShorter.shortKey(file.unlinkedKey);
178+
_writelnWithIndent('unlinkedKey: $unlinkedShort');
179+
}
180+
125181
void _writeLibraryContext(LibraryContextTestData testData) {
126182
_writelnWithIndent('libraryCycles');
127183
_withIndent(() {
@@ -149,6 +205,11 @@ class AnalyzerStatePrinter {
149205
_withIndent(() {
150206
final short = keyShorter.shortKey(current.resolutionKey!);
151207
_writelnWithIndent('key: $short');
208+
209+
final fileIdList = current.libraries
210+
.map((fileState) => fileStateIdProvider[fileState])
211+
.toList();
212+
_writelnWithIndent('libraries: ${fileIdList.join(' ')}');
152213
});
153214
}
154215

@@ -180,6 +241,14 @@ class AnalyzerStatePrinter {
180241
}
181242
}
182243

244+
class FileStateIdProvider {
245+
final Map<FileState, String> _map = Map.identity();
246+
247+
String operator [](FileState file) {
248+
return _map[file] ??= 'file_${_map.length}';
249+
}
250+
}
251+
183252
/// Keys in the byte store are long hashes, which are hard to read.
184253
/// So, we generate short unique versions for them.
185254
class KeyShorter {

pkg/analyzer/test/src/dart/micro/file_resolution.dart

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'package:linter/src/rules.dart';
2323
import 'package:test/test.dart';
2424

2525
import '../analysis/analyzer_state_printer.dart' as printer;
26+
import '../resolution/node_text_expectations.dart';
2627
import '../resolution/resolution.dart';
2728

2829
/// [FileResolver] based implementation of [ResolutionTest].
@@ -38,6 +39,8 @@ class FileResolutionTest with ResourceProviderMixin, ResolutionTest {
3839

3940
late FileResolver fileResolver;
4041

42+
final printer.FileStateIdProvider _fileStateIdProvider =
43+
printer.FileStateIdProvider();
4144
final printer.KeyShorter _keyShorter = printer.KeyShorter();
4245

4346
FileSystemState get fsState => fileResolver.fsState!;
@@ -68,6 +71,7 @@ class FileResolutionTest with ResourceProviderMixin, ResolutionTest {
6871
final buffer = StringBuffer();
6972
printer.AnalyzerStatePrinter(
7073
byteStore: byteStore,
74+
fileStateIdProvider: _fileStateIdProvider,
7175
keyShorter: _keyShorter,
7276
libraryContext: libraryContext,
7377
resourceProvider: resourceProvider,
@@ -77,6 +81,7 @@ class FileResolutionTest with ResourceProviderMixin, ResolutionTest {
7781

7882
if (actual != expected) {
7983
print(actual);
84+
NodeTextExpectationsCollector.add(actual);
8085
}
8186
expect(actual, expected);
8287
}

0 commit comments

Comments
 (0)