| 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 import "dart:collection"; | 7 import "dart:collection"; |
| 8 | 8 |
| 9 // These values are allowed to be passed directly over the wire. | 9 // These values are allowed to be passed directly over the wire. |
| 10 bool _isSimpleValue(var value) { | 10 bool _isSimpleValue(var value) { |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 super(reflectee); | 367 super(reflectee); |
| 368 | 368 |
| 369 final Type _reflectedType; | 369 final Type _reflectedType; |
| 370 final bool _isGeneric; | 370 final bool _isGeneric; |
| 371 | 371 |
| 372 Symbol _simpleName; | 372 Symbol _simpleName; |
| 373 Symbol get simpleName { | 373 Symbol get simpleName { |
| 374 // dynamic, void and the function types have their names set eagerly in the | 374 // dynamic, void and the function types have their names set eagerly in the |
| 375 // constructor. | 375 // constructor. |
| 376 if(_simpleName == null) { | 376 if(_simpleName == null) { |
| 377 _simpleName = _s(_name(_reflectee)); | 377 var simpleString = _name(_reflectee); |
| 378 if (simpleString.contains('&')) { |
| 379 _simpleName = this._computeMixinApplicationName; |
| 380 } else { |
| 381 _simpleName = _s(simpleString); |
| 382 } |
| 378 } | 383 } |
| 379 return _simpleName; | 384 return _simpleName; |
| 380 } | 385 } |
| 381 | 386 |
| 382 Symbol _qualifiedName = null; | 387 Symbol _qualifiedName = null; |
| 383 Symbol get qualifiedName { | 388 Symbol get qualifiedName { |
| 384 if (_qualifiedName == null) { | 389 if (_qualifiedName == null) { |
| 385 _qualifiedName = _computeQualifiedName(owner, simpleName); | 390 _qualifiedName = _computeQualifiedName(owner, simpleName); |
| 386 } | 391 } |
| 387 return _qualifiedName; | 392 return _qualifiedName; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 410 ClassMirror get defaultFactory => null; | 415 ClassMirror get defaultFactory => null; |
| 411 | 416 |
| 412 ClassMirror _superclass; | 417 ClassMirror _superclass; |
| 413 ClassMirror get superclass { | 418 ClassMirror get superclass { |
| 414 if (_superclass == null) { | 419 if (_superclass == null) { |
| 415 Type supertype = _supertype(_reflectee); | 420 Type supertype = _supertype(_reflectee); |
| 416 if (supertype == null) { | 421 if (supertype == null) { |
| 417 // Object has no superclass. | 422 // Object has no superclass. |
| 418 return null; | 423 return null; |
| 419 } | 424 } |
| 420 _superclass = reflectClass(supertype); | 425 _superclass = _Mirrors._reflectType(supertype); |
| 421 } | 426 } |
| 422 return _superclass; | 427 return _superclass; |
| 423 } | 428 } |
| 424 | 429 |
| 425 var _superinterfaces; | 430 var _superinterfaces; |
| 426 List<ClassMirror> get superinterfaces { | 431 List<ClassMirror> get superinterfaces { |
| 427 if (_superinterfaces == null) { | 432 if (_superinterfaces == null) { |
| 428 _superinterfaces = _interfaces(_reflectee) | 433 _superinterfaces = _interfaces(_reflectee) |
| 429 .map((i) => reflectClass(i)).toList(growable:false); | 434 .map((i) => _Mirrors._reflectType(i)).toList(growable:false); |
| 430 } | 435 } |
| 431 return _superinterfaces; | 436 return _superinterfaces; |
| 432 } | 437 } |
| 433 | 438 |
| 439 get _computeMixinApplicationName { |
| 440 var mixins = new List<ClassMirror>(); |
| 441 var klass = this; |
| 442 while (_computeMixin(klass._reflectee) != null) { |
| 443 mixins.add(klass.mixin); |
| 444 klass = klass.superclass; |
| 445 } |
| 446 return _s( |
| 447 _n(klass.qualifiedName) |
| 448 + ' with ' |
| 449 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', ')); |
| 450 } |
| 451 |
| 452 var _mixin; |
| 453 ClassMirror get mixin { |
| 454 if (_mixin == null) { |
| 455 var mixinType = _computeMixin(_reflectee); |
| 456 if (mixinType == null) { |
| 457 // The reflectee is not a mixin application. |
| 458 _mixin = this; |
| 459 } else { |
| 460 _mixin = _Mirrors._reflectType(mixinType); |
| 461 } |
| 462 } |
| 463 return _mixin; |
| 464 } |
| 465 |
| 434 Map<Symbol, Mirror> _members; | 466 Map<Symbol, Mirror> _members; |
| 435 | 467 |
| 436 Map<Symbol, Mirror> get members { | 468 Map<Symbol, Mirror> get members { |
| 437 if (_members == null) { | 469 if (_members == null) { |
| 438 _members = _makeMemberMap(_computeMembers(_reflectee)); | 470 _members = _makeMemberMap(mixin._computeMembers(_reflectee)); |
| 439 } | 471 } |
| 440 return _members; | 472 return _members; |
| 441 } | 473 } |
| 442 | 474 |
| 443 Map<Symbol, MethodMirror> _methods = null; | 475 Map<Symbol, MethodMirror> _methods = null; |
| 444 Map<Symbol, MethodMirror> _getters = null; | 476 Map<Symbol, MethodMirror> _getters = null; |
| 445 Map<Symbol, MethodMirror> _setters = null; | 477 Map<Symbol, MethodMirror> _setters = null; |
| 446 Map<Symbol, VariableMirror> _variables = null; | 478 Map<Symbol, VariableMirror> _variables = null; |
| 447 | 479 |
| 448 Map<Symbol, MethodMirror> get methods { | 480 Map<Symbol, MethodMirror> get methods { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 478 members, | 510 members, |
| 479 (key, value) => (value is VariableMirror)); | 511 (key, value) => (value is VariableMirror)); |
| 480 } | 512 } |
| 481 return _variables; | 513 return _variables; |
| 482 } | 514 } |
| 483 | 515 |
| 484 Map<Symbol, MethodMirror> _constructors; | 516 Map<Symbol, MethodMirror> _constructors; |
| 485 | 517 |
| 486 Map<Symbol, MethodMirror> get constructors { | 518 Map<Symbol, MethodMirror> get constructors { |
| 487 if (_constructors == null) { | 519 if (_constructors == null) { |
| 488 _constructors = _makeMemberMap(_computeConstructors(_reflectee)); | 520 var constructorsList = _computeConstructors(_reflectee); |
| 521 var stringName = _n(simpleName); |
| 522 constructorsList.forEach((c) => c._patchConstructorName(stringName)); |
| 523 _constructors = _makeMemberMap(constructorsList); |
| 489 } | 524 } |
| 490 return _constructors; | 525 return _constructors; |
| 491 } | 526 } |
| 492 | 527 |
| 493 Map<Symbol, TypeVariableMirror> _typeVariables = null; | 528 Map<Symbol, TypeVariableMirror> _typeVariables = null; |
| 494 | 529 |
| 495 Map<Symbol, TypeVariableMirror> get typeVariables { | 530 Map<Symbol, TypeVariableMirror> get typeVariables { |
| 496 if (_typeVariables == null) { | 531 if (_typeVariables == null) { |
| 497 List params = _ClassMirror_type_variables(_reflectee); | 532 List params = _ClassMirror_type_variables(_reflectee); |
| 498 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>(); | 533 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 | 621 |
| 587 static _library(reflectee) | 622 static _library(reflectee) |
| 588 native "ClassMirror_library"; | 623 native "ClassMirror_library"; |
| 589 | 624 |
| 590 static _supertype(reflectee) | 625 static _supertype(reflectee) |
| 591 native "ClassMirror_supertype"; | 626 native "ClassMirror_supertype"; |
| 592 | 627 |
| 593 static _interfaces(reflectee) | 628 static _interfaces(reflectee) |
| 594 native "ClassMirror_interfaces"; | 629 native "ClassMirror_interfaces"; |
| 595 | 630 |
| 631 static _computeMixin(reflectee) |
| 632 native "ClassMirror_mixin"; |
| 633 |
| 596 _computeMembers(reflectee) | 634 _computeMembers(reflectee) |
| 597 native "ClassMirror_members"; | 635 native "ClassMirror_members"; |
| 598 | 636 |
| 599 _computeConstructors(reflectee) | 637 _computeConstructors(reflectee) |
| 600 native "ClassMirror_constructors"; | 638 native "ClassMirror_constructors"; |
| 601 | 639 |
| 602 _invoke(reflectee, memberName, positionalArguments) | 640 _invoke(reflectee, memberName, positionalArguments) |
| 603 native 'ClassMirror_invoke'; | 641 native 'ClassMirror_invoke'; |
| 604 | 642 |
| 605 _invokeGetter(reflectee, getterName) | 643 _invokeGetter(reflectee, getterName) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 | 706 |
| 669 static Type _FunctionTypeMirror_return_type(reflectee) | 707 static Type _FunctionTypeMirror_return_type(reflectee) |
| 670 native "FunctionTypeMirror_return_type"; | 708 native "FunctionTypeMirror_return_type"; |
| 671 | 709 |
| 672 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) | 710 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) |
| 673 native "FunctionTypeMirror_parameters"; | 711 native "FunctionTypeMirror_parameters"; |
| 674 } | 712 } |
| 675 | 713 |
| 676 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl | 714 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl |
| 677 implements DeclarationMirror { | 715 implements DeclarationMirror { |
| 678 _LocalDeclarationMirrorImpl(this._reflectee, this.simpleName); | 716 _LocalDeclarationMirrorImpl(this._reflectee, this._simpleName); |
| 679 | 717 |
| 680 final _reflectee; | 718 final _reflectee; |
| 681 | 719 |
| 682 final Symbol simpleName; | 720 Symbol _simpleName; |
| 721 Symbol get simpleName => _simpleName; |
| 683 | 722 |
| 684 Symbol _qualifiedName = null; | 723 Symbol _qualifiedName = null; |
| 685 Symbol get qualifiedName { | 724 Symbol get qualifiedName { |
| 686 if (_qualifiedName == null) { | 725 if (_qualifiedName == null) { |
| 687 _qualifiedName = _computeQualifiedName(owner, simpleName); | 726 _qualifiedName = _computeQualifiedName(owner, simpleName); |
| 688 } | 727 } |
| 689 return _qualifiedName; | 728 return _qualifiedName; |
| 690 } | 729 } |
| 691 | 730 |
| 692 List<InstanceMirror> get metadata { | 731 List<InstanceMirror> get metadata { |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 } else if (parts.length == 2) { | 1039 } else if (parts.length == 2) { |
| 1001 _constructorName = _s(parts[1]); | 1040 _constructorName = _s(parts[1]); |
| 1002 } else { | 1041 } else { |
| 1003 _constructorName = _s(''); | 1042 _constructorName = _s(''); |
| 1004 } | 1043 } |
| 1005 } | 1044 } |
| 1006 } | 1045 } |
| 1007 return _constructorName; | 1046 return _constructorName; |
| 1008 } | 1047 } |
| 1009 | 1048 |
| 1049 void _patchConstructorName(ownerName) { |
| 1050 var cn = _n(constructorName); |
| 1051 if(cn == ''){ |
| 1052 _simpleName = _s(ownerName); |
| 1053 } else { |
| 1054 _simpleName = _s(ownerName + "." + cn); |
| 1055 } |
| 1056 } |
| 1057 |
| 1010 String toString() => "MethodMirror on '${_n(simpleName)}'"; | 1058 String toString() => "MethodMirror on '${_n(simpleName)}'"; |
| 1011 | 1059 |
| 1012 static dynamic _MethodMirror_owner(reflectee) | 1060 static dynamic _MethodMirror_owner(reflectee) |
| 1013 native "MethodMirror_owner"; | 1061 native "MethodMirror_owner"; |
| 1014 | 1062 |
| 1015 static dynamic _MethodMirror_return_type(reflectee) | 1063 static dynamic _MethodMirror_return_type(reflectee) |
| 1016 native "MethodMirror_return_type"; | 1064 native "MethodMirror_return_type"; |
| 1017 | 1065 |
| 1018 List<ParameterMirror> _MethodMirror_parameters(reflectee) | 1066 List<ParameterMirror> _MethodMirror_parameters(reflectee) |
| 1019 native "MethodMirror_parameters"; | 1067 native "MethodMirror_parameters"; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 if (typeMirror == null) { | 1258 if (typeMirror == null) { |
| 1211 typeMirror = makeLocalTypeMirror(key); | 1259 typeMirror = makeLocalTypeMirror(key); |
| 1212 _instanitationCache[key] = typeMirror; | 1260 _instanitationCache[key] = typeMirror; |
| 1213 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1261 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
| 1214 _declarationCache[key] = typeMirror; | 1262 _declarationCache[key] = typeMirror; |
| 1215 } | 1263 } |
| 1216 } | 1264 } |
| 1217 return typeMirror; | 1265 return typeMirror; |
| 1218 } | 1266 } |
| 1219 } | 1267 } |
| OLD | NEW |