@@ -10,9 +10,11 @@ import 'package:analyzer/src/dart/analysis/library_context.dart';
1010import 'package:analyzer/src/dart/micro/resolve_file.dart' ;
1111import 'package:collection/collection.dart' ;
1212import 'package:path/path.dart' ;
13+ import 'package:test/test.dart' ;
1314
1415class 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.
185254class KeyShorter {
0 commit comments