| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // TODO(ahe): This is a hack, see delegate below. | 244 // TODO(ahe): This is a hack, see delegate below. |
| 245 static Function _invokeOnClosure; | 245 static Function _invokeOnClosure; |
| 246 | 246 |
| 247 _LocalInstanceMirrorImpl(reflectee) : super(reflectee); | 247 _LocalInstanceMirrorImpl(reflectee) : super(reflectee); |
| 248 | 248 |
| 249 ClassMirror _type; | 249 ClassMirror _type; |
| 250 ClassMirror get type { | 250 ClassMirror get type { |
| 251 if (_type == null) { | 251 if (_type == null) { |
| 252 // Note it not safe to use reflectee.runtimeType because runtimeType may | 252 // Note it not safe to use reflectee.runtimeType because runtimeType may |
| 253 // be overridden. | 253 // be overridden. |
| 254 _type = reflectClass(_computeType(reflectee)); | 254 _type = _Mirrors._reflectType(_computeType(reflectee)); |
| 255 } | 255 } |
| 256 return _type; | 256 return _type; |
| 257 } | 257 } |
| 258 | 258 |
| 259 // LocalInstanceMirrors always reflect local instances | 259 // LocalInstanceMirrors always reflect local instances |
| 260 bool hasReflectee = true; | 260 bool hasReflectee = true; |
| 261 | 261 |
| 262 get reflectee => _reflectee; | 262 get reflectee => _reflectee; |
| 263 | 263 |
| 264 delegate(Invocation invocation) { | 264 delegate(Invocation invocation) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 static _apply(reflectee, positionalArguments) | 353 static _apply(reflectee, positionalArguments) |
| 354 native 'ClosureMirror_apply'; | 354 native 'ClosureMirror_apply'; |
| 355 | 355 |
| 356 static _computeFunction(reflectee) | 356 static _computeFunction(reflectee) |
| 357 native 'ClosureMirror_function'; | 357 native 'ClosureMirror_function'; |
| 358 } | 358 } |
| 359 | 359 |
| 360 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl | 360 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl |
| 361 implements ClassMirror { | 361 implements ClassMirror { |
| 362 _LocalClassMirrorImpl(reflectee, | 362 _LocalClassMirrorImpl(reflectee, |
| 363 String simpleName) | 363 this._reflectedType, |
| 364 String simpleName, |
| 365 this._isGeneric) |
| 364 : this._simpleName = _s(simpleName), | 366 : this._simpleName = _s(simpleName), |
| 365 super(reflectee); | 367 super(reflectee); |
| 366 | 368 |
| 369 final Type _reflectedType; |
| 370 final bool _isGeneric; |
| 371 |
| 367 Symbol _simpleName; | 372 Symbol _simpleName; |
| 368 Symbol get simpleName { | 373 Symbol get simpleName { |
| 369 // 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 |
| 370 // constructor. | 375 // constructor. |
| 371 if(_simpleName == null) { | 376 if(_simpleName == null) { |
| 372 _simpleName = _s(_name(_reflectee)); | 377 _simpleName = _s(_name(_reflectee)); |
| 373 } | 378 } |
| 374 return _simpleName; | 379 return _simpleName; |
| 375 } | 380 } |
| 376 | 381 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 var mirror; | 499 var mirror; |
| 495 for (var i = 0; i < params.length; i += 2) { | 500 for (var i = 0; i < params.length; i += 2) { |
| 496 mirror = new _LocalTypeVariableMirrorImpl( | 501 mirror = new _LocalTypeVariableMirrorImpl( |
| 497 params[i + 1], params[i], this); | 502 params[i + 1], params[i], this); |
| 498 _typeVariables[mirror.simpleName] = mirror; | 503 _typeVariables[mirror.simpleName] = mirror; |
| 499 } | 504 } |
| 500 } | 505 } |
| 501 return _typeVariables; | 506 return _typeVariables; |
| 502 } | 507 } |
| 503 | 508 |
| 509 Map<Symbol, TypeMirror> _typeArguments = null; |
| 504 Map<Symbol, TypeMirror> get typeArguments { | 510 Map<Symbol, TypeMirror> get typeArguments { |
| 505 throw new UnimplementedError( | 511 if(_typeArguments == null) { |
| 506 'ClassMirror.typeArguments is not implemented'); | 512 if(_reflectedType == null) { |
| 513 _typeArguments = new LinkedHashMap<Symbol, TypeMirror>(); |
| 514 } else { |
| 515 _typeArguments = |
| 516 new LinkedHashMap<Symbol, TypeMirror>.fromIterables(typeVariables.ke
ys, |
| 517 _computeTypeArgu
ments(_reflectedType)); |
| 518 } |
| 519 } |
| 520 return _typeArguments; |
| 507 } | 521 } |
| 508 | 522 |
| 509 bool get isOriginalDeclaration { | 523 bool get isOriginalDeclaration { |
| 510 throw new UnimplementedError( | 524 return !_isGeneric || _reflectedType == null; |
| 511 'ClassMirror.isOriginalDeclaration is not implemented'); | |
| 512 } | 525 } |
| 513 | 526 |
| 514 ClassMirror get genericDeclaration { | 527 ClassMirror get originalDeclaration { |
| 515 throw new UnimplementedError( | 528 if (isOriginalDeclaration) { |
| 516 'ClassMirror.originalDeclaration is not implemented'); | 529 return this; |
| 530 } else { |
| 531 return reflectClass(_reflectedType); |
| 532 } |
| 517 } | 533 } |
| 518 | 534 |
| 519 String toString() { | 535 String toString() { |
| 520 return "ClassMirror on '${_n(simpleName)}'"; | 536 return "ClassMirror on '${_n(simpleName)}'"; |
| 521 } | 537 } |
| 522 | 538 |
| 523 InstanceMirror newInstance(Symbol constructorName, | 539 InstanceMirror newInstance(Symbol constructorName, |
| 524 List positionalArguments, | 540 List positionalArguments, |
| 525 [Map<Symbol, dynamic> namedArguments]) { | 541 [Map<Symbol, dynamic> namedArguments]) { |
| 526 if (namedArguments != null) { | 542 if (namedArguments != null) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 551 } | 567 } |
| 552 | 568 |
| 553 List<InstanceMirror> get metadata { | 569 List<InstanceMirror> get metadata { |
| 554 // Get the metadata objects, convert them into InstanceMirrors using | 570 // Get the metadata objects, convert them into InstanceMirrors using |
| 555 // reflect() and then make them into a Dart list. | 571 // reflect() and then make them into a Dart list. |
| 556 return _metadata(_reflectee).map(reflect).toList(growable:false); | 572 return _metadata(_reflectee).map(reflect).toList(growable:false); |
| 557 } | 573 } |
| 558 | 574 |
| 559 bool operator ==(other) { | 575 bool operator ==(other) { |
| 560 return this.runtimeType == other.runtimeType && | 576 return this.runtimeType == other.runtimeType && |
| 561 this._reflectee == other._reflectee; | 577 this._reflectee == other._reflectee && |
| 578 (isOriginalDeclaration || |
| 579 this._reflectedType == other._reflectedType); |
| 562 } | 580 } |
| 563 | 581 |
| 564 int get hashCode => simpleName.hashCode; | 582 int get hashCode => simpleName.hashCode; |
| 565 | 583 |
| 566 static _name(reflectee) | 584 static _name(reflectee) |
| 567 native "ClassMirror_name"; | 585 native "ClassMirror_name"; |
| 568 | 586 |
| 569 static _library(reflectee) | 587 static _library(reflectee) |
| 570 native "ClassMirror_library"; | 588 native "ClassMirror_library"; |
| 571 | 589 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 588 native 'ClassMirror_invokeGetter'; | 606 native 'ClassMirror_invokeGetter'; |
| 589 | 607 |
| 590 _invokeSetter(reflectee, setterName, value) | 608 _invokeSetter(reflectee, setterName, value) |
| 591 native 'ClassMirror_invokeSetter'; | 609 native 'ClassMirror_invokeSetter'; |
| 592 | 610 |
| 593 static _invokeConstructor(reflectee, constructorName, positionalArguments) | 611 static _invokeConstructor(reflectee, constructorName, positionalArguments) |
| 594 native 'ClassMirror_invokeConstructor'; | 612 native 'ClassMirror_invokeConstructor'; |
| 595 | 613 |
| 596 static _ClassMirror_type_variables(reflectee) | 614 static _ClassMirror_type_variables(reflectee) |
| 597 native "ClassMirror_type_variables"; | 615 native "ClassMirror_type_variables"; |
| 616 |
| 617 static _computeTypeArguments(reflectee) |
| 618 native "ClassMirror_type_arguments"; |
| 598 } | 619 } |
| 599 | 620 |
| 600 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl | 621 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl |
| 601 implements FunctionTypeMirror { | 622 implements FunctionTypeMirror { |
| 602 _LocalFunctionTypeMirrorImpl(reflectee) : super(reflectee, null); | 623 _LocalFunctionTypeMirrorImpl(reflectee, reflectedType) |
| 624 : super(reflectee, reflectedType, null, false); |
| 603 | 625 |
| 604 // FunctionTypeMirrors have a simpleName generated from their signature. | 626 // FunctionTypeMirrors have a simpleName generated from their signature. |
| 605 Symbol _simpleName = null; | 627 Symbol _simpleName = null; |
| 606 Symbol get simpleName { | 628 Symbol get simpleName { |
| 607 if (_simpleName == null) { | 629 if (_simpleName == null) { |
| 608 _simpleName = _s(_makeSignatureString(returnType, parameters)); | 630 _simpleName = _s(_makeSignatureString(returnType, parameters)); |
| 609 } | 631 } |
| 610 return _simpleName; | 632 return _simpleName; |
| 611 } | 633 } |
| 612 | 634 |
| 613 TypeMirror _returnType = null; | 635 TypeMirror _returnType = null; |
| 614 TypeMirror get returnType { | 636 TypeMirror get returnType { |
| 615 if (_returnType == null) { | 637 if (_returnType == null) { |
| 616 _returnType = _FunctionTypeMirror_return_type(_reflectee); | 638 _returnType = |
| 639 _Mirrors._reflectType(_FunctionTypeMirror_return_type(_reflectee)); |
| 617 } | 640 } |
| 618 return _returnType; | 641 return _returnType; |
| 619 } | 642 } |
| 620 | 643 |
| 621 List<ParameterMirror> _parameters = null; | 644 List<ParameterMirror> _parameters = null; |
| 622 List<ParameterMirror> get parameters { | 645 List<ParameterMirror> get parameters { |
| 623 if (_parameters == null) { | 646 if (_parameters == null) { |
| 624 _parameters = _FunctionTypeMirror_parameters(_reflectee); | 647 _parameters = _FunctionTypeMirror_parameters(_reflectee); |
| 625 } | 648 } |
| 626 return _parameters; | 649 return _parameters; |
| 627 } | 650 } |
| 628 | 651 |
| 629 Map<Symbol, Mirror> get members => new Map<Symbol,Mirror>(); | 652 Map<Symbol, Mirror> get members => new Map<Symbol,Mirror>(); |
| 630 Map<Symbol, MethodMirror> get constructors => new Map<Symbol,MethodMirror>(); | 653 Map<Symbol, MethodMirror> get constructors => new Map<Symbol,MethodMirror>(); |
| 631 final Map<Symbol, TypeVariableMirror> typeVariables = const {}; | 654 final Map<Symbol, TypeVariableMirror> typeVariables = const {}; |
| 632 | 655 |
| 633 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; | 656 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; |
| 634 | 657 |
| 635 static TypeMirror _FunctionTypeMirror_return_type(reflectee) | 658 static Type _FunctionTypeMirror_return_type(reflectee) |
| 636 native "FunctionTypeMirror_return_type"; | 659 native "FunctionTypeMirror_return_type"; |
| 637 | 660 |
| 638 static List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) | 661 static List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) |
| 639 native "FunctionTypeMirror_parameters"; | 662 native "FunctionTypeMirror_parameters"; |
| 640 } | 663 } |
| 641 | 664 |
| 642 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl | 665 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl |
| 643 implements DeclarationMirror { | 666 implements DeclarationMirror { |
| 644 _LocalDeclarationMirrorImpl(this._reflectee, this.simpleName); | 667 _LocalDeclarationMirrorImpl(this._reflectee, this.simpleName); |
| 645 | 668 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 672 class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl | 695 class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl |
| 673 implements TypeVariableMirror { | 696 implements TypeVariableMirror { |
| 674 _LocalTypeVariableMirrorImpl(reflectee, | 697 _LocalTypeVariableMirrorImpl(reflectee, |
| 675 String simpleName, | 698 String simpleName, |
| 676 this._owner) | 699 this._owner) |
| 677 : super(reflectee, _s(simpleName)); | 700 : super(reflectee, _s(simpleName)); |
| 678 | 701 |
| 679 DeclarationMirror _owner; | 702 DeclarationMirror _owner; |
| 680 DeclarationMirror get owner { | 703 DeclarationMirror get owner { |
| 681 if (_owner == null) { | 704 if (_owner == null) { |
| 682 _owner = _LocalTypeVariableMirror_owner(_reflectee); | 705 _owner = _TypeVariableMirror_owner(_reflectee); |
| 683 } | 706 } |
| 684 return _owner; | 707 return _owner; |
| 685 } | 708 } |
| 686 | 709 |
| 687 bool get isPrivate => false; | 710 bool get isPrivate => false; |
| 688 | 711 |
| 689 final bool isTopLevel = false; | 712 final bool isTopLevel = false; |
| 690 | 713 |
| 691 SourceLocation get location { | 714 SourceLocation get location { |
| 692 throw new UnimplementedError( | 715 throw new UnimplementedError( |
| 693 'TypeVariableMirror.location is not implemented'); | 716 'TypeVariableMirror.location is not implemented'); |
| 694 } | 717 } |
| 695 | 718 |
| 696 TypeMirror _upperBound = null; | 719 TypeMirror _upperBound = null; |
| 697 TypeMirror get upperBound { | 720 TypeMirror get upperBound { |
| 698 if (_upperBound == null) { | 721 if (_upperBound == null) { |
| 699 _upperBound = _LocalTypeVariableMirror_upper_bound(_reflectee); | 722 _upperBound = |
| 723 _Mirrors._reflectType(_TypeVariableMirror_upper_bound(_reflectee)); |
| 700 } | 724 } |
| 701 return _upperBound; | 725 return _upperBound; |
| 702 } | 726 } |
| 703 | 727 |
| 704 List<InstanceMirror> get metadata { | 728 List<InstanceMirror> get metadata { |
| 705 throw new UnimplementedError( | 729 throw new UnimplementedError( |
| 706 'TypeVariableMirror.metadata is not implemented'); | 730 'TypeVariableMirror.metadata is not implemented'); |
| 707 } | 731 } |
| 708 | 732 |
| 733 bool get isOriginalDeclaration => true; |
| 734 ClassMirror get originalDeclaration => this; |
| 735 |
| 709 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; | 736 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; |
| 710 | 737 |
| 711 static DeclarationMirror _LocalTypeVariableMirror_owner(reflectee) | 738 static DeclarationMirror _TypeVariableMirror_owner(reflectee) |
| 712 native "LocalTypeVariableMirror_owner"; | 739 native "TypeVariableMirror_owner"; |
| 713 | 740 |
| 714 static TypeMirror _LocalTypeVariableMirror_upper_bound(reflectee) | 741 static Type _TypeVariableMirror_upper_bound(reflectee) |
| 715 native "LocalTypeVariableMirror_upper_bound"; | 742 native "TypeVariableMirror_upper_bound"; |
| 716 } | 743 } |
| 717 | 744 |
| 718 | 745 |
| 719 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl | 746 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl |
| 720 implements TypedefMirror { | 747 implements TypedefMirror { |
| 721 _LocalTypedefMirrorImpl(reflectee, | 748 _LocalTypedefMirrorImpl(reflectee, |
| 722 String simpleName, | 749 String simpleName, |
| 723 this._owner) | 750 this._owner) |
| 724 : super(reflectee, _s(simpleName)); | 751 : super(reflectee, _s(simpleName)); |
| 725 | 752 |
| 753 // TODO(12282): Deal with generic typedefs. |
| 754 bool get _isGeneric => false; |
| 755 |
| 726 DeclarationMirror _owner; | 756 DeclarationMirror _owner; |
| 727 DeclarationMirror get owner { | 757 DeclarationMirror get owner { |
| 728 if (_owner == null) { | 758 if (_owner == null) { |
| 729 _owner = _LocalClassMirrorImpl._library(_reflectee); | 759 _owner = _LocalClassMirrorImpl._library(_reflectee); |
| 730 } | 760 } |
| 731 return _owner; | 761 return _owner; |
| 732 } | 762 } |
| 733 | 763 |
| 734 bool get isPrivate => false; | 764 bool get isPrivate => false; |
| 735 | 765 |
| 736 final bool isTopLevel = true; | 766 final bool isTopLevel = true; |
| 737 | 767 |
| 738 SourceLocation get location { | 768 SourceLocation get location { |
| 739 throw new UnimplementedError( | 769 throw new UnimplementedError( |
| 740 'TypedefMirror.location is not implemented'); | 770 'TypedefMirror.location is not implemented'); |
| 741 } | 771 } |
| 742 | 772 |
| 743 TypeMirror _referent = null; | 773 TypeMirror _referent = null; |
| 744 TypeMirror get referent { | 774 TypeMirror get referent { |
| 745 if (_referent == null) { | 775 if (_referent == null) { |
| 776 // TODO(12282): Deal with generic typedef. |
| 746 return new _LocalFunctionTypeMirrorImpl( | 777 return new _LocalFunctionTypeMirrorImpl( |
| 747 _TypedefMirror_referent(_reflectee)); | 778 _TypedefMirror_referent(_reflectee), null); |
| 748 } | 779 } |
| 749 return _referent; | 780 return _referent; |
| 750 } | 781 } |
| 751 | 782 |
| 752 String toString() => "TypedefMirror on '${_n(simpleName)}'"; | 783 String toString() => "TypedefMirror on '${_n(simpleName)}'"; |
| 753 | 784 |
| 754 static _TypedefMirror_referent(_reflectee) | 785 static _TypedefMirror_referent(_reflectee) |
| 755 native "TypedefMirror_referent"; | 786 native "TypedefMirror_referent"; |
| 756 } | 787 } |
| 757 | 788 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 throw new UnimplementedError( | 936 throw new UnimplementedError( |
| 906 'MethodMirror.location is not implemented'); | 937 'MethodMirror.location is not implemented'); |
| 907 } | 938 } |
| 908 | 939 |
| 909 TypeMirror _returnType = null; | 940 TypeMirror _returnType = null; |
| 910 TypeMirror get returnType { | 941 TypeMirror get returnType { |
| 911 if (_returnType == null) { | 942 if (_returnType == null) { |
| 912 if (isConstructor) { | 943 if (isConstructor) { |
| 913 _returnType = owner; | 944 _returnType = owner; |
| 914 } else { | 945 } else { |
| 915 _returnType = _MethodMirror_return_type(_reflectee); | 946 _returnType = |
| 947 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee)); |
| 916 } | 948 } |
| 917 } | 949 } |
| 918 return _returnType; | 950 return _returnType; |
| 919 } | 951 } |
| 920 | 952 |
| 921 List<ParameterMirror> _parameters = null; | 953 List<ParameterMirror> _parameters = null; |
| 922 List<ParameterMirror> get parameters { | 954 List<ParameterMirror> get parameters { |
| 923 if (_parameters == null) { | 955 if (_parameters == null) { |
| 924 _parameters = _MethodMirror_parameters(_reflectee); | 956 _parameters = _MethodMirror_parameters(_reflectee); |
| 925 } | 957 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 } | 1031 } |
| 1000 | 1032 |
| 1001 SourceLocation get location { | 1033 SourceLocation get location { |
| 1002 throw new UnimplementedError( | 1034 throw new UnimplementedError( |
| 1003 'VariableMirror.location is not implemented'); | 1035 'VariableMirror.location is not implemented'); |
| 1004 } | 1036 } |
| 1005 | 1037 |
| 1006 TypeMirror _type; | 1038 TypeMirror _type; |
| 1007 TypeMirror get type { | 1039 TypeMirror get type { |
| 1008 if (_type == null) { | 1040 if (_type == null) { |
| 1009 _type = _VariableMirror_type(_reflectee); | 1041 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee)); |
| 1010 } | 1042 } |
| 1011 return _type; | 1043 return _type; |
| 1012 } | 1044 } |
| 1013 | 1045 |
| 1014 final bool isStatic; | 1046 final bool isStatic; |
| 1015 final bool isFinal; | 1047 final bool isFinal; |
| 1016 | 1048 |
| 1017 String toString() => "VariableMirror on '${_n(simpleName)}'"; | 1049 String toString() => "VariableMirror on '${_n(simpleName)}'"; |
| 1018 | 1050 |
| 1019 static _VariableMirror_type(reflectee) | 1051 static _VariableMirror_type(reflectee) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1043 | 1075 |
| 1044 // TODO(11418): Implement. | 1076 // TODO(11418): Implement. |
| 1045 List<InstanceMirror> get metadata { | 1077 List<InstanceMirror> get metadata { |
| 1046 throw new UnimplementedError( | 1078 throw new UnimplementedError( |
| 1047 'ParameterMirror.metadata is not implemented'); | 1079 'ParameterMirror.metadata is not implemented'); |
| 1048 } | 1080 } |
| 1049 | 1081 |
| 1050 TypeMirror _type = null; | 1082 TypeMirror _type = null; |
| 1051 TypeMirror get type { | 1083 TypeMirror get type { |
| 1052 if (_type == null) { | 1084 if (_type == null) { |
| 1053 _type = _ParameterMirror_type(_reflectee, _position); | 1085 _type = |
| 1086 _Mirrors._reflectType(_ParameterMirror_type(_reflectee, _position)); |
| 1054 } | 1087 } |
| 1055 return _type; | 1088 return _type; |
| 1056 } | 1089 } |
| 1057 | 1090 |
| 1058 static TypeMirror _ParameterMirror_type(_reflectee, _position) | 1091 static Type _ParameterMirror_type(_reflectee, _position) |
| 1059 native "ParameterMirror_type"; | 1092 native "ParameterMirror_type"; |
| 1060 } | 1093 } |
| 1061 | 1094 |
| 1062 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl | 1095 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl |
| 1063 implements TypeMirror, DeclarationMirror { | 1096 implements TypeMirror, DeclarationMirror { |
| 1064 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); | 1097 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); |
| 1065 | 1098 |
| 1066 final bool isPrivate = false; | 1099 final bool isPrivate = false; |
| 1067 final bool isTopLevel = true; | 1100 final bool isTopLevel = true; |
| 1068 | 1101 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 } | 1161 } |
| 1129 } | 1162 } |
| 1130 | 1163 |
| 1131 // Creates a new local mirror for some Object. | 1164 // Creates a new local mirror for some Object. |
| 1132 static InstanceMirror reflect(Object reflectee) { | 1165 static InstanceMirror reflect(Object reflectee) { |
| 1133 return reflectee is Function | 1166 return reflectee is Function |
| 1134 ? new _LocalClosureMirrorImpl(reflectee) | 1167 ? new _LocalClosureMirrorImpl(reflectee) |
| 1135 : new _LocalInstanceMirrorImpl(reflectee); | 1168 : new _LocalInstanceMirrorImpl(reflectee); |
| 1136 } | 1169 } |
| 1137 | 1170 |
| 1138 // Creates a new local ClassMirror. | |
| 1139 static ClassMirror makeLocalClassMirror(Type key) | 1171 static ClassMirror makeLocalClassMirror(Type key) |
| 1140 native "Mirrors_makeLocalClassMirror"; | 1172 native "Mirrors_makeLocalClassMirror"; |
| 1173 static TypeMirror makeLocalTypeMirror(Type key) |
| 1174 native "Mirrors_makeLocalTypeMirror"; |
| 1141 | 1175 |
| 1142 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); | 1176 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror"); |
| 1177 static Expando<ClassMirror> _instanitationCache = new Expando("TypeMirror"); |
| 1178 |
| 1143 static ClassMirror reflectClass(Type key) { | 1179 static ClassMirror reflectClass(Type key) { |
| 1144 var classMirror = _classMirrorCache[key]; | 1180 var classMirror = _declarationCache[key]; |
| 1145 if (classMirror == null) { | 1181 if (classMirror == null) { |
| 1146 classMirror = makeLocalClassMirror(key); | 1182 classMirror = makeLocalClassMirror(key); |
| 1147 _classMirrorCache[key] = classMirror; | 1183 _declarationCache[key] = classMirror; |
| 1184 if (!classMirror._isGeneric) { |
| 1185 _instanitationCache[key] = classMirror; |
| 1186 } |
| 1148 } | 1187 } |
| 1149 return classMirror; | 1188 return classMirror; |
| 1150 } | 1189 } |
| 1190 |
| 1191 static TypeMirror _reflectType(Type key) { |
| 1192 var typeMirror = _instanitationCache[key]; |
| 1193 if (typeMirror == null) { |
| 1194 typeMirror = makeLocalTypeMirror(key); |
| 1195 _instanitationCache[key] = typeMirror; |
| 1196 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
| 1197 _declarationCache[key] = typeMirror; |
| 1198 } |
| 1199 } |
| 1200 return typeMirror; |
| 1201 } |
| 1151 } | 1202 } |
| OLD | NEW |