| OLD | NEW |
| 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 Loading... |
| 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(appendSlash('$libraryRoot')); | 218 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot')); |
| 220 Uri packageUri = null; | 219 Uri packageUri = null; |
| 221 if (packageRoot != null) { | 220 if (packageRoot != null) { |
| 222 packageUri = cwd.resolve(appendSlash('$packageRoot')); | 221 packageUri = currentDirectory.resolve(appendSlash('$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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 * Analyzes set of libraries and provides a mirror system which can be used for | 274 * Analyzes set of libraries and provides a mirror system which can be used for |
| 276 * static inspection of the source code. | 275 * static inspection of the source code. |
| 277 */ | 276 */ |
| 278 // TODO(johnniwinther): Move dart:io dependent parts outside | 277 // TODO(johnniwinther): Move dart:io dependent parts outside |
| 279 // dart2js_mirror.dart. | 278 // dart2js_mirror.dart. |
| 280 Future<MirrorSystem> analyze(List<Path> libraries, | 279 Future<MirrorSystem> analyze(List<Path> libraries, |
| 281 Path libraryRoot, | 280 Path libraryRoot, |
| 282 {Path packageRoot, | 281 {Path packageRoot, |
| 283 List<String> options: const <String>[], | 282 List<String> options: const <String>[], |
| 284 api.DiagnosticHandler diagnosticHandler}) { | 283 api.DiagnosticHandler diagnosticHandler}) { |
| 285 Uri cwd = getCurrentDirectory(); | |
| 286 SourceFileProvider provider = new SourceFileProvider(); | 284 SourceFileProvider provider = new SourceFileProvider(); |
| 287 if (diagnosticHandler == null) { | 285 if (diagnosticHandler == null) { |
| 288 diagnosticHandler = | 286 diagnosticHandler = |
| 289 new FormattingDiagnosticHandler(provider).diagnosticHandler; | 287 new FormattingDiagnosticHandler(provider).diagnosticHandler; |
| 290 } | 288 } |
| 291 Uri libraryUri = cwd.resolve(appendSlash('$libraryRoot')); | 289 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot')); |
| 292 Uri packageUri = null; | 290 Uri packageUri = null; |
| 293 if (packageRoot != null) { | 291 if (packageRoot != null) { |
| 294 packageUri = cwd.resolve(appendSlash('$packageRoot')); | 292 packageUri = currentDirectory.resolve(appendSlash('$packageRoot')); |
| 295 } | 293 } |
| 296 List<Uri> librariesUri = <Uri>[]; | 294 List<Uri> librariesUri = <Uri>[]; |
| 297 for (Path library in libraries) { | 295 for (Path library in libraries) { |
| 298 librariesUri.add(cwd.resolve(library.toString())); | 296 librariesUri.add(currentDirectory.resolve(library.toString())); |
| 299 } | 297 } |
| 300 return analyzeUri(librariesUri, libraryUri, packageUri, | 298 return analyzeUri(librariesUri, libraryUri, packageUri, |
| 301 provider.readStringFromUri, diagnosticHandler, options); | 299 provider.readStringFromUri, diagnosticHandler, options); |
| 302 } | 300 } |
| 303 | 301 |
| 304 //------------------------------------------------------------------------------ | 302 //------------------------------------------------------------------------------ |
| 305 // Dart2Js specific extensions of mirror interfaces | 303 // Dart2Js specific extensions of mirror interfaces |
| 306 //------------------------------------------------------------------------------ | 304 //------------------------------------------------------------------------------ |
| 307 | 305 |
| 308 abstract class Dart2JsMirror implements Mirror { | 306 abstract class Dart2JsMirror implements Mirror { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 456 |
| 459 bool get isStatic => false; | 457 bool get isStatic => false; |
| 460 | 458 |
| 461 bool get isParameter => false; | 459 bool get isParameter => false; |
| 462 } | 460 } |
| 463 | 461 |
| 464 //------------------------------------------------------------------------------ | 462 //------------------------------------------------------------------------------ |
| 465 // Mirror system implementation. | 463 // Mirror system implementation. |
| 466 //------------------------------------------------------------------------------ | 464 //------------------------------------------------------------------------------ |
| 467 | 465 |
| 468 class Dart2JsMirrorSystem implements MirrorSystem { | 466 class Dart2JsMirrorSystem extends MirrorSystem { |
| 469 final Compiler compiler; | 467 final Compiler compiler; |
| 470 Map<String, Dart2JsLibraryMirror> _libraries; | 468 Map<Uri, Dart2JsLibraryMirror> _libraries; |
| 471 Map<LibraryElement, Dart2JsLibraryMirror> _libraryMap; | 469 Map<LibraryElement, Dart2JsLibraryMirror> _libraryMap; |
| 472 | 470 |
| 473 Dart2JsMirrorSystem(this.compiler) | 471 Dart2JsMirrorSystem(this.compiler) |
| 474 : _libraryMap = new Map<LibraryElement, Dart2JsLibraryMirror>(); | 472 : _libraryMap = new Map<LibraryElement, Dart2JsLibraryMirror>(); |
| 475 | 473 |
| 476 void _ensureLibraries() { | 474 void _ensureLibraries() { |
| 477 if (_libraries == null) { | 475 if (_libraries == null) { |
| 478 _libraries = <String, Dart2JsLibraryMirror>{}; | 476 _libraries = new Map<Uri, Dart2JsLibraryMirror>(); |
| 479 compiler.libraries.forEach((_, LibraryElement v) { | 477 compiler.libraries.forEach((_, LibraryElement v) { |
| 480 var mirror = new Dart2JsLibraryMirror(mirrors, v); | 478 var mirror = new Dart2JsLibraryMirror(mirrors, v); |
| 481 _libraries[mirror.simpleName] = mirror; | 479 _libraries[mirror.uri] = mirror; |
| 482 _libraryMap[v] = mirror; | 480 _libraryMap[v] = mirror; |
| 483 }); | 481 }); |
| 484 } | 482 } |
| 485 } | 483 } |
| 486 | 484 |
| 487 Map<String, LibraryMirror> get libraries { | 485 Map<Uri, LibraryMirror> get libraries { |
| 488 _ensureLibraries(); | 486 _ensureLibraries(); |
| 489 return new ImmutableMapWrapper<String, LibraryMirror>(_libraries); | 487 return new ImmutableMapWrapper<Uri, LibraryMirror>(_libraries); |
| 490 } | 488 } |
| 491 | 489 |
| 492 Dart2JsLibraryMirror _getLibrary(LibraryElement element) => | 490 Dart2JsLibraryMirror _getLibrary(LibraryElement element) => |
| 493 _libraryMap[element]; | 491 _libraryMap[element]; |
| 494 | 492 |
| 495 Dart2JsMirrorSystem get mirrors => this; | 493 Dart2JsMirrorSystem get mirrors => this; |
| 496 | 494 |
| 497 TypeMirror get dynamicType => | 495 TypeMirror get dynamicType => |
| 498 _convertTypeToTypeMirror(this, compiler.types.dynamicType, null); | 496 _convertTypeToTypeMirror(this, compiler.types.dynamicType, null); |
| 499 | 497 |
| (...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1749 return new Future.value( | 1747 return new Future.value( |
| 1750 new Dart2JsStringConstantMirror.fromString(mirrors, text)); | 1748 new Dart2JsStringConstantMirror.fromString(mirrors, text)); |
| 1751 } else if (fieldName == 'trimmedText') { | 1749 } else if (fieldName == 'trimmedText') { |
| 1752 return new Future.value( | 1750 return new Future.value( |
| 1753 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText)); | 1751 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText)); |
| 1754 } | 1752 } |
| 1755 // TODO(johnniwinther): Which exception/error should be thrown here? | 1753 // TODO(johnniwinther): Which exception/error should be thrown here? |
| 1756 throw new UnsupportedError('InstanceMirror does not have a reflectee'); | 1754 throw new UnsupportedError('InstanceMirror does not have a reflectee'); |
| 1757 } | 1755 } |
| 1758 } | 1756 } |
| OLD | NEW |