@@ -316,31 +316,79 @@ class AnalyzerStatePrinter {
316
316
void _writeFiles (FileSystemTestData testData) {
317
317
fileSystemState.pullReferencedFiles ();
318
318
319
- final fileDataList = < FileTestData > [];
320
- for (final fileData in testData.files.values) {
321
- if (omitSdkFiles && fileData.uri.isScheme ('dart' )) {
322
- continue ;
319
+ // Discover libraries for parts.
320
+ // This is required for consistency checking.
321
+ for (final fileData in testData.files.values.toList ()) {
322
+ final current = fileSystemState.getExisting (fileData.file);
323
+ if (current != null ) {
324
+ final kind = current.kind;
325
+ if (kind is PartOfNameFileStateKind ) {
326
+ kind.discoverLibraries ();
327
+ }
328
+ }
329
+ }
330
+
331
+ // Ask referenced libraries.
332
+ // This is required for consistency checking.
333
+ // TODO(scheglov) Remove when we use these for cycles.
334
+ for (final fileData in testData.files.values.toList ()) {
335
+ final current = fileSystemState.getExisting (fileData.file);
336
+ if (current != null ) {
337
+ final kind = current.kind;
338
+ if (kind is LibraryOrAugmentationFileKind ) {
339
+ kind.imports;
340
+ kind.exports;
341
+ }
323
342
}
324
- fileDataList.add (fileData);
325
343
}
326
- fileDataList.sortBy ((fileData) => fileData.file.path);
344
+
345
+ // Sort, mostly by path.
346
+ // But sort SDK libraries to the end, with `dart:core` first.
347
+ final fileDataList = testData.files.values.toList ();
348
+ fileDataList.sort ((first, second) {
349
+ final firstPath = first.file.path;
350
+ final secondPath = second.file.path;
351
+ if (omitSdkFiles) {
352
+ final firstUri = first.uri;
353
+ final secondUri = second.uri;
354
+ final firstIsSdk = firstUri.isScheme ('dart' );
355
+ final secondIsSdk = secondUri.isScheme ('dart' );
356
+ if (firstIsSdk && ! secondIsSdk) {
357
+ return 1 ;
358
+ } else if (! firstIsSdk && secondIsSdk) {
359
+ return - 1 ;
360
+ } else if (firstIsSdk && secondIsSdk) {
361
+ if ('$firstUri ' == 'dart:core' ) {
362
+ return - 1 ;
363
+ } else if ('$secondUri ' == 'dart:core' ) {
364
+ return 1 ;
365
+ }
366
+ }
367
+ }
368
+ return firstPath.compareTo (secondPath);
369
+ });
327
370
328
371
// Ask ID for every file in the sorted order, so that IDs are nice.
372
+ // Register objects that can be referenced.
373
+ idProvider.resetRegisteredObject ();
329
374
for (final fileData in fileDataList) {
330
375
final current = fileSystemState.getExisting (fileData.file);
331
376
if (current != null ) {
332
- idProvider.fileState (current);
377
+ idProvider.registerFileState (current);
333
378
final kind = current.kind;
334
- idProvider.fileStateKind (kind);
379
+ idProvider.registerFileStateKind (kind);
335
380
if (kind is LibraryFileStateKind ) {
336
- idProvider.libraryCycle (kind.libraryCycle);
381
+ idProvider.registerLibraryCycle (kind.libraryCycle);
337
382
}
338
383
}
339
384
}
340
385
341
386
_writelnWithIndent ('files' );
342
387
_withIndent (() {
343
388
for (final fileData in fileDataList) {
389
+ if (omitSdkFiles && fileData.uri.isScheme ('dart' )) {
390
+ continue ;
391
+ }
344
392
final file = fileData.file;
345
393
_writelnWithIndent (_posixPath (file));
346
394
_withIndent (() {
@@ -474,9 +522,10 @@ class AnalyzerStatePrinter {
474
522
void _writeReferencingFiles (FileState file) {
475
523
final referencingFiles = file.referencingFiles;
476
524
if (referencingFiles.isNotEmpty) {
477
- // TODO(scheglov) Print space-separated.
478
- final fileIds =
479
- referencingFiles.map (idProvider.fileState).sorted (compareNatural);
525
+ final fileIds = referencingFiles
526
+ .map (idProvider.fileState)
527
+ .sorted (compareNatural)
528
+ .join (' ' );
480
529
_writelnWithIndent ('referencingFiles: $fileIds ' );
481
530
}
482
531
}
@@ -511,16 +560,26 @@ class IdProvider {
511
560
final Map <String , String > _shortToKey = {};
512
561
final Map <String , String > _apiSignature = {};
513
562
563
+ Set <FileState > _currentFiles = {};
564
+ Set <FileStateKind > _currentKinds = {};
565
+ Set <LibraryCycle > _currentCycles = {};
566
+
514
567
String apiSignature (String signature) {
515
568
final length = _apiSignature.length;
516
569
return _apiSignature[signature] ?? = 'apiSignature_$length ' ;
517
570
}
518
571
519
572
String fileState (FileState file) {
573
+ if (! _currentFiles.contains (file)) {
574
+ throw StateError ('$file ' );
575
+ }
520
576
return _fileState[file] ?? = 'file_${_fileState .length }' ;
521
577
}
522
578
523
579
String fileStateKind (FileStateKind kind) {
580
+ if (! _currentKinds.contains (kind)) {
581
+ throw StateError ('$kind ' );
582
+ }
524
583
return _fileStateKind[kind] ?? = () {
525
584
if (kind is AugmentationKnownFileStateKind ) {
526
585
return 'augmentation_${_fileStateKind .length }' ;
@@ -541,9 +600,42 @@ class IdProvider {
541
600
}
542
601
543
602
String libraryCycle (LibraryCycle cycle) {
603
+ if (! _currentCycles.contains (cycle)) {
604
+ throw StateError ('$cycle ' );
605
+ }
544
606
return _libraryCycle[cycle] ?? = 'cycle_${_libraryCycle .length }' ;
545
607
}
546
608
609
+ /// Register that [file] is an object that can be referenced.
610
+ void registerFileState (FileState file) {
611
+ if (_currentFiles.contains (file)) {
612
+ throw StateError ('Duplicate: $file ' );
613
+ }
614
+ _currentFiles.add (file);
615
+ fileState (file);
616
+ }
617
+
618
+ /// Register that [kind] is an object that can be referenced.
619
+ void registerFileStateKind (FileStateKind kind) {
620
+ if (_currentKinds.contains (kind)) {
621
+ throw StateError ('Duplicate: $kind ' );
622
+ }
623
+ _currentKinds.add (kind);
624
+ fileStateKind (kind);
625
+ }
626
+
627
+ /// Register that [cycle] is an object that can be referenced.
628
+ void registerLibraryCycle (LibraryCycle cycle) {
629
+ _currentCycles.add (cycle);
630
+ libraryCycle (cycle);
631
+ }
632
+
633
+ void resetRegisteredObject () {
634
+ _currentFiles = {};
635
+ _currentKinds = {};
636
+ _currentCycles = {};
637
+ }
638
+
547
639
String shortKey (String key) {
548
640
var short = _keyToShort[key];
549
641
if (short == null ) {
0 commit comments