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 mocks; | 5 library mocks; |
6 | 6 |
| 7 import 'dart:async'; |
| 8 import 'dart:io'; |
7 @MirrorsUsed(targets: 'mocks', override: '*') | 9 @MirrorsUsed(targets: 'mocks', override: '*') |
8 import 'dart:mirrors'; | 10 import 'dart:mirrors'; |
9 import 'dart:async'; | |
10 import 'dart:io'; | |
11 | 11 |
12 import 'package:analysis_server/src/analysis_server.dart'; | 12 import 'package:analysis_server/src/analysis_server.dart'; |
13 import 'package:analysis_server/src/channel/channel.dart'; | 13 import 'package:analysis_server/src/channel/channel.dart'; |
14 import 'package:analysis_server/src/operation/operation.dart'; | 14 import 'package:analysis_server/src/operation/operation.dart'; |
15 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 15 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
16 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; | 16 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; |
17 import 'package:analysis_server/src/source/optimizing_pub_package_map_provider.d
art'; | |
18 import 'package:analyzer/file_system/file_system.dart' as resource; | 17 import 'package:analyzer/file_system/file_system.dart' as resource; |
19 import 'package:analyzer/file_system/memory_file_system.dart' as resource; | 18 import 'package:analyzer/file_system/memory_file_system.dart' as resource; |
20 import 'package:analyzer/source/package_map_provider.dart'; | 19 import 'package:analyzer/source/package_map_provider.dart'; |
| 20 import 'package:analyzer/source/pub_package_map_provider.dart'; |
21 import 'package:analyzer/src/generated/element.dart'; | 21 import 'package:analyzer/src/generated/element.dart'; |
22 import 'package:analyzer/src/generated/engine.dart'; | 22 import 'package:analyzer/src/generated/engine.dart'; |
23 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
24 import 'package:typed_mock/typed_mock.dart'; | 24 import 'package:typed_mock/typed_mock.dart'; |
25 import 'package:unittest/unittest.dart'; | 25 import 'package:unittest/unittest.dart'; |
26 | 26 |
27 /** | 27 /** |
28 * Answer the absolute path the the SDK relative to the currently running | 28 * Answer the absolute path the the SDK relative to the currently running |
29 * script or throw an exception if it cannot be found. | 29 * script or throw an exception if it cannot be found. |
30 */ | 30 */ |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 class MockMethodElement extends StringTypedMock implements MethodElement { | 146 class MockMethodElement extends StringTypedMock implements MethodElement { |
147 final kind = ElementKind.METHOD; | 147 final kind = ElementKind.METHOD; |
148 MockMethodElement([String name = 'method']) : super(name); | 148 MockMethodElement([String name = 'method']) : super(name); |
149 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 149 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
150 } | 150 } |
151 | 151 |
152 /** | 152 /** |
153 * A mock [PackageMapProvider]. | 153 * A mock [PackageMapProvider]. |
154 */ | 154 */ |
155 class MockPackageMapProvider implements OptimizingPubPackageMapProvider { | 155 class MockPackageMapProvider implements PubPackageMapProvider { |
156 /** | 156 /** |
157 * Package map that will be returned by the next call to [computePackageMap]. | 157 * Package map that will be returned by the next call to [computePackageMap]. |
158 */ | 158 */ |
159 Map<String, List<resource.Folder>> packageMap = | 159 Map<String, List<resource.Folder>> packageMap = |
160 <String, List<resource.Folder>>{}; | 160 <String, List<resource.Folder>>{}; |
161 | 161 |
162 /** | 162 /** |
163 * Package maps that will be returned by the next call to [computePackageMap]. | 163 * Package maps that will be returned by the next call to [computePackageMap]. |
164 */ | 164 */ |
165 Map<String, Map<String, List<resource.Folder>>> packageMaps = null; | 165 Map<String, Map<String, List<resource.Folder>>> packageMaps = null; |
166 | 166 |
167 /** | 167 /** |
168 * Dependency list that will be returned by the next call to [computePackageMa
p]. | 168 * Dependency list that will be returned by the next call to [computePackageMa
p]. |
169 */ | 169 */ |
170 Set<String> dependencies = new Set<String>(); | 170 Set<String> dependencies = new Set<String>(); |
171 | 171 |
172 /** | 172 /** |
173 * Modification times that will be returned by the next call to | |
174 * [computePackageMap]. This will be filtered to include only those paths | |
175 * mentioned in the `dependencies` field of [computePackageMap]'s | |
176 * `previousInfo` argument. | |
177 */ | |
178 Map<String, int> modificationTimes = <String, int>{}; | |
179 | |
180 /** | |
181 * Number of times [computePackageMap] has been called. | 173 * Number of times [computePackageMap] has been called. |
182 */ | 174 */ |
183 int computeCount = 0; | 175 int computeCount = 0; |
184 | 176 |
185 @override | 177 @override |
186 OptimizingPubPackageMapInfo computePackageMap(resource.Folder folder, | 178 PackageMapInfo computePackageMap(resource.Folder folder) { |
187 [OptimizingPubPackageMapInfo previousInfo]) { | |
188 ++computeCount; | 179 ++computeCount; |
189 Map<String, int> filteredModificationTimes = <String, int>{}; | 180 if (packageMaps != null) { |
190 if (previousInfo != null) { | 181 return new PackageMapInfo(packageMaps[folder.path], dependencies); |
191 for (String dependency in previousInfo.dependencies) { | |
192 if (modificationTimes.containsKey(dependency)) { | |
193 filteredModificationTimes[dependency] = modificationTimes[dependency]; | |
194 } | |
195 } | |
196 } | 182 } |
197 if (packageMaps != null) { | 183 return new PackageMapInfo(packageMap, dependencies); |
198 return new OptimizingPubPackageMapInfo( | |
199 packageMaps[folder.path], dependencies, filteredModificationTimes); | |
200 } | |
201 return new OptimizingPubPackageMapInfo( | |
202 packageMap, dependencies, filteredModificationTimes); | |
203 } | 184 } |
204 | 185 |
205 noSuchMethod(Invocation invocation) { | 186 noSuchMethod(Invocation invocation) { |
206 // No other methods should be called. | 187 // No other methods should be called. |
207 return super.noSuchMethod(invocation); | 188 return super.noSuchMethod(invocation); |
208 } | 189 } |
209 } | 190 } |
210 | 191 |
211 class MockParameterElement extends TypedMock implements ParameterElement { | 192 class MockParameterElement extends TypedMock implements ParameterElement { |
212 final ElementKind kind = ElementKind.PARAMETER; | 193 final ElementKind kind = ElementKind.PARAMETER; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 } | 461 } |
481 return mismatchDescription; | 462 return mismatchDescription; |
482 } | 463 } |
483 | 464 |
484 @override | 465 @override |
485 bool matches(item, Map matchState) { | 466 bool matches(item, Map matchState) { |
486 Response response = item; | 467 Response response = item; |
487 return response != null && response.id == _id && response.error == null; | 468 return response != null && response.id == _id && response.error == null; |
488 } | 469 } |
489 } | 470 } |
OLD | NEW |