@@ -10,9 +10,11 @@ import 'package:analyzer/src/dart/analysis/library_context.dart';
10
10
import 'package:analyzer/src/dart/micro/resolve_file.dart' ;
11
11
import 'package:collection/collection.dart' ;
12
12
import 'package:path/path.dart' ;
13
+ import 'package:test/test.dart' ;
13
14
14
15
class AnalyzerStatePrinter {
15
16
final MemoryByteStore byteStore;
17
+ final FileStateIdProvider fileStateIdProvider;
16
18
final KeyShorter keyShorter;
17
19
final LibraryContext libraryContext;
18
20
final ResourceProvider resourceProvider;
@@ -22,6 +24,7 @@ class AnalyzerStatePrinter {
22
24
23
25
AnalyzerStatePrinter ({
24
26
required this .byteStore,
27
+ required this .fileStateIdProvider,
25
28
required this .keyShorter,
26
29
required this .libraryContext,
27
30
required this .resourceProvider,
@@ -93,35 +96,88 @@ class AnalyzerStatePrinter {
93
96
});
94
97
}
95
98
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
+
96
140
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
+
97
153
_writelnWithIndent ('files' );
98
154
_withIndent (() {
99
- final fileMap = testData.files;
100
- final fileDataList = fileMap.values.toList ();
101
- fileDataList.sortBy ((fileData) => fileData.file.path);
102
-
103
155
for (final fileData in fileDataList) {
104
156
final file = fileData.file;
105
157
_writelnWithIndent (_posixPath (file));
106
158
_withIndent (() {
107
- final current = fileSystemState.getExistingFileForResource (file);
159
+ final current = fileSystemState.getExisting (file);
108
160
if (current != null ) {
109
161
_writelnWithIndent ('current' );
110
- _withIndent (() {
111
- final unlinkedShort = keyShorter.shortKey (current.unlinkedKey);
112
- _writelnWithIndent ('unlinkedKey: $unlinkedShort ' );
113
- });
162
+ _writeFile (current);
114
163
}
115
164
116
165
final shortGets = keyShorter.shortKeys (fileData.unlinkedKeyGet);
117
166
final shortPuts = keyShorter.shortKeys (fileData.unlinkedKeyPut);
118
167
_writelnWithIndent ('unlinkedGet: $shortGets ' );
119
168
_writelnWithIndent ('unlinkedPut: $shortPuts ' );
169
+
170
+ _writelnWithIndent ('uri: ${fileData .uri }' );
120
171
});
121
172
}
122
173
});
123
174
}
124
175
176
+ void _writeFileUnlinkedKey (FileState file) {
177
+ final unlinkedShort = keyShorter.shortKey (file.unlinkedKey);
178
+ _writelnWithIndent ('unlinkedKey: $unlinkedShort ' );
179
+ }
180
+
125
181
void _writeLibraryContext (LibraryContextTestData testData) {
126
182
_writelnWithIndent ('libraryCycles' );
127
183
_withIndent (() {
@@ -149,6 +205,11 @@ class AnalyzerStatePrinter {
149
205
_withIndent (() {
150
206
final short = keyShorter.shortKey (current.resolutionKey! );
151
207
_writelnWithIndent ('key: $short ' );
208
+
209
+ final fileIdList = current.libraries
210
+ .map ((fileState) => fileStateIdProvider[fileState])
211
+ .toList ();
212
+ _writelnWithIndent ('libraries: ${fileIdList .join (' ' )}' );
152
213
});
153
214
}
154
215
@@ -180,6 +241,14 @@ class AnalyzerStatePrinter {
180
241
}
181
242
}
182
243
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
+
183
252
/// Keys in the byte store are long hashes, which are hard to read.
184
253
/// So, we generate short unique versions for them.
185
254
class KeyShorter {
0 commit comments