Index: pkg/analyzer/test/src/dart/analysis/file_state_test.dart |
diff --git a/pkg/analyzer/test/src/dart/analysis/file_state_test.dart b/pkg/analyzer/test/src/dart/analysis/file_state_test.dart |
index 80696fa9c16c8d99b64644d0fd1b0d5141b66cd0..c2fac1c5f82b0fd2299843c5989a462fd3dda8ba 100644 |
--- a/pkg/analyzer/test/src/dart/analysis/file_state_test.dart |
+++ b/pkg/analyzer/test/src/dart/analysis/file_state_test.dart |
@@ -67,7 +67,7 @@ class FileSystemStateTest { |
expect(file.importedFiles, isEmpty); |
expect(file.exportedFiles, isEmpty); |
expect(file.partedFiles, isEmpty); |
- expect(file.dependencies, isEmpty); |
+ expect(file.directReferencedFiles, isEmpty); |
expect(file.isPart, isFalse); |
expect(file.library, isNull); |
expect(file.unlinked, isNotNull); |
@@ -123,7 +123,7 @@ class A1 {} |
expect(file.partedFiles[0].path, a4); |
expect(file.partedFiles[0].uri, FastUri.parse('package:aaa/a4.dart')); |
- expect(file.dependencies, hasLength(5)); |
+ expect(file.directReferencedFiles, hasLength(5)); |
expect(fileSystemState.getFilesForPath(a1), [file]); |
} |
@@ -155,7 +155,7 @@ class A2 {} |
expect(file_a2.importedFiles, isEmpty); |
expect(file_a2.exportedFiles, isEmpty); |
expect(file_a2.partedFiles, isEmpty); |
- expect(file_a2.dependencies, isEmpty); |
+ expect(file_a2.directReferencedFiles, isEmpty); |
// The library is not known yet. |
expect(file_a2.isPart, isTrue); |
@@ -165,7 +165,7 @@ class A2 {} |
FileState file_a1 = fileSystemState.getFileForPath(a1); |
expect(file_a1.partedFiles, hasLength(1)); |
expect(file_a1.partedFiles[0], same(file_a2)); |
- expect(file_a1.dependencies, unorderedEquals([file_a2])); |
+ expect(file_a1.directReferencedFiles, unorderedEquals([file_a2])); |
// Now the part knows its library. |
expect(file_a2.library, same(file_a1)); |
@@ -265,6 +265,95 @@ class C { |
expect(file.apiSignature, signature); |
} |
+ test_transitiveFiles() { |
+ String pa = _p('/aaa/lib/a.dart'); |
+ String pb = _p('/aaa/lib/b.dart'); |
+ String pc = _p('/aaa/lib/c.dart'); |
+ String pd = _p('/aaa/lib/d.dart'); |
+ |
+ FileState fa = fileSystemState.getFileForPath(pa); |
+ FileState fb = fileSystemState.getFileForPath(pb); |
+ FileState fc = fileSystemState.getFileForPath(pc); |
+ FileState fd = fileSystemState.getFileForPath(pd); |
+ |
+ // Compute transitive closures for all files. |
+ fa.transitiveFiles; |
+ fb.transitiveFiles; |
+ fc.transitiveFiles; |
+ fd.transitiveFiles; |
+ expect(fileSystemState.test.filesWithoutTransitive, isEmpty); |
+ |
+ // No imports, so just a single file. |
+ provider.newFile(pa, ""); |
+ _assertTransitiveFiles(pa, [pa]); |
+ |
+ // Import b.dart into a.dart, two files now. |
+ provider.newFile(pa, "import 'b.dart';"); |
+ fa.refresh(); |
+ _assertFilesWithoutTransitive([fa]); |
+ _assertTransitiveFiles(pa, [pa, pb]); |
+ |
+ // Update b.dart so that it imports c.dart now. |
+ provider.newFile(pb, "import 'c.dart';"); |
+ fb.refresh(); |
+ _assertFilesWithoutTransitive([fa, fb]); |
+ _assertTransitiveFiles(pa, [pa, pb, pc]); |
+ _assertTransitiveFiles(pb, [pb, pc]); |
+ _assertFilesWithoutTransitive([]); |
+ |
+ // Update b.dart so that it exports d.dart instead. |
+ provider.newFile(pb, "export 'd.dart';"); |
+ fb.refresh(); |
+ _assertFilesWithoutTransitive([fa, fb]); |
+ _assertTransitiveFiles(pa, [pa, pb, pd]); |
+ _assertTransitiveFiles(pb, [pb, pd]); |
+ _assertFilesWithoutTransitive([]); |
+ |
+ // Update a.dart so that it does not import b.dart anymore. |
+ provider.newFile(pa, ""); |
+ fa.refresh(); |
+ _assertFilesWithoutTransitive([fa]); |
+ _assertTransitiveFiles(pa, [pa]); |
+ } |
+ |
+ test_transitiveFiles_cycle() { |
+ String pa = _p('/aaa/lib/a.dart'); |
+ String pb = _p('/aaa/lib/b.dart'); |
+ |
+ provider.newFile(pa, "import 'b.dart';"); |
+ provider.newFile(pb, "import 'a.dart';"); |
+ |
+ FileState fa = fileSystemState.getFileForPath(pa); |
+ FileState fb = fileSystemState.getFileForPath(pb); |
+ |
+ // Compute transitive closures for all files. |
+ fa.transitiveFiles; |
+ fb.transitiveFiles; |
+ _assertFilesWithoutTransitive([]); |
+ |
+ // It's a cycle. |
+ _assertTransitiveFiles(pa, [pa, pb]); |
+ _assertTransitiveFiles(pb, [pa, pb]); |
+ |
+ // Update a.dart so that it does not import b.dart anymore. |
+ provider.newFile(pa, ""); |
+ fa.refresh(); |
+ _assertFilesWithoutTransitive([fa, fb]); |
+ _assertTransitiveFiles(pa, [pa]); |
+ _assertTransitiveFiles(pb, [pa, pb]); |
+ } |
+ |
+ void _assertFilesWithoutTransitive(List<FileState> expected) { |
+ var actual = fileSystemState.test.filesWithoutTransitive; |
+ expect(actual, unorderedEquals(expected)); |
+ } |
+ |
+ void _assertTransitiveFiles(String path, List<String> expectedPaths) { |
+ FileState file = fileSystemState.getFileForPath(path); |
+ expect(file.transitiveFiles, |
+ unorderedEquals(expectedPaths.map(fileSystemState.getFileForPath))); |
+ } |
+ |
String _p(String path) => provider.convertPath(path); |
static String _md5(String content) { |