| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.context.directory.manager; | 5 library test.context.directory.manager; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/context_manager.dart'; | 9 import 'package:analysis_server/src/context_manager.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| (...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 } | 840 } |
| 841 } | 841 } |
| 842 | 842 |
| 843 class TestContextManager extends ContextManager { | 843 class TestContextManager extends ContextManager { |
| 844 /** | 844 /** |
| 845 * Source of timestamps stored in [currentContextFilePaths]. | 845 * Source of timestamps stored in [currentContextFilePaths]. |
| 846 */ | 846 */ |
| 847 int now = 0; | 847 int now = 0; |
| 848 | 848 |
| 849 /** | 849 /** |
| 850 * The analysis context that was created. |
| 851 */ |
| 852 AnalysisContextImpl currentContext; |
| 853 |
| 854 /** |
| 850 * Map from context to the timestamp when the context was created. | 855 * Map from context to the timestamp when the context was created. |
| 851 */ | 856 */ |
| 852 Map<String, int> currentContextTimestamps = <String, int>{}; | 857 Map<String, int> currentContextTimestamps = <String, int>{}; |
| 853 | 858 |
| 854 /** | 859 /** |
| 855 * Map from context to (map from file path to timestamp of last event). | 860 * Map from context to (map from file path to timestamp of last event). |
| 856 */ | 861 */ |
| 857 final Map<String, Map<String, int>> currentContextFilePaths = | 862 final Map<String, Map<String, int>> currentContextFilePaths = |
| 858 <String, Map<String, int>>{}; | 863 <String, Map<String, int>>{}; |
| 859 | 864 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 881 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; | 886 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; |
| 882 | 887 |
| 883 @override | 888 @override |
| 884 AnalysisContext addContext(Folder folder, UriResolver packageUriResolver) { | 889 AnalysisContext addContext(Folder folder, UriResolver packageUriResolver) { |
| 885 String path = folder.path; | 890 String path = folder.path; |
| 886 expect(currentContextPaths, isNot(contains(path))); | 891 expect(currentContextPaths, isNot(contains(path))); |
| 887 currentContextTimestamps[path] = now; | 892 currentContextTimestamps[path] = now; |
| 888 currentContextFilePaths[path] = <String, int>{}; | 893 currentContextFilePaths[path] = <String, int>{}; |
| 889 currentContextSources[path] = new HashSet<Source>(); | 894 currentContextSources[path] = new HashSet<Source>(); |
| 890 currentContextPackageUriResolvers[path] = packageUriResolver; | 895 currentContextPackageUriResolvers[path] = packageUriResolver; |
| 891 AnalysisContextImpl context = new AnalysisContextImpl(); | 896 currentContext = new AnalysisContextImpl(); |
| 892 context.sourceFactory = new SourceFactory( | 897 currentContext.sourceFactory = new SourceFactory( |
| 893 packageUriResolver == null ? [] : [packageUriResolver]); | 898 packageUriResolver == null ? [] : [packageUriResolver]); |
| 894 return context; | 899 return currentContext; |
| 895 } | 900 } |
| 896 | 901 |
| 897 @override | 902 @override |
| 898 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { | 903 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { |
| 899 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path]; | 904 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path]; |
| 900 Set<Source> sources = currentContextSources[contextFolder.path]; | 905 Set<Source> sources = currentContextSources[contextFolder.path]; |
| 901 | 906 |
| 902 for (Source source in changeSet.addedSources) { | 907 for (Source source in changeSet.addedSources) { |
| 903 expect(filePaths, isNot(contains(source.fullName))); | 908 expect(filePaths, isNot(contains(source.fullName))); |
| 904 filePaths[source.fullName] = now; | 909 filePaths[source.fullName] = now; |
| 905 sources.add(source); | 910 sources.add(source); |
| 906 } | 911 } |
| 907 for (Source source in changeSet.removedSources) { | 912 for (Source source in changeSet.removedSources) { |
| 908 expect(filePaths, contains(source.fullName)); | 913 expect(filePaths, contains(source.fullName)); |
| 909 filePaths.remove(source.fullName); | 914 filePaths.remove(source.fullName); |
| 910 sources.remove(source); | 915 sources.remove(source); |
| 911 } | 916 } |
| 912 for (Source source in changeSet.changedSources) { | 917 for (Source source in changeSet.changedSources) { |
| 913 expect(filePaths, contains(source.fullName)); | 918 expect(filePaths, contains(source.fullName)); |
| 914 filePaths[source.fullName] = now; | 919 filePaths[source.fullName] = now; |
| 915 } | 920 } |
| 921 |
| 922 currentContext.applyChanges(changeSet); |
| 916 } | 923 } |
| 917 | 924 |
| 918 void assertContextFiles(String contextPath, List<String> expectedFiles) { | 925 void assertContextFiles(String contextPath, List<String> expectedFiles) { |
| 919 var actualFiles = currentContextFilePaths[contextPath].keys; | 926 var actualFiles = currentContextFilePaths[contextPath].keys; |
| 920 expect(actualFiles, unorderedEquals(expectedFiles)); | 927 expect(actualFiles, unorderedEquals(expectedFiles)); |
| 921 } | 928 } |
| 922 | 929 |
| 923 void assertContextPaths(List<String> expected) { | 930 void assertContextPaths(List<String> expected) { |
| 924 expect(currentContextPaths, unorderedEquals(expected)); | 931 expect(currentContextPaths, unorderedEquals(expected)); |
| 925 } | 932 } |
| 926 | 933 |
| 927 @override | 934 @override |
| 928 void removeContext(Folder folder) { | 935 void removeContext(Folder folder) { |
| 929 String path = folder.path; | 936 String path = folder.path; |
| 930 expect(currentContextPaths, contains(path)); | 937 expect(currentContextPaths, contains(path)); |
| 931 currentContextTimestamps.remove(path); | 938 currentContextTimestamps.remove(path); |
| 932 currentContextFilePaths.remove(path); | 939 currentContextFilePaths.remove(path); |
| 933 currentContextSources.remove(path); | 940 currentContextSources.remove(path); |
| 934 currentContextPackageUriResolvers.remove(path); | 941 currentContextPackageUriResolvers.remove(path); |
| 935 } | 942 } |
| 936 | 943 |
| 937 @override | 944 @override |
| 938 void updateContextPackageUriResolver( | 945 void updateContextPackageUriResolver( |
| 939 Folder contextFolder, UriResolver packageUriResolver) { | 946 Folder contextFolder, UriResolver packageUriResolver) { |
| 940 currentContextPackageUriResolvers[contextFolder.path] = packageUriResolver; | 947 currentContextPackageUriResolvers[contextFolder.path] = packageUriResolver; |
| 941 } | 948 } |
| 942 } | 949 } |
| OLD | NEW |