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 testing.mock_sdk; | 5 library testing.mock_sdk; |
6 | 6 |
7 import 'package:analyzer/file_system/file_system.dart' as resource; | 7 import 'package:analyzer/file_system/file_system.dart' as resource; |
8 import 'package:analyzer/file_system/memory_file_system.dart' as resource; | 8 import 'package:analyzer/file_system/memory_file_system.dart' as resource; |
9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
10 import 'package:analyzer/src/generated/sdk.dart'; | 10 import 'package:analyzer/src/generated/sdk.dart'; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 static const List<SdkLibrary> LIBRARIES = const [ | 104 static const List<SdkLibrary> LIBRARIES = const [ |
105 LIB_CORE, | 105 LIB_CORE, |
106 LIB_ASYNC, | 106 LIB_ASYNC, |
107 LIB_MATH, | 107 LIB_MATH, |
108 LIB_HTML,]; | 108 LIB_HTML,]; |
109 | 109 |
110 final resource.MemoryResourceProvider provider = | 110 final resource.MemoryResourceProvider provider = |
111 new resource.MemoryResourceProvider(); | 111 new resource.MemoryResourceProvider(); |
112 | 112 |
| 113 /** |
| 114 * The [AnalysisContext] which is used for all of the sources. |
| 115 */ |
| 116 InternalAnalysisContext _analysisContext; |
| 117 |
113 MockSdk() { | 118 MockSdk() { |
114 LIBRARIES.forEach((_MockSdkLibrary library) { | 119 LIBRARIES.forEach((_MockSdkLibrary library) { |
115 provider.newFile(library.path, library.content); | 120 provider.newFile(library.path, library.content); |
116 }); | 121 }); |
117 } | 122 } |
118 | 123 |
119 @override | 124 @override |
120 AnalysisContext get context => throw unimplemented; | 125 AnalysisContext get context { |
| 126 if (_analysisContext == null) { |
| 127 _analysisContext = new SdkAnalysisContext(); |
| 128 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); |
| 129 _analysisContext.sourceFactory = factory; |
| 130 ChangeSet changeSet = new ChangeSet(); |
| 131 for (String uri in uris) { |
| 132 Source source = factory.forUri(uri); |
| 133 changeSet.addedSource(source); |
| 134 } |
| 135 _analysisContext.applyChanges(changeSet); |
| 136 } |
| 137 return _analysisContext; |
| 138 } |
121 | 139 |
122 @override | 140 @override |
123 List<SdkLibrary> get sdkLibraries => LIBRARIES; | 141 List<SdkLibrary> get sdkLibraries => LIBRARIES; |
124 | 142 |
125 @override | 143 @override |
126 String get sdkVersion => throw unimplemented; | 144 String get sdkVersion => throw unimplemented; |
127 | 145 |
128 UnimplementedError get unimplemented => new UnimplementedError(); | 146 UnimplementedError get unimplemented => new UnimplementedError(); |
129 | 147 |
130 @override | 148 @override |
131 List<String> get uris => throw unimplemented; | 149 List<String> get uris { |
| 150 List<String> uris = <String>[]; |
| 151 for (SdkLibrary library in LIBRARIES) { |
| 152 uris.add(library.shortName); |
| 153 } |
| 154 return uris; |
| 155 } |
132 | 156 |
133 @override | 157 @override |
134 Source fromFileUri(Uri uri) { | 158 Source fromFileUri(Uri uri) { |
135 String filePath = uri.path; | 159 String filePath = uri.path; |
136 String libPath = '/lib'; | 160 String libPath = '/lib'; |
137 if (!filePath.startsWith("$libPath/")) { | 161 if (!filePath.startsWith("$libPath/")) { |
138 return null; | 162 return null; |
139 } | 163 } |
140 for (SdkLibrary library in LIBRARIES) { | 164 for (SdkLibrary library in LIBRARIES) { |
141 String libraryPath = library.path; | 165 String libraryPath = library.path; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 bool get isInternal => throw unimplemented; | 242 bool get isInternal => throw unimplemented; |
219 | 243 |
220 @override | 244 @override |
221 bool get isShared => throw unimplemented; | 245 bool get isShared => throw unimplemented; |
222 | 246 |
223 @override | 247 @override |
224 bool get isVmLibrary => throw unimplemented; | 248 bool get isVmLibrary => throw unimplemented; |
225 | 249 |
226 UnimplementedError get unimplemented => new UnimplementedError(); | 250 UnimplementedError get unimplemented => new UnimplementedError(); |
227 } | 251 } |
OLD | NEW |