Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(906)

Side by Side Diff: pkg/code_transformers/lib/src/dart_sdk.dart

Issue 311403003: Fix bug in code_transformers. Apparently mock SDK needs to have a source factory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/code_transformers/lib/src/resolvers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 code_transformers.src.dart_sdk; 5 library code_transformers.src.dart_sdk;
6 6
7 import 'dart:convert' as convert; 7 import 'dart:convert' as convert;
8 import 'dart:io' show File, Platform, Process; 8 import 'dart:io' show File, Platform, Process;
9 import 'package:path/path.dart' as path; 9 import 'package:path/path.dart' as path;
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 /// Dart SDK which contains a mock implementation of the SDK libraries. May be 140 /// Dart SDK which contains a mock implementation of the SDK libraries. May be
141 /// used to speed up resultion when most of the core libraries is not needed. 141 /// used to speed up resultion when most of the core libraries is not needed.
142 class MockDartSdk implements DartSdk { 142 class MockDartSdk implements DartSdk {
143 final Map<Uri, _MockSdkSource> _sources = {}; 143 final Map<Uri, _MockSdkSource> _sources = {};
144 final bool reportMissing; 144 final bool reportMissing;
145 final Map<String, SdkLibrary> _libs = {}; 145 final Map<String, SdkLibrary> _libs = {};
146 final String sdkVersion = '0'; 146 final String sdkVersion = '0';
147 List<String> get uris => _sources.keys.map((uri) => '$uri').toList(); 147 List<String> get uris => _sources.keys.map((uri) => '$uri').toList();
148 final AnalysisContext context = new _SdkAnalysisContext(); 148 final AnalysisContext context = new _SdkAnalysisContext();
149 DartUriResolver _resolver;
150 DartUriResolver get resolver => _resolver;
149 151
150 MockDartSdk(Map<String, String> sources, {this.reportMissing}) { 152 MockDartSdk(Map<String, String> sources, {this.reportMissing}) {
151 sources.forEach((uriString, contents) { 153 sources.forEach((uriString, contents) {
152 var uri = Uri.parse(uriString); 154 var uri = Uri.parse(uriString);
153 _sources[uri] = new _MockSdkSource(uri, contents); 155 _sources[uri] = new _MockSdkSource(uri, contents);
154 _libs[uriString] = new SdkLibraryImpl(uri.path) 156 _libs[uriString] = new SdkLibraryImpl(uri.path)
155 ..setDart2JsLibrary() 157 ..setDart2JsLibrary()
156 ..setVmLibrary(); 158 ..setVmLibrary();
157 }); 159 });
160 _resolver = new DartUriResolver(this);
161 context.sourceFactory = new SourceFactory([_resolver]);
158 } 162 }
159 163
160 List<SdkLibrary> get sdkLibraries => _libs.values.toList(); 164 List<SdkLibrary> get sdkLibraries => _libs.values.toList();
161 SdkLibrary getSdkLibrary(String dartUri) => _libs[dartUri]; 165 SdkLibrary getSdkLibrary(String dartUri) => _libs[dartUri];
162 Source mapDartUri(String dartUri) => _getSource(Uri.parse(dartUri)); 166 Source mapDartUri(String dartUri) => _getSource(Uri.parse(dartUri));
163 167
164 Source fromEncoding(UriKind kind, Uri uri) { 168 Source fromEncoding(UriKind kind, Uri uri) {
165 if (kind != UriKind.DART_URI) { 169 if (kind != UriKind.DART_URI) {
166 throw new UnsupportedError('expected dart: uri kind, got $kind.'); 170 throw new UnsupportedError('expected dart: uri kind, got $kind.');
167 } 171 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 class _SdkAnalysisContext extends AnalysisContextImpl { 220 class _SdkAnalysisContext extends AnalysisContextImpl {
217 @override 221 @override
218 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { 222 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) {
219 if (factory == null) return super.createCacheFromSourceFactory(factory); 223 if (factory == null) return super.createCacheFromSourceFactory(factory);
220 var sdk = factory.dartSdk; 224 var sdk = factory.dartSdk;
221 if (sdk == null) throw "Missing a DartUriResolver in source factory"; 225 if (sdk == null) throw "Missing a DartUriResolver in source factory";
222 return new AnalysisCache( 226 return new AnalysisCache(
223 [AnalysisEngine.instance.partitionManager.forSdk(sdk)]); 227 [AnalysisEngine.instance.partitionManager.forSdk(sdk)]);
224 } 228 }
225 } 229 }
OLDNEW
« no previous file with comments | « no previous file | pkg/code_transformers/lib/src/resolvers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698