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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart

Issue 13797002: Change MirrorSystem.libraries to Map<Uri, String> (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 mirrors_dart2js; 5 library mirrors_dart2js;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection' show LinkedHashMap; 8 import 'dart:collection' show LinkedHashMap;
9 import 'dart:io' show Path; 9 import 'dart:io' show Path;
10 import 'dart:uri'; 10 import 'dart:uri';
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 * has been successfully compiled. 202 * has been successfully compiled.
203 * 203 *
204 * TODO(johnniwinther): The method is deprecated but here to support [Path] 204 * TODO(johnniwinther): The method is deprecated but here to support [Path]
205 * which is used through dartdoc. 205 * which is used through dartdoc.
206 */ 206 */
207 Future<String> compile(Path script, 207 Future<String> compile(Path script,
208 Path libraryRoot, 208 Path libraryRoot,
209 {Path packageRoot, 209 {Path packageRoot,
210 List<String> options: const <String>[], 210 List<String> options: const <String>[],
211 api.DiagnosticHandler diagnosticHandler}) { 211 api.DiagnosticHandler diagnosticHandler}) {
212 Uri cwd = getCurrentDirectory();
213 SourceFileProvider provider = new SourceFileProvider(); 212 SourceFileProvider provider = new SourceFileProvider();
214 if (diagnosticHandler == null) { 213 if (diagnosticHandler == null) {
215 diagnosticHandler = 214 diagnosticHandler =
216 new FormattingDiagnosticHandler(provider).diagnosticHandler; 215 new FormattingDiagnosticHandler(provider).diagnosticHandler;
217 } 216 }
218 Uri scriptUri = cwd.resolve(script.toString()); 217 Uri scriptUri = currentDirectory.resolve(script.toString());
219 Uri libraryUri = cwd.resolve('${libraryRoot}/'); 218 Uri libraryUri = currentDirectory.resolve('${libraryRoot}/');
220 Uri packageUri = null; 219 Uri packageUri = null;
221 if (packageRoot != null) { 220 if (packageRoot != null) {
222 packageUri = cwd.resolve('${packageRoot}/'); 221 packageUri = currentDirectory.resolve('${packageRoot}/');
223 } 222 }
224 return api.compile(scriptUri, libraryUri, packageUri, 223 return api.compile(scriptUri, libraryUri, packageUri,
225 provider.readStringFromUri, diagnosticHandler, options); 224 provider.readStringFromUri, diagnosticHandler, options);
226 } 225 }
227 226
228 /** 227 /**
229 * Analyzes set of libraries and provides a mirror system which can be used for 228 * Analyzes set of libraries and provides a mirror system which can be used for
230 * static inspection of the source code. 229 * static inspection of the source code.
231 */ 230 */
232 // TODO(johnniwinther): Move this to [compiler/compiler.dart] and rename to 231 // TODO(johnniwinther): Move this to [compiler/compiler.dart] and rename to
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 * Analyzes set of libraries and provides a mirror system which can be used for 276 * Analyzes set of libraries and provides a mirror system which can be used for
278 * static inspection of the source code. 277 * static inspection of the source code.
279 */ 278 */
280 // TODO(johnniwinther): Move dart:io dependent parts outside 279 // TODO(johnniwinther): Move dart:io dependent parts outside
281 // dart2js_mirror.dart. 280 // dart2js_mirror.dart.
282 Future<MirrorSystem> analyze(List<Path> libraries, 281 Future<MirrorSystem> analyze(List<Path> libraries,
283 Path libraryRoot, 282 Path libraryRoot,
284 {Path packageRoot, 283 {Path packageRoot,
285 List<String> options: const <String>[], 284 List<String> options: const <String>[],
286 api.DiagnosticHandler diagnosticHandler}) { 285 api.DiagnosticHandler diagnosticHandler}) {
287 Uri cwd = getCurrentDirectory();
288 SourceFileProvider provider = new SourceFileProvider(); 286 SourceFileProvider provider = new SourceFileProvider();
289 if (diagnosticHandler == null) { 287 if (diagnosticHandler == null) {
290 diagnosticHandler = 288 diagnosticHandler =
291 new FormattingDiagnosticHandler(provider).diagnosticHandler; 289 new FormattingDiagnosticHandler(provider).diagnosticHandler;
292 } 290 }
293 Uri libraryUri = cwd.resolve('${libraryRoot}/'); 291 Uri libraryUri = currentDirectory.resolve('${libraryRoot}/');
294 Uri packageUri = null; 292 Uri packageUri = null;
295 if (packageRoot != null) { 293 if (packageRoot != null) {
296 packageUri = cwd.resolve('${packageRoot}/'); 294 packageUri = currentDirectory.resolve('${packageRoot}/');
297 } 295 }
298 List<Uri> librariesUri = <Uri>[]; 296 List<Uri> librariesUri = <Uri>[];
299 for (Path library in libraries) { 297 for (Path library in libraries) {
300 librariesUri.add(cwd.resolve(library.toString())); 298 librariesUri.add(currentDirectory.resolve(library.toString()));
301 } 299 }
302 return analyzeUri(librariesUri, libraryUri, packageUri, 300 return analyzeUri(librariesUri, libraryUri, packageUri,
303 provider.readStringFromUri, diagnosticHandler, options); 301 provider.readStringFromUri, diagnosticHandler, options);
304 } 302 }
305 303
306 //------------------------------------------------------------------------------ 304 //------------------------------------------------------------------------------
307 // Dart2Js specific extensions of mirror interfaces 305 // Dart2Js specific extensions of mirror interfaces
308 //------------------------------------------------------------------------------ 306 //------------------------------------------------------------------------------
309 307
310 abstract class Dart2JsMirror implements Mirror { 308 abstract class Dart2JsMirror implements Mirror {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 460
463 bool get isParameter => false; 461 bool get isParameter => false;
464 } 462 }
465 463
466 //------------------------------------------------------------------------------ 464 //------------------------------------------------------------------------------
467 // Mirror system implementation. 465 // Mirror system implementation.
468 //------------------------------------------------------------------------------ 466 //------------------------------------------------------------------------------
469 467
470 class Dart2JsMirrorSystem implements MirrorSystem { 468 class Dart2JsMirrorSystem implements MirrorSystem {
471 final Compiler compiler; 469 final Compiler compiler;
472 Map<String, Dart2JsLibraryMirror> _libraries; 470 Map<Uri, Dart2JsLibraryMirror> _libraries;
473 Map<LibraryElement, Dart2JsLibraryMirror> _libraryMap; 471 Map<LibraryElement, Dart2JsLibraryMirror> _libraryMap;
474 472
475 Dart2JsMirrorSystem(this.compiler) 473 Dart2JsMirrorSystem(this.compiler)
476 : _libraryMap = new Map<LibraryElement, Dart2JsLibraryMirror>(); 474 : _libraryMap = new Map<LibraryElement, Dart2JsLibraryMirror>();
477 475
478 void _ensureLibraries() { 476 void _ensureLibraries() {
479 if (_libraries == null) { 477 if (_libraries == null) {
480 _libraries = <String, Dart2JsLibraryMirror>{}; 478 _libraries = new Map<Uri, Dart2JsLibraryMirror>();
481 compiler.libraries.forEach((_, LibraryElement v) { 479 compiler.libraries.forEach((_, LibraryElement v) {
482 var mirror = new Dart2JsLibraryMirror(mirrors, v); 480 var mirror = new Dart2JsLibraryMirror(mirrors, v);
483 _libraries[mirror.simpleName] = mirror; 481 _libraries[mirror.uri] = mirror;
484 _libraryMap[v] = mirror; 482 _libraryMap[v] = mirror;
485 }); 483 });
486 } 484 }
487 } 485 }
488 486
489 Map<String, LibraryMirror> get libraries { 487 Map<Uri, LibraryMirror> get libraries {
490 _ensureLibraries(); 488 _ensureLibraries();
491 return new ImmutableMapWrapper<String, LibraryMirror>(_libraries); 489 return new ImmutableMapWrapper<Uri, LibraryMirror>(_libraries);
492 } 490 }
493 491
494 Dart2JsLibraryMirror _getLibrary(LibraryElement element) => 492 Dart2JsLibraryMirror _getLibrary(LibraryElement element) =>
495 _libraryMap[element]; 493 _libraryMap[element];
496 494
497 Dart2JsMirrorSystem get mirrors => this; 495 Dart2JsMirrorSystem get mirrors => this;
498 496
499 TypeMirror get dynamicType => 497 TypeMirror get dynamicType =>
500 _convertTypeToTypeMirror(this, compiler.types.dynamicType, null); 498 _convertTypeToTypeMirror(this, compiler.types.dynamicType, null);
501 499
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 return new Future.immediate( 1749 return new Future.immediate(
1752 new Dart2JsStringConstantMirror.fromString(mirrors, text)); 1750 new Dart2JsStringConstantMirror.fromString(mirrors, text));
1753 } else if (fieldName == 'trimmedText') { 1751 } else if (fieldName == 'trimmedText') {
1754 return new Future.immediate( 1752 return new Future.immediate(
1755 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText)); 1753 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText));
1756 } 1754 }
1757 // TODO(johnniwinther): Which exception/error should be thrown here? 1755 // TODO(johnniwinther): Which exception/error should be thrown here?
1758 throw new UnsupportedError('InstanceMirror does not have a reflectee'); 1756 throw new UnsupportedError('InstanceMirror does not have a reflectee');
1759 } 1757 }
1760 } 1758 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698