| 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 static _computeFunction(reflectee) | 413 static _computeFunction(reflectee) |
| 414 native 'ClosureMirror_function'; | 414 native 'ClosureMirror_function'; |
| 415 | 415 |
| 416 static _computeFindInContext(reflectee, name) | 416 static _computeFindInContext(reflectee, name) |
| 417 native 'ClosureMirror_find_in_context'; | 417 native 'ClosureMirror_find_in_context'; |
| 418 } | 418 } |
| 419 | 419 |
| 420 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl | 420 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl |
| 421 implements ClassMirror { | 421 implements ClassMirror { |
| 422 _LocalClassMirrorImpl(reflectee, | 422 _LocalClassMirrorImpl(reflectee, |
| 423 this._reflectedType, | 423 reflectedType, |
| 424 String simpleName, | 424 String simpleName, |
| 425 this._isGeneric, | 425 this._isGeneric, |
| 426 this._isMixinTypedef, | 426 this._isMixinTypedef, |
| 427 this._isGenericDeclaration) | 427 this._isGenericDeclaration) |
| 428 : this._simpleName = _s(simpleName), | 428 : this._simpleName = _s(simpleName), |
| 429 this._reflectedType = reflectedType, |
| 430 this._instantiator = reflectedType, |
| 429 super(reflectee); | 431 super(reflectee); |
| 430 | 432 |
| 431 final Type _reflectedType; | 433 final Type _reflectedType; |
| 432 final bool _isGeneric; | 434 final bool _isGeneric; |
| 433 final bool _isMixinTypedef; | 435 final bool _isMixinTypedef; |
| 434 final bool _isGenericDeclaration; | 436 final bool _isGenericDeclaration; |
| 437 Type _instantiator; |
| 435 | 438 |
| 436 TypeMirror _instantiateInContextOf(declaration) => this; | 439 TypeMirror _instantiateInContextOf(declaration) => this; |
| 437 | 440 |
| 438 bool get hasReflectedType => !_isGenericDeclaration; | 441 bool get hasReflectedType => !_isGenericDeclaration; |
| 439 Type get reflectedType { | 442 Type get reflectedType { |
| 440 if (!hasReflectedType) { | 443 if (!hasReflectedType) { |
| 441 throw new UnsupportedError( | 444 throw new UnsupportedError( |
| 442 "Declarations of generics have no reflected type"); | 445 "Declarations of generics have no reflected type"); |
| 443 } | 446 } |
| 444 return _reflectedType; | 447 return _reflectedType; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 ClassMirror get _trueSuperclass { | 489 ClassMirror get _trueSuperclass { |
| 487 if (_trueSuperclassField == null) { | 490 if (_trueSuperclassField == null) { |
| 488 Type supertype = isOriginalDeclaration | 491 Type supertype = isOriginalDeclaration |
| 489 ? _supertype(_reflectedType) | 492 ? _supertype(_reflectedType) |
| 490 : _supertypeInstantiated(_reflectedType); | 493 : _supertypeInstantiated(_reflectedType); |
| 491 if (supertype == null) { | 494 if (supertype == null) { |
| 492 // Object has no superclass. | 495 // Object has no superclass. |
| 493 return null; | 496 return null; |
| 494 } | 497 } |
| 495 _trueSuperclassField = _Mirrors._reflectType(supertype); | 498 _trueSuperclassField = _Mirrors._reflectType(supertype); |
| 499 _trueSuperclassField._instantiator = _instantiator; |
| 496 } | 500 } |
| 497 return _trueSuperclassField; | 501 return _trueSuperclassField; |
| 498 } | 502 } |
| 499 ClassMirror get superclass { | 503 ClassMirror get superclass { |
| 500 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass; | 504 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass; |
| 501 } | 505 } |
| 502 | 506 |
| 503 var _superinterfaces; | 507 var _superinterfaces; |
| 504 List<ClassMirror> get superinterfaces { | 508 List<ClassMirror> get superinterfaces { |
| 505 if (_superinterfaces == null) { | 509 if (_superinterfaces == null) { |
| 506 _superinterfaces = _interfaces(_reflectee) | 510 _superinterfaces = isOriginalDeclaration |
| 511 ? _nativeInterfaces(_reflectedType) |
| 512 : _nativeInterfacesInstantiated(_reflectedType); |
| 513 _superinterfaces = _superinterfaces |
| 507 .map((i) => _Mirrors._reflectType(i)).toList(growable:false); | 514 .map((i) => _Mirrors._reflectType(i)).toList(growable:false); |
| 508 } | 515 } |
| 509 return _superinterfaces; | 516 return _superinterfaces; |
| 510 } | 517 } |
| 511 | 518 |
| 512 get _mixinApplicationName { | 519 get _mixinApplicationName { |
| 513 var mixins = new List<ClassMirror>(); | 520 var mixins = new List<ClassMirror>(); |
| 514 var klass = this; | 521 var klass = this; |
| 515 while (_computeMixin(klass._reflectee) != null) { | 522 while (_nativeMixin(klass._reflectedType) != null) { |
| 516 mixins.add(klass.mixin); | 523 mixins.add(klass.mixin); |
| 517 klass = klass.superclass; | 524 klass = klass.superclass; |
| 518 } | 525 } |
| 519 return _s( | 526 return _s( |
| 520 _n(klass.qualifiedName) | 527 _n(klass.qualifiedName) |
| 521 + ' with ' | 528 + ' with ' |
| 522 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', ')); | 529 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', ')); |
| 523 } | 530 } |
| 524 | 531 |
| 525 var _mixin; | 532 var _mixin; |
| 526 ClassMirror get mixin { | 533 ClassMirror get mixin { |
| 527 if (_mixin == null) { | 534 if (_mixin == null) { |
| 528 if (_isMixinTypedef) { | 535 if (_isMixinTypedef) { |
| 529 _mixin = _trueSuperclass.mixin; | 536 Type mixinType = isOriginalDeclaration |
| 537 ? _nativeMixin(_trueSuperclass._reflectedType) |
| 538 : _nativeMixinInstantiated(_trueSuperclass._reflectedType, _instanti
ator); |
| 539 _mixin = _Mirrors._reflectType(mixinType); |
| 530 } else { | 540 } else { |
| 531 var mixinType = _computeMixin(_reflectee); | 541 Type mixinType = isOriginalDeclaration |
| 542 ? _nativeMixin(_reflectedType) |
| 543 : _nativeMixinInstantiated(_reflectedType, _instantiator); |
| 532 if (mixinType == null) { | 544 if (mixinType == null) { |
| 533 // The reflectee is not a mixin application. | 545 // The reflectee is not a mixin application. |
| 534 _mixin = this; | 546 _mixin = this; |
| 535 } else { | 547 } else { |
| 536 _mixin = _Mirrors._reflectType(mixinType); | 548 _mixin = _Mirrors._reflectType(mixinType); |
| 537 } | 549 } |
| 538 } | 550 } |
| 539 } | 551 } |
| 540 return _mixin; | 552 return _mixin; |
| 541 } | 553 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 | 714 |
| 703 static _library(reflectee) | 715 static _library(reflectee) |
| 704 native "ClassMirror_library"; | 716 native "ClassMirror_library"; |
| 705 | 717 |
| 706 static _supertype(reflectedType) | 718 static _supertype(reflectedType) |
| 707 native "ClassMirror_supertype"; | 719 native "ClassMirror_supertype"; |
| 708 | 720 |
| 709 static _supertypeInstantiated(reflectedType) | 721 static _supertypeInstantiated(reflectedType) |
| 710 native "ClassMirror_supertype_instantiated"; | 722 native "ClassMirror_supertype_instantiated"; |
| 711 | 723 |
| 712 static _interfaces(reflectee) | 724 static _nativeInterfaces(reflectedType) |
| 713 native "ClassMirror_interfaces"; | 725 native "ClassMirror_interfaces"; |
| 714 | 726 |
| 715 static _computeMixin(reflectee) | 727 static _nativeInterfacesInstantiated(reflectedType) |
| 728 native "ClassMirror_interfaces_instantiated"; |
| 729 |
| 730 static _nativeMixin(reflectedType) |
| 716 native "ClassMirror_mixin"; | 731 native "ClassMirror_mixin"; |
| 717 | 732 |
| 733 static _nativeMixinInstantiated(reflectedType, instantiator) |
| 734 native "ClassMirror_mixin_instantiated"; |
| 735 |
| 718 _computeMembers(reflectee) | 736 _computeMembers(reflectee) |
| 719 native "ClassMirror_members"; | 737 native "ClassMirror_members"; |
| 720 | 738 |
| 721 _computeConstructors(reflectee) | 739 _computeConstructors(reflectee) |
| 722 native "ClassMirror_constructors"; | 740 native "ClassMirror_constructors"; |
| 723 | 741 |
| 724 _invoke(reflectee, memberName, arguments, argumentNames) | 742 _invoke(reflectee, memberName, arguments, argumentNames) |
| 725 native 'ClassMirror_invoke'; | 743 native 'ClassMirror_invoke'; |
| 726 | 744 |
| 727 _invokeGetter(reflectee, getterName) | 745 _invokeGetter(reflectee, getterName) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 738 | 756 |
| 739 static _computeTypeArguments(reflectee) | 757 static _computeTypeArguments(reflectee) |
| 740 native "ClassMirror_type_arguments"; | 758 native "ClassMirror_type_arguments"; |
| 741 } | 759 } |
| 742 | 760 |
| 743 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl | 761 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl |
| 744 implements FunctionTypeMirror { | 762 implements FunctionTypeMirror { |
| 745 _LocalFunctionTypeMirrorImpl(reflectee, reflectedType) | 763 _LocalFunctionTypeMirrorImpl(reflectee, reflectedType) |
| 746 : super(reflectee, reflectedType, null, false, false, false); | 764 : super(reflectee, reflectedType, null, false, false, false); |
| 747 | 765 |
| 766 bool get _isAnonymousMixinApplication => false; |
| 767 |
| 748 // FunctionTypeMirrors have a simpleName generated from their signature. | 768 // FunctionTypeMirrors have a simpleName generated from their signature. |
| 749 Symbol _simpleName = null; | 769 Symbol _simpleName = null; |
| 750 Symbol get simpleName { | 770 Symbol get simpleName { |
| 751 if (_simpleName == null) { | 771 if (_simpleName == null) { |
| 752 _simpleName = _s(_makeSignatureString(returnType, parameters)); | 772 _simpleName = _s(_makeSignatureString(returnType, parameters)); |
| 753 } | 773 } |
| 754 return _simpleName; | 774 return _simpleName; |
| 755 } | 775 } |
| 756 | 776 |
| 757 MethodMirror _callMethod; | 777 MethodMirror _callMethod; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 Type get reflectedType => throw new UnsupportedError() ; | 882 Type get reflectedType => throw new UnsupportedError() ; |
| 863 | 883 |
| 864 List<TypeVariableMirror> get typeVariables => new UnmodifiableListView<TypeVar
iableMirror>(); | 884 List<TypeVariableMirror> get typeVariables => new UnmodifiableListView<TypeVar
iableMirror>(); |
| 865 List<TypeMirror> get typeArguments => new UnmodifiableListView<TypeMirror>(); | 885 List<TypeMirror> get typeArguments => new UnmodifiableListView<TypeMirror>(); |
| 866 | 886 |
| 867 bool get isOriginalDeclaration => true; | 887 bool get isOriginalDeclaration => true; |
| 868 TypeMirror get originalDeclaration => this; | 888 TypeMirror get originalDeclaration => this; |
| 869 | 889 |
| 870 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; | 890 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; |
| 871 | 891 |
| 892 operator ==(other) { |
| 893 return other is TypeVariableMirror |
| 894 && simpleName == other.simpleName |
| 895 && owner == other.owner; |
| 896 } |
| 897 int get hashCode => simpleName.hashCode; |
| 898 |
| 872 static DeclarationMirror _TypeVariableMirror_owner(reflectee) | 899 static DeclarationMirror _TypeVariableMirror_owner(reflectee) |
| 873 native "TypeVariableMirror_owner"; | 900 native "TypeVariableMirror_owner"; |
| 874 | 901 |
| 875 static Type _TypeVariableMirror_upper_bound(reflectee) | 902 static Type _TypeVariableMirror_upper_bound(reflectee) |
| 876 native "TypeVariableMirror_upper_bound"; | 903 native "TypeVariableMirror_upper_bound"; |
| 877 | 904 |
| 878 static Type _TypeVariableMirror_instantiate_from(reflectee, instantiator) | 905 static Type _TypeVariableMirror_instantiate_from(reflectee, instantiator) |
| 879 native "TypeVariableMirror_instantiate_from"; | 906 native "TypeVariableMirror_instantiate_from"; |
| 880 | 907 |
| 881 TypeMirror _instantiateInContextOf(declaration) { | 908 TypeMirror _instantiateInContextOf(declaration) { |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 if (typeMirror == null) { | 1393 if (typeMirror == null) { |
| 1367 typeMirror = makeLocalTypeMirror(key); | 1394 typeMirror = makeLocalTypeMirror(key); |
| 1368 _instanitationCache[key] = typeMirror; | 1395 _instanitationCache[key] = typeMirror; |
| 1369 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1396 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
| 1370 _declarationCache[key] = typeMirror; | 1397 _declarationCache[key] = typeMirror; |
| 1371 } | 1398 } |
| 1372 } | 1399 } |
| 1373 return typeMirror; | 1400 return typeMirror; |
| 1374 } | 1401 } |
| 1375 } | 1402 } |
| OLD | NEW |