| 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 // VM-specific implementation of the dart:mirrors library. | 5 // VM-specific implementation of the dart:mirrors library. |
| 6 | 6 |
| 7 // These values are allowed to be passed directly over the wire. | 7 // These values are allowed to be passed directly over the wire. |
| 8 bool isSimpleValue(var value) { | 8 bool isSimpleValue(var value) { |
| 9 return (value === null || value is num || value is String || value is bool); | 9 return (value === null || value is num || value is String || value is bool); |
| 10 } | 10 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 TypeMirror get voidType() { | 41 TypeMirror get voidType() { |
| 42 if (_voidType === null) { | 42 if (_voidType === null) { |
| 43 _voidType = | 43 _voidType = |
| 44 new _LocalClassMirrorImpl( | 44 new _LocalClassMirrorImpl( |
| 45 null, 'void', false, null, null, [], null, const {}); | 45 null, 'void', false, null, null, [], null, const {}); |
| 46 } | 46 } |
| 47 return _voidType; | 47 return _voidType; |
| 48 } | 48 } |
| 49 | 49 |
| 50 String toString() { | 50 String toString() => "MirrorSystem for isolate '$debugName'"; |
| 51 return "MirrorSystem for isolate '$debugName'"; | |
| 52 } | |
| 53 } | 51 } |
| 54 | 52 |
| 55 abstract class _LocalMirrorImpl implements Mirror { | 53 abstract class _LocalMirrorImpl implements Mirror { |
| 56 int hashCode() { | 54 int hashCode() { |
| 57 throw new NotImplementedException('Mirror.hashCode() not yet implemented'); | 55 throw new NotImplementedException('Mirror.hashCode() not yet implemented'); |
| 58 } | 56 } |
| 59 | 57 |
| 60 // Local mirrors always return the same MirrorSystem. This field | 58 // Local mirrors always return the same MirrorSystem. This field |
| 61 // is more interesting once we implement remote mirrors. | 59 // is more interesting once we implement remote mirrors. |
| 62 MirrorSystem get mirrors() { return _Mirrors.currentMirrorSystem(); } | 60 MirrorSystem get mirrors() => _Mirrors.currentMirrorSystem(); |
| 63 } | 61 } |
| 64 | 62 |
| 65 class _LocalIsolateMirrorImpl extends _LocalMirrorImpl | 63 class _LocalIsolateMirrorImpl extends _LocalMirrorImpl |
| 66 implements IsolateMirror { | 64 implements IsolateMirror { |
| 67 _LocalIsolateMirrorImpl(this.debugName, this._rootLibrary) {} | 65 _LocalIsolateMirrorImpl(this.debugName, this._rootLibrary) {} |
| 68 | 66 |
| 69 final String debugName; | 67 final String debugName; |
| 70 final bool isCurrent = true; | 68 final bool isCurrent = true; |
| 71 | 69 |
| 72 var _rootLibrary; | 70 var _rootLibrary; |
| 73 LibraryMirror get rootLibrary() { | 71 LibraryMirror get rootLibrary() { |
| 74 if (_rootLibrary is _LazyLibraryMirror) { | 72 if (_rootLibrary is _LazyLibraryMirror) { |
| 75 _rootLibrary = _rootLibrary.resolve(mirrors); | 73 _rootLibrary = _rootLibrary.resolve(mirrors); |
| 76 } | 74 } |
| 77 return _rootLibrary; | 75 return _rootLibrary; |
| 78 } | 76 } |
| 79 | 77 |
| 80 String toString() { | 78 String toString() => "IsolateMirror on '$debugName'"; |
| 81 return "IsolateMirror on '$debugName'"; | |
| 82 } | |
| 83 } | 79 } |
| 84 | 80 |
| 85 // A VMReference is used to hold a reference to a VM-internal object, | 81 // A VMReference is used to hold a reference to a VM-internal object, |
| 86 // which can include things like libraries, classes, etc. | 82 // which can include things like libraries, classes, etc. |
| 87 class VMReference extends NativeFieldWrapperClass1 { | 83 class VMReference extends NativeFieldWrapperClass1 { |
| 88 } | 84 } |
| 89 | 85 |
| 90 abstract class _LocalVMObjectMirrorImpl extends _LocalMirrorImpl { | 86 abstract class _LocalVMObjectMirrorImpl extends _LocalMirrorImpl { |
| 91 _LocalVMObjectMirrorImpl(this._reference) {} | 87 _LocalVMObjectMirrorImpl(this._reference) {} |
| 92 | 88 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 static _getField(ref, fieldName) | 161 static _getField(ref, fieldName) |
| 166 native 'LocalObjectMirrorImpl_getField'; | 162 native 'LocalObjectMirrorImpl_getField'; |
| 167 | 163 |
| 168 static _setField(ref, fieldName, value) | 164 static _setField(ref, fieldName, value) |
| 169 native 'LocalObjectMirrorImpl_setField'; | 165 native 'LocalObjectMirrorImpl_setField'; |
| 170 } | 166 } |
| 171 | 167 |
| 172 // Prints a string as it might appear in dart program text. | 168 // Prints a string as it might appear in dart program text. |
| 173 // TODO(turnidge): Consider truncating. | 169 // TODO(turnidge): Consider truncating. |
| 174 String _dartEscape(String str) { | 170 String _dartEscape(String str) { |
| 175 bool isNice(int code) { | 171 bool isNice(int code) => (code >= 32 && code <= 126); |
| 176 return (code >= 32 && code <= 126); | |
| 177 } | |
| 178 | 172 |
| 179 StringBuffer buf = new StringBuffer(); | 173 StringBuffer buf = new StringBuffer(); |
| 180 for (int i = 0; i < str.length; i++) { | 174 for (int i = 0; i < str.length; i++) { |
| 181 var input = str[i]; | 175 var input = str[i]; |
| 182 String output; | 176 String output; |
| 183 switch (input) { | 177 switch (input) { |
| 184 case '\\' : | 178 case '\\' : |
| 185 output = @'\\'; | 179 output = @'\\'; |
| 186 break; | 180 break; |
| 187 case "\'" : | 181 case "\'" : |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 248 |
| 255 class _LocalClosureMirrorImpl extends _LocalInstanceMirrorImpl | 249 class _LocalClosureMirrorImpl extends _LocalInstanceMirrorImpl |
| 256 implements ClosureMirror { | 250 implements ClosureMirror { |
| 257 _LocalClosureMirrorImpl(ref, | 251 _LocalClosureMirrorImpl(ref, |
| 258 klass, | 252 klass, |
| 259 reflectee) : super(ref, klass, reflectee) {} | 253 reflectee) : super(ref, klass, reflectee) {} |
| 260 | 254 |
| 261 MethodMirror _function; | 255 MethodMirror _function; |
| 262 MethodMirror function() => _function; | 256 MethodMirror function() => _function; |
| 263 | 257 |
| 264 String source() { | 258 String get source() { |
| 265 throw new NotImplementedException('ClosureMirror.source() not implemented'); | 259 throw new NotImplementedException('ClosureMirror.source not implemented'); |
| 266 } | 260 } |
| 267 | 261 |
| 268 Future<ObjectMirror> apply(List<Object> positionalArguments, | 262 Future<ObjectMirror> apply(List<Object> positionalArguments, |
| 269 [Map<String,Object> namedArguments]) { | 263 [Map<String,Object> namedArguments]) { |
| 270 if (namedArguments !== null) { | 264 if (namedArguments !== null) { |
| 271 throw new NotImplementedException('named arguments not implemented'); | 265 throw new NotImplementedException('named arguments not implemented'); |
| 272 } | 266 } |
| 273 // Walk the arguments and make sure they are legal. | 267 // Walk the arguments and make sure they are legal. |
| 274 for (int i = 0; i < positionalArguments.length; i++) { | 268 for (int i = 0; i < positionalArguments.length; i++) { |
| 275 var arg = positionalArguments[i]; | 269 var arg = positionalArguments[i]; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 307 |
| 314 final String libraryName; | 308 final String libraryName; |
| 315 final String interfaceName; | 309 final String interfaceName; |
| 316 } | 310 } |
| 317 | 311 |
| 318 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl | 312 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl |
| 319 implements ClassMirror { | 313 implements ClassMirror { |
| 320 _LocalClassMirrorImpl(ref, | 314 _LocalClassMirrorImpl(ref, |
| 321 this.simpleName, | 315 this.simpleName, |
| 322 this.isClass, | 316 this.isClass, |
| 323 this._library, | 317 this._owner, |
| 324 this._superclass, | 318 this._superclass, |
| 325 this._superinterfaces, | 319 this._superinterfaces, |
| 326 this._defaultFactory, | 320 this._defaultFactory, |
| 327 this.members) : super(ref) {} | 321 this.members) : super(ref) {} |
| 328 | 322 |
| 329 final String simpleName; | 323 final String simpleName; |
| 324 |
| 325 String _qualifiedName = null; |
| 326 String get qualifiedName() { |
| 327 if (_qualifiedName === null) { |
| 328 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; |
| 329 } |
| 330 return _qualifiedName; |
| 331 } |
| 332 |
| 333 var _owner; |
| 334 DeclarationMirror get owner() { |
| 335 if (_owner is! Mirror) { |
| 336 _owner = _owner.resolve(mirrors); |
| 337 } |
| 338 return _owner; |
| 339 } |
| 340 |
| 341 bool get isPrivate() => simpleName.startsWith('_'); |
| 342 |
| 343 final bool isTopLevel = true; |
| 344 |
| 345 SourceLocation get location() { |
| 346 throw new NotImplementedException( |
| 347 'ClassMirror.location not yet implemented'); |
| 348 } |
| 349 |
| 330 final bool isClass; | 350 final bool isClass; |
| 331 | 351 |
| 332 var _library; | |
| 333 LibraryMirror get library() { | |
| 334 if (_library is _LazyLibraryMirror) { | |
| 335 _library = _library.resolve(mirrors); | |
| 336 } | |
| 337 return _library; | |
| 338 } | |
| 339 | |
| 340 var _superclass; | 352 var _superclass; |
| 341 ClassMirror get superclass() { | 353 ClassMirror get superclass() { |
| 342 if (_superclass is _LazyClassMirror) { | 354 if (_superclass is _LazyClassMirror) { |
| 343 _superclass = _superclass.resolve(mirrors); | 355 _superclass = _superclass.resolve(mirrors); |
| 344 } | 356 } |
| 345 return _superclass; | 357 return _superclass; |
| 346 } | 358 } |
| 347 | 359 |
| 348 var _superinterfaces; | 360 var _superinterfaces; |
| 349 List<ClassMirror> get superinterfaces() { | 361 List<ClassMirror> get superinterfaces() { |
| 350 if (_superinterfaces.length > 0 && | 362 if (_superinterfaces.length > 0 && |
| 351 _superinterfaces[0] is _LazyClassMirror) { | 363 _superinterfaces[0] is _LazyClassMirror) { |
| 352 List<ClassMirror> resolved = new List<ClassMirror>(); | 364 List<ClassMirror> resolved = new List<ClassMirror>(); |
| 353 for (int i = 0; i < _superinterfaces.length; i++) { | 365 for (int i = 0; i < _superinterfaces.length; i++) { |
| 354 resolved.add(_superinterfaces[i].resolve(mirrors)); | 366 resolved.add(_superinterfaces[i].resolve(mirrors)); |
| 355 } | 367 } |
| 356 _superinterfaces = resolved; | 368 _superinterfaces = resolved; |
| 357 } | 369 } |
| 358 return _superinterfaces; | 370 return _superinterfaces; |
| 359 } | 371 } |
| 360 | 372 |
| 361 var _defaultFactory; | 373 var _defaultFactory; |
| 362 ClassMirror get defaultFactory() { | 374 ClassMirror get defaultFactory() { |
| 363 if (_defaultFactory is _LazyClassMirror) { | 375 if (_defaultFactory is _LazyClassMirror) { |
| 364 _defaultFactory = _defaultFactory.resolve(mirrors); | 376 _defaultFactory = _defaultFactory.resolve(mirrors); |
| 365 } | 377 } |
| 366 return _defaultFactory; | 378 return _defaultFactory; |
| 367 } | 379 } |
| 368 | 380 |
| 369 final Map<String, ClassMirror> members; | 381 final Map<String, Mirror> members; |
| 370 | 382 |
| 371 Map<String, ClassMirror> _methods = null; | 383 Map<String, MethodMirror> _methods = null; |
| 372 Map<String, ClassMirror> _variables = null; | 384 Map<String, MethodMirror> _constructors = null; |
| 385 Map<String, MethodMirror> _getters = null; |
| 386 Map<String, MethodMirror> _setters = null; |
| 387 Map<String, VariableMirror> _variables = null; |
| 373 | 388 |
| 374 Map<String, MethodMirror> get methods() { | 389 Map<String, MethodMirror> get methods() { |
| 375 if (_methods == null) { | 390 if (_methods == null) { |
| 376 _methods = filterMap(members, | 391 _methods = filterMap(members, |
| 377 (key, value) => (value is MethodMirror)); | 392 (key, value) => (value is MethodMirror)); |
| 378 } | 393 } |
| 379 return _methods; | 394 return _methods; |
| 380 } | 395 } |
| 381 | 396 |
| 397 Map<String, MethodMirror> get constructors() { |
| 398 if (_constructors == null) { |
| 399 _constructors = filterMap(methods, |
| 400 (key, value) => (value.isConstructor)); |
| 401 } |
| 402 return _constructors; |
| 403 } |
| 404 |
| 405 Map<String, MethodMirror> get getters() { |
| 406 if (_getters == null) { |
| 407 _getters = filterMap(methods, |
| 408 (key, value) => (value.isGetter)); |
| 409 } |
| 410 return _getters; |
| 411 } |
| 412 |
| 413 Map<String, MethodMirror> get setters() { |
| 414 if (_setters == null) { |
| 415 _setters = filterMap(methods, |
| 416 (key, value) => (value.isSetter)); |
| 417 } |
| 418 return _setters; |
| 419 } |
| 420 |
| 382 Map<String, VariableMirror> get variables() { | 421 Map<String, VariableMirror> get variables() { |
| 383 if (_variables == null) { | 422 if (_variables == null) { |
| 384 _variables = filterMap(members, | 423 _variables = filterMap(members, |
| 385 (key, value) => (value is VariableMirror)); | 424 (key, value) => (value is VariableMirror)); |
| 386 } | 425 } |
| 387 return _variables; | 426 return _variables; |
| 388 } | 427 } |
| 389 | 428 |
| 390 String toString() { | 429 List<TypeVariableMirror> get typeVariables() { |
| 391 return "ClassMirror on '$simpleName'"; | 430 throw new NotImplementedException( |
| 431 'ClassMirror.typeVariables not yet implemented'); |
| 392 } | 432 } |
| 393 | 433 |
| 434 List<TypeMirror> get typeArguments() { |
| 435 throw new NotImplementedException( |
| 436 'ClassMirror.typeArguments not yet implemented'); |
| 437 } |
| 438 |
| 439 bool isGenericDeclaration() { |
| 440 throw new NotImplementedException( |
| 441 'ClassMirror.isGenericDeclaration not yet implemented'); |
| 442 } |
| 443 |
| 444 ClassMirror genericDeclaration() { |
| 445 throw new NotImplementedException( |
| 446 'ClassMirror.genericDeclaration not yet implemented'); |
| 447 } |
| 448 |
| 449 String toString() => "ClassMirror on '$simpleName'"; |
| 450 |
| 394 Future<InstanceMirror> newInstance(String constructorName, | 451 Future<InstanceMirror> newInstance(String constructorName, |
| 395 List positionalArguments, | 452 List positionalArguments, |
| 396 [Map<String,Dynamic> namedArguments]) { | 453 [Map<String,Dynamic> namedArguments]) { |
| 397 if (namedArguments !== null) { | 454 if (namedArguments !== null) { |
| 398 throw new NotImplementedException('named arguments not implemented'); | 455 throw new NotImplementedException('named arguments not implemented'); |
| 399 } | 456 } |
| 400 // Walk the arguments and make sure they are legal. | 457 // Walk the arguments and make sure they are legal. |
| 401 for (int i = 0; i < positionalArguments.length; i++) { | 458 for (int i = 0; i < positionalArguments.length; i++) { |
| 402 var arg = positionalArguments[i]; | 459 var arg = positionalArguments[i]; |
| 403 _LocalObjectMirrorImpl._validateArgument(i, arg); | 460 _LocalObjectMirrorImpl._validateArgument(i, arg); |
| 404 } | 461 } |
| 405 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 462 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 406 try { | 463 try { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 427 } | 484 } |
| 428 | 485 |
| 429 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl | 486 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl |
| 430 implements LibraryMirror { | 487 implements LibraryMirror { |
| 431 _LocalLibraryMirrorImpl(ref, | 488 _LocalLibraryMirrorImpl(ref, |
| 432 this.simpleName, | 489 this.simpleName, |
| 433 this.url, | 490 this.url, |
| 434 this.members) : super(ref) {} | 491 this.members) : super(ref) {} |
| 435 | 492 |
| 436 final String simpleName; | 493 final String simpleName; |
| 494 |
| 495 // The simple name and the qualified name are the same for a library. |
| 496 String get qualifiedName() => simpleName; |
| 497 |
| 498 // Always null for libraries. |
| 499 final DeclarationMirror owner = null; |
| 500 |
| 501 // Always false for libraries. |
| 502 final bool isPrivate = false; |
| 503 |
| 504 // Always false for libraries. |
| 505 final bool isTopLevel = false; |
| 506 |
| 507 SourceLocation get location() { |
| 508 throw new NotImplementedException( |
| 509 'LibraryMirror.location not yet implemented'); |
| 510 } |
| 511 |
| 437 final String url; | 512 final String url; |
| 438 final Map<String, ClassMirror> members; | 513 final Map<String, Mirror> members; |
| 439 | 514 |
| 440 Map<String, ClassMirror> _classes = null; | 515 Map<String, ClassMirror> _classes = null; |
| 441 Map<String, ClassMirror> _functions = null; | 516 Map<String, MethodMirror> _functions = null; |
| 442 Map<String, ClassMirror> _variables = null; | 517 Map<String, MethodMirror> _getters = null; |
| 518 Map<String, MethodMirror> _setters = null; |
| 519 Map<String, VariableMirror> _variables = null; |
| 443 | 520 |
| 444 Map<String, ClassMirror> get classes() { | 521 Map<String, ClassMirror> get classes() { |
| 445 if (_classes == null) { | 522 if (_classes == null) { |
| 446 _classes = filterMap(members, | 523 _classes = filterMap(members, |
| 447 (key, value) => (value is ClassMirror)); | 524 (key, value) => (value is ClassMirror)); |
| 448 } | 525 } |
| 449 return _classes; | 526 return _classes; |
| 450 } | 527 } |
| 451 | 528 |
| 452 Map<String, MethodMirror> get functions() { | 529 Map<String, MethodMirror> get functions() { |
| 453 if (_functions == null) { | 530 if (_functions == null) { |
| 454 _functions = filterMap(members, | 531 _functions = filterMap(members, |
| 455 (key, value) => (value is MethodMirror)); | 532 (key, value) => (value is MethodMirror)); |
| 456 } | 533 } |
| 457 return _functions; | 534 return _functions; |
| 458 } | 535 } |
| 459 | 536 |
| 537 Map<String, MethodMirror> get getters() { |
| 538 if (_getters == null) { |
| 539 _getters = filterMap(functions, |
| 540 (key, value) => (value.isGetter)); |
| 541 } |
| 542 return _getters; |
| 543 } |
| 544 |
| 545 Map<String, MethodMirror> get setters() { |
| 546 if (_setters == null) { |
| 547 _setters = filterMap(functions, |
| 548 (key, value) => (value.isSetter)); |
| 549 } |
| 550 return _setters; |
| 551 } |
| 552 |
| 460 Map<String, VariableMirror> get variables() { | 553 Map<String, VariableMirror> get variables() { |
| 461 if (_variables == null) { | 554 if (_variables == null) { |
| 462 _variables = filterMap(members, | 555 _variables = filterMap(members, |
| 463 (key, value) => (value is VariableMirror)); | 556 (key, value) => (value is VariableMirror)); |
| 464 } | 557 } |
| 465 return _variables; | 558 return _variables; |
| 466 } | 559 } |
| 467 | 560 |
| 468 String toString() { | 561 String toString() => "LibraryMirror on '$simpleName'"; |
| 469 return "LibraryMirror on '$simpleName'"; | |
| 470 } | |
| 471 } | 562 } |
| 472 | 563 |
| 473 class _LocalMethodMirrorImpl extends _LocalMirrorImpl | 564 class _LocalMethodMirrorImpl extends _LocalMirrorImpl |
| 474 implements MethodMirror { | 565 implements MethodMirror { |
| 475 _LocalMethodMirrorImpl(this.simpleName, | 566 _LocalMethodMirrorImpl(this.simpleName, |
| 476 this._owner, | 567 this._owner, |
| 477 this.parameters, | 568 this.parameters, |
| 478 this.isStatic, | 569 this.isStatic, |
| 479 this.isAbstract, | 570 this.isAbstract, |
| 480 this.isGetter, | 571 this.isGetter, |
| 481 this.isSetter, | 572 this.isSetter, |
| 482 this.isConstructor, | 573 this.isConstructor, |
| 483 this.isConstConstructor, | 574 this.isConstConstructor, |
| 484 this.isGenerativeConstructor, | 575 this.isGenerativeConstructor, |
| 485 this.isRedirectingConstructor, | 576 this.isRedirectingConstructor, |
| 486 this.isFactoryConstructor) {} | 577 this.isFactoryConstructor) {} |
| 487 | 578 |
| 488 final String simpleName; | 579 final String simpleName; |
| 489 | 580 |
| 581 String _qualifiedName = null; |
| 582 String get qualifiedName() { |
| 583 if (_qualifiedName === null) { |
| 584 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; |
| 585 } |
| 586 return _qualifiedName; |
| 587 } |
| 588 |
| 490 var _owner; | 589 var _owner; |
| 491 Mirror get owner() { | 590 DeclarationMirror get owner() { |
| 492 if (_owner is! Mirror) { | 591 if (_owner is! Mirror) { |
| 493 _owner = _owner.resolve(mirrors); | 592 _owner = _owner.resolve(mirrors); |
| 494 } | 593 } |
| 495 return _owner; | 594 return _owner; |
| 496 } | 595 } |
| 497 | 596 |
| 597 bool get isPrivate() { |
| 598 return simpleName.startsWith('_') || constructorName.startsWith('_'); |
| 599 } |
| 600 |
| 601 bool get isTopLevel() => owner is LibraryMirror; |
| 602 |
| 603 SourceLocation get location() { |
| 604 throw new NotImplementedException( |
| 605 'MethodMirror.location not yet implemented'); |
| 606 } |
| 607 |
| 608 TypeMirror get returnType() { |
| 609 throw new NotImplementedException( |
| 610 'MethodMirror.returnType not yet implemented'); |
| 611 } |
| 612 |
| 498 final List<ParameterMirror> parameters; | 613 final List<ParameterMirror> parameters; |
| 499 | 614 |
| 500 bool get isTopLevel() { | 615 final bool isStatic; |
| 501 return owner is LibraryMirror; | 616 final bool isAbstract; |
| 617 |
| 618 bool get isRegularMethod() => !isGetter && !isSetter && !isConstructor; |
| 619 |
| 620 TypeMirror get isOperator() { |
| 621 throw new NotImplementedException( |
| 622 'MethodMirror.isOperator not yet implemented'); |
| 502 } | 623 } |
| 503 | 624 |
| 504 final bool isStatic; | |
| 505 | |
| 506 bool get isMethod() { | |
| 507 return !isGetter && !isSetter && !isConstructor; | |
| 508 } | |
| 509 | |
| 510 final bool isAbstract; | |
| 511 final bool isGetter; | 625 final bool isGetter; |
| 512 final bool isSetter; | 626 final bool isSetter; |
| 513 final bool isConstructor; | 627 final bool isConstructor; |
| 514 | 628 |
| 629 var _constructorName = null; |
| 630 String get constructorName() { |
| 631 if (_constructorName === null) { |
| 632 if (!isConstructor) { |
| 633 _constructorName = ''; |
| 634 } else { |
| 635 var parts = simpleName.split('.'); |
| 636 if (parts.length > 2) { |
| 637 throw new MirrorException( |
| 638 'Internal error in MethodMirror.constructorName: ' |
| 639 'malformed name <$simpleName>'); |
| 640 } else if (parts.length == 2) { |
| 641 _constructorName = parts[1]; |
| 642 } else { |
| 643 _constructorName = ''; |
| 644 } |
| 645 } |
| 646 } |
| 647 return _constructorName; |
| 648 } |
| 649 |
| 515 final bool isConstConstructor; | 650 final bool isConstConstructor; |
| 516 final bool isGenerativeConstructor; | 651 final bool isGenerativeConstructor; |
| 517 final bool isRedirectingConstructor; | 652 final bool isRedirectingConstructor; |
| 518 final bool isFactoryConstructor; | 653 final bool isFactoryConstructor; |
| 519 | 654 |
| 520 String toString() { | 655 String toString() => "MethodMirror on '$simpleName'"; |
| 521 return "MethodMirror on '$simpleName'"; | |
| 522 } | |
| 523 } | |
| 524 | |
| 525 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl | |
| 526 implements ParameterMirror { | |
| 527 // TODO(rmacnak): Fill these mirrors will real information | |
| 528 _LocalParameterMirrorImpl(this.isOptional) | |
| 529 : super(null, null, false, false) {} | |
| 530 | |
| 531 final bool isOptional; | |
| 532 | |
| 533 TypeMirror get type() => null; | |
| 534 String get defaultValue() => null; | |
| 535 bool get hasDefaultValue() => null; | |
| 536 } | 656 } |
| 537 | 657 |
| 538 class _LocalVariableMirrorImpl extends _LocalMirrorImpl | 658 class _LocalVariableMirrorImpl extends _LocalMirrorImpl |
| 539 implements VariableMirror { | 659 implements VariableMirror { |
| 540 _LocalVariableMirrorImpl(this.simpleName, | 660 _LocalVariableMirrorImpl(this.simpleName, |
| 541 this._owner, | 661 this._owner, |
| 542 this.isStatic, | 662 this.isStatic, |
| 543 this.isFinal) {} | 663 this.isFinal) {} |
| 544 | 664 |
| 545 final String simpleName; | 665 final String simpleName; |
| 546 | 666 |
| 667 String _qualifiedName = null; |
| 668 String get qualifiedName() { |
| 669 if (_qualifiedName === null) { |
| 670 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; |
| 671 } |
| 672 return _qualifiedName; |
| 673 } |
| 674 |
| 547 var _owner; | 675 var _owner; |
| 548 Mirror get owner() { | 676 DeclarationMirror get owner() { |
| 549 if (_owner is! Mirror) { | 677 if (_owner is! Mirror) { |
| 550 _owner = _owner.resolve(mirrors); | 678 _owner = _owner.resolve(mirrors); |
| 551 } | 679 } |
| 552 return _owner; | 680 return _owner; |
| 553 } | 681 } |
| 554 | 682 |
| 683 bool get isPrivate() { |
| 684 return simpleName.startsWith('_'); |
| 685 } |
| 686 |
| 555 bool get isTopLevel() { | 687 bool get isTopLevel() { |
| 556 return owner is LibraryMirror; | 688 return owner is LibraryMirror; |
| 557 } | 689 } |
| 558 | 690 |
| 691 SourceLocation get location() { |
| 692 throw new NotImplementedException( |
| 693 'MethodMirror.location not yet implemented'); |
| 694 } |
| 695 |
| 696 TypeMirror get returnType() { |
| 697 throw new NotImplementedException( |
| 698 'MethodMirror.returnType not yet implemented'); |
| 699 } |
| 700 |
| 559 final bool isStatic; | 701 final bool isStatic; |
| 560 final bool isFinal; | 702 final bool isFinal; |
| 561 | 703 |
| 562 String toString() { | 704 String toString() => "VariableMirror on '$simpleName'"; |
| 563 return "VariableMirror on '$simpleName'"; | 705 } |
| 706 |
| 707 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl |
| 708 implements ParameterMirror { |
| 709 // TODO(rmacnak): Fill these mirrors will real information |
| 710 _LocalParameterMirrorImpl(this.isOptional) |
| 711 : super(null, null, false, false) {} |
| 712 |
| 713 final bool isOptional; |
| 714 |
| 715 TypeMirror get type() { |
| 716 throw new NotImplementedException( |
| 717 'ParameterMirror.type not yet implemented'); |
| 718 } |
| 719 |
| 720 String get defaultValue() { |
| 721 throw new NotImplementedException( |
| 722 'ParameterMirror.defaultValue not yet implemented'); |
| 723 } |
| 724 |
| 725 bool get hasDefaultValue() { |
| 726 throw new NotImplementedException( |
| 727 'ParameterMirror.hasDefaultValue not yet implemented'); |
| 564 } | 728 } |
| 565 } | 729 } |
| 566 | 730 |
| 567 class _Mirrors { | 731 class _Mirrors { |
| 568 // Does a port refer to our local isolate? | 732 // Does a port refer to our local isolate? |
| 569 static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort'; | 733 static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort'; |
| 570 | 734 |
| 571 static MirrorSystem _currentMirrorSystem = null; | 735 static MirrorSystem _currentMirrorSystem = null; |
| 572 | 736 |
| 573 // Creates a new local MirrorSystem. | 737 // Creates a new local MirrorSystem. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 600 | 764 |
| 601 // Creates a new local InstanceMirror | 765 // Creates a new local InstanceMirror |
| 602 static InstanceMirror makeLocalInstanceMirror(Object reflectee) | 766 static InstanceMirror makeLocalInstanceMirror(Object reflectee) |
| 603 native 'Mirrors_makeLocalInstanceMirror'; | 767 native 'Mirrors_makeLocalInstanceMirror'; |
| 604 | 768 |
| 605 // Creates a new local mirror for some Object. | 769 // Creates a new local mirror for some Object. |
| 606 static InstanceMirror reflect(Object reflectee) { | 770 static InstanceMirror reflect(Object reflectee) { |
| 607 return makeLocalInstanceMirror(reflectee); | 771 return makeLocalInstanceMirror(reflectee); |
| 608 } | 772 } |
| 609 } | 773 } |
| OLD | NEW |