| 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 @MirrorsUsed(targets: 'mocks', override: '*') | 7 @MirrorsUsed(targets: 'mocks', override: '*') |
| 8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:io'; | 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'; |
| 17 import 'package:analyzer/file_system/file_system.dart' as resource; | 18 import 'package:analyzer/file_system/file_system.dart' as resource; |
| 18 import 'package:analyzer/file_system/memory_file_system.dart' as resource; | 19 import 'package:analyzer/file_system/memory_file_system.dart' as resource; |
| 19 import 'package:analyzer/source/package_map_provider.dart'; | 20 import 'package:analyzer/source/package_map_provider.dart'; |
| 20 import 'package:analyzer/src/generated/element.dart'; | 21 import 'package:analyzer/src/generated/element.dart'; |
| 21 import 'package:analyzer/src/generated/engine.dart'; | 22 import 'package:analyzer/src/generated/engine.dart'; |
| 22 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
| 23 import 'package:matcher/matcher.dart'; | 24 import 'package:matcher/matcher.dart'; |
| 24 import 'package:typed_mock/typed_mock.dart'; | 25 import 'package:typed_mock/typed_mock.dart'; |
| 25 import 'package:unittest/unittest.dart'; | 26 import 'package:unittest/unittest.dart'; |
| 26 | 27 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 146 |
| 146 class MockMethodElement extends StringTypedMock implements MethodElement { | 147 class MockMethodElement extends StringTypedMock implements MethodElement { |
| 147 final kind = ElementKind.METHOD; | 148 final kind = ElementKind.METHOD; |
| 148 MockMethodElement([String name = 'method']) : super(name); | 149 MockMethodElement([String name = 'method']) : super(name); |
| 149 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 150 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 150 } | 151 } |
| 151 | 152 |
| 152 /** | 153 /** |
| 153 * A mock [PackageMapProvider]. | 154 * A mock [PackageMapProvider]. |
| 154 */ | 155 */ |
| 155 class MockPackageMapProvider implements PackageMapProvider { | 156 class MockPackageMapProvider implements OptimizingPubPackageMapProvider { |
| 156 /** | 157 /** |
| 157 * Package map that will be returned by the next call to [computePackageMap]. | 158 * Package map that will be returned by the next call to [computePackageMap]. |
| 158 */ | 159 */ |
| 159 Map<String, List<resource.Folder>> packageMap = | 160 Map<String, List<resource.Folder>> packageMap = |
| 160 <String, List<resource.Folder>>{}; | 161 <String, List<resource.Folder>>{}; |
| 161 | 162 |
| 162 /** | 163 /** |
| 163 * Package maps that will be returned by the next call to [computePackageMap]. | 164 * Package maps that will be returned by the next call to [computePackageMap]. |
| 164 */ | 165 */ |
| 165 Map<String, Map<String, List<resource.Folder>>> packageMaps = null; | 166 Map<String, Map<String, List<resource.Folder>>> packageMaps = null; |
| 166 | 167 |
| 167 /** | 168 /** |
| 168 * Dependency list that will be returned by the next call to [computePackageMa
p]. | 169 * Dependency list that will be returned by the next call to [computePackageMa
p]. |
| 169 */ | 170 */ |
| 170 Set<String> dependencies = new Set<String>(); | 171 Set<String> dependencies = new Set<String>(); |
| 171 | 172 |
| 173 /** |
| 174 * Modification times that will be returned by the next call to |
| 175 * [computePackageMap]. This will be filtered to include only those paths |
| 176 * mentioned in the `dependencies` field of [computePackageMap]'s |
| 177 * `previousInfo` argument. |
| 178 */ |
| 179 Map<String, int> modificationTimes = <String, int>{}; |
| 180 |
| 181 /** |
| 182 * Number of times [computePackageMap] has been called. |
| 183 */ |
| 184 int computeCount = 0; |
| 185 |
| 172 @override | 186 @override |
| 173 PackageMapInfo computePackageMap(resource.Folder folder) { | 187 OptimizingPubPackageMapInfo computePackageMap(resource.Folder folder, |
| 188 [OptimizingPubPackageMapInfo previousInfo]) { |
| 189 ++computeCount; |
| 190 Map<String, int> filteredModificationTimes = <String, int>{}; |
| 191 if (previousInfo != null) { |
| 192 for (String dependency in previousInfo.dependencies) { |
| 193 if (modificationTimes.containsKey(dependency)) { |
| 194 filteredModificationTimes[dependency] = modificationTimes[dependency]; |
| 195 } |
| 196 } |
| 197 } |
| 174 if (packageMaps != null) { | 198 if (packageMaps != null) { |
| 175 return new PackageMapInfo(packageMaps[folder.path], dependencies); | 199 return new OptimizingPubPackageMapInfo( |
| 200 packageMaps[folder.path], dependencies, filteredModificationTimes); |
| 176 } | 201 } |
| 177 return new PackageMapInfo(packageMap, dependencies); | 202 return new OptimizingPubPackageMapInfo( |
| 203 packageMap, dependencies, filteredModificationTimes); |
| 204 } |
| 205 |
| 206 noSuchMethod(Invocation invocation) { |
| 207 // No other methods should be called. |
| 208 return super.noSuchMethod(invocation); |
| 178 } | 209 } |
| 179 } | 210 } |
| 180 | 211 |
| 181 class MockParameterElement extends TypedMock implements ParameterElement { | 212 class MockParameterElement extends TypedMock implements ParameterElement { |
| 182 final ElementKind kind = ElementKind.PARAMETER; | 213 final ElementKind kind = ElementKind.PARAMETER; |
| 183 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 214 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 184 } | 215 } |
| 185 | 216 |
| 186 class MockPropertyAccessorElement extends TypedMock | 217 class MockPropertyAccessorElement extends TypedMock |
| 187 implements PropertyAccessorElement { | 218 implements PropertyAccessorElement { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 } | 481 } |
| 451 return mismatchDescription; | 482 return mismatchDescription; |
| 452 } | 483 } |
| 453 | 484 |
| 454 @override | 485 @override |
| 455 bool matches(item, Map matchState) { | 486 bool matches(item, Map matchState) { |
| 456 Response response = item; | 487 Response response = item; |
| 457 return response != null && response.id == _id && response.error == null; | 488 return response != null && response.id == _id && response.error == null; |
| 458 } | 489 } |
| 459 } | 490 } |
| OLD | NEW |