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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 var result = _invokeConstructor(_reflectee, | 558 var result = _invokeConstructor(_reflectee, |
559 _n(constructorName), | 559 _n(constructorName), |
560 _unwarpAsyncPositionals(positionalArgument
s)); | 560 _unwarpAsyncPositionals(positionalArgument
s)); |
561 return new Future.value(reflect(result)); | 561 return new Future.value(reflect(result)); |
562 } on MirroredError catch(e) { | 562 } on MirroredError catch(e) { |
563 return new Future.error(e); | 563 return new Future.error(e); |
564 } | 564 } |
565 } | 565 } |
566 | 566 |
567 List<InstanceMirror> get metadata { | 567 List<InstanceMirror> get metadata { |
568 // get the metadata objects, convert them into InstanceMirrors using | 568 // Get the metadata objects, convert them into InstanceMirrors using |
569 // reflect() and then make them into a Dart list | 569 // reflect() and then make them into a Dart list. |
570 return _metadata(_reflectee).map(reflect).toList(); | 570 return _metadata(_reflectee).map(reflect).toList(growable:false); |
571 } | 571 } |
572 | 572 |
573 static _name(reflectee) | 573 static _name(reflectee) |
574 native "ClassMirror_name"; | 574 native "ClassMirror_name"; |
575 | 575 |
576 _invoke(reflectee, memberName, positionalArguments) | 576 _invoke(reflectee, memberName, positionalArguments) |
577 native 'ClassMirror_invoke'; | 577 native 'ClassMirror_invoke'; |
578 | 578 |
579 _invokeGetter(reflectee, getterName) | 579 _invokeGetter(reflectee, getterName) |
580 native 'ClassMirror_invokeGetter'; | 580 native 'ClassMirror_invokeGetter'; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 _returnType = _returnType.resolve(mirrors); | 621 _returnType = _returnType.resolve(mirrors); |
622 } | 622 } |
623 return _returnType; | 623 return _returnType; |
624 } | 624 } |
625 | 625 |
626 final List<ParameterMirror> parameters; | 626 final List<ParameterMirror> parameters; |
627 | 627 |
628 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; | 628 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; |
629 } | 629 } |
630 | 630 |
| 631 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl |
| 632 implements DeclarationMirror { |
| 633 _LocalDeclarationMirrorImpl(this._reflectee); |
| 634 final _MirrorReference _reflectee; |
| 635 |
| 636 List<InstanceMirror> get metadata { |
| 637 // Get the metadata objects, convert them into InstanceMirrors using |
| 638 // reflect() and then make them into a Dart list. |
| 639 return _metadata(_reflectee).map(reflect).toList(growable:false); |
| 640 } |
| 641 } |
631 | 642 |
632 class _LazyTypeVariableMirror { | 643 class _LazyTypeVariableMirror { |
633 _LazyTypeVariableMirror(String variableName, this._owner) | 644 _LazyTypeVariableMirror(String variableName, this._owner) |
634 : this._variableName = _s(variableName); | 645 : this._variableName = _s(variableName); |
635 | 646 |
636 TypeVariableMirror resolve(MirrorSystem mirrors) { | 647 TypeVariableMirror resolve(MirrorSystem mirrors) { |
637 ClassMirror owner = _owner.resolve(mirrors); | 648 ClassMirror owner = _owner.resolve(mirrors); |
638 return owner.typeVariables[_variableName]; | 649 return owner.typeVariables[_variableName]; |
639 } | 650 } |
640 | 651 |
641 final Symbol _variableName; | 652 final Symbol _variableName; |
642 final _LazyTypeMirror _owner; | 653 final _LazyTypeMirror _owner; |
643 } | 654 } |
644 | 655 |
645 class _LocalTypeVariableMirrorImpl extends _LocalMirrorImpl | 656 class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl |
646 implements TypeVariableMirror { | 657 implements TypeVariableMirror { |
647 _LocalTypeVariableMirrorImpl(String simpleName, | 658 _LocalTypeVariableMirrorImpl(reflectee, |
| 659 String simpleName, |
648 this._owner, | 660 this._owner, |
649 this._upperBound) | 661 this._upperBound) |
650 : this.simpleName = _s(simpleName); | 662 : this.simpleName = _s(simpleName), |
| 663 super(reflectee); |
651 | 664 |
652 final Symbol simpleName; | 665 final Symbol simpleName; |
653 | 666 |
654 Symbol _qualifiedName = null; | 667 Symbol _qualifiedName = null; |
655 Symbol get qualifiedName { | 668 Symbol get qualifiedName { |
656 if (_qualifiedName == null) { | 669 if (_qualifiedName == null) { |
657 _qualifiedName = _computeQualifiedName(owner, simpleName); | 670 _qualifiedName = _computeQualifiedName(owner, simpleName); |
658 } | 671 } |
659 return _qualifiedName; | 672 return _qualifiedName; |
660 } | 673 } |
(...skipping 25 matching lines...) Expand all Loading... |
686 | 699 |
687 List<InstanceMirror> get metadata { | 700 List<InstanceMirror> get metadata { |
688 throw new UnimplementedError( | 701 throw new UnimplementedError( |
689 'TypeVariableMirror.metadata is not implemented'); | 702 'TypeVariableMirror.metadata is not implemented'); |
690 } | 703 } |
691 | 704 |
692 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; | 705 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; |
693 } | 706 } |
694 | 707 |
695 | 708 |
696 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl | 709 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl |
697 implements TypedefMirror { | 710 implements TypedefMirror { |
698 _LocalTypedefMirrorImpl(String simpleName, | 711 _LocalTypedefMirrorImpl(reflectee, |
| 712 String simpleName, |
699 this._owner, | 713 this._owner, |
700 this._referent) | 714 this._referent) |
701 : this.simpleName = _s(simpleName); | 715 : this.simpleName = _s(simpleName), |
| 716 super(reflectee); |
702 | 717 |
703 final Symbol simpleName; | 718 final Symbol simpleName; |
704 | 719 |
705 Symbol _qualifiedName = null; | 720 Symbol _qualifiedName = null; |
706 Symbol get qualifiedName { | 721 Symbol get qualifiedName { |
707 if (_qualifiedName == null) { | 722 if (_qualifiedName == null) { |
708 _qualifiedName = _computeQualifiedName(owner, simpleName); | 723 _qualifiedName = _computeQualifiedName(owner, simpleName); |
709 } | 724 } |
710 return _qualifiedName; | 725 return _qualifiedName; |
711 } | 726 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 | 837 |
823 Map<Symbol, VariableMirror> get variables { | 838 Map<Symbol, VariableMirror> get variables { |
824 if (_variables == null) { | 839 if (_variables == null) { |
825 _variables = _filterMap(members, | 840 _variables = _filterMap(members, |
826 (key, value) => (value is VariableMirror)); | 841 (key, value) => (value is VariableMirror)); |
827 } | 842 } |
828 return _variables; | 843 return _variables; |
829 } | 844 } |
830 | 845 |
831 List<InstanceMirror> get metadata { | 846 List<InstanceMirror> get metadata { |
832 // get the metadata objects, convert them into InstanceMirrors using | 847 // Get the metadata objects, convert them into InstanceMirrors using |
833 // reflect() and then make them into a Dart list | 848 // reflect() and then make them into a Dart list. |
834 _metadata(_reflectee).map(reflect).toList(); | 849 return _metadata(_reflectee).map(reflect).toList(growable:false); |
835 } | 850 } |
836 | 851 |
837 String toString() => "LibraryMirror on '${_n(simpleName)}'"; | 852 String toString() => "LibraryMirror on '${_n(simpleName)}'"; |
838 | 853 |
839 _invoke(reflectee, memberName, positionalArguments) | 854 _invoke(reflectee, memberName, positionalArguments) |
840 native 'LibraryMirror_invoke'; | 855 native 'LibraryMirror_invoke'; |
841 | 856 |
842 _invokeGetter(reflectee, getterName) | 857 _invokeGetter(reflectee, getterName) |
843 native 'LibraryMirror_invokeGetter'; | 858 native 'LibraryMirror_invokeGetter'; |
844 | 859 |
845 _invokeSetter(reflectee, setterName, value) | 860 _invokeSetter(reflectee, setterName, value) |
846 native 'LibraryMirror_invokeSetter'; | 861 native 'LibraryMirror_invokeSetter'; |
847 } | 862 } |
848 | 863 |
849 class _LocalMethodMirrorImpl extends _LocalMirrorImpl | 864 class _LocalMethodMirrorImpl extends _LocalDeclarationMirrorImpl |
850 implements MethodMirror { | 865 implements MethodMirror { |
851 _LocalMethodMirrorImpl(this._reflectee, | 866 _LocalMethodMirrorImpl(reflectee, |
852 this._owner, | 867 this._owner, |
853 this.parameters, | 868 this.parameters, |
854 this._returnType, | 869 this._returnType, |
855 this.isStatic, | 870 this.isStatic, |
856 this.isAbstract, | 871 this.isAbstract, |
857 this.isGetter, | 872 this.isGetter, |
858 this.isSetter, | 873 this.isSetter, |
859 this.isConstructor, | 874 this.isConstructor, |
860 this.isConstConstructor, | 875 this.isConstConstructor, |
861 this.isGenerativeConstructor, | 876 this.isGenerativeConstructor, |
862 this.isRedirectingConstructor, | 877 this.isRedirectingConstructor, |
863 this.isFactoryConstructor); | 878 this.isFactoryConstructor) : super(reflectee); |
864 | |
865 final _MirrorReference _reflectee; | |
866 | 879 |
867 Symbol _simpleName = null; | 880 Symbol _simpleName = null; |
868 Symbol get simpleName { | 881 Symbol get simpleName { |
869 if (_simpleName == null) { | 882 if (_simpleName == null) { |
870 _simpleName = _s(_MethodMirror_name(_reflectee)); | 883 _simpleName = _s(_MethodMirror_name(_reflectee)); |
871 } | 884 } |
872 return _simpleName; | 885 return _simpleName; |
873 } | 886 } |
874 | 887 |
875 Symbol _qualifiedName = null; | 888 Symbol _qualifiedName = null; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 } | 962 } |
950 } | 963 } |
951 return _constructorName; | 964 return _constructorName; |
952 } | 965 } |
953 | 966 |
954 final bool isConstConstructor; | 967 final bool isConstConstructor; |
955 final bool isGenerativeConstructor; | 968 final bool isGenerativeConstructor; |
956 final bool isRedirectingConstructor; | 969 final bool isRedirectingConstructor; |
957 final bool isFactoryConstructor; | 970 final bool isFactoryConstructor; |
958 | 971 |
959 List<InstanceMirror> get metadata { | |
960 owner; // ensure owner is computed | |
961 // get the metadata objects, convert them into InstanceMirrors using | |
962 // reflect() and then make them into a Dart list | |
963 return _metadata(_reflectee).map(reflect).toList(); | |
964 } | |
965 | |
966 String toString() => "MethodMirror on '${_n(simpleName)}'"; | 972 String toString() => "MethodMirror on '${_n(simpleName)}'"; |
967 | 973 |
968 static String _MethodMirror_name(reflectee) | 974 static String _MethodMirror_name(reflectee) |
969 native "MethodMirror_name"; | 975 native "MethodMirror_name"; |
970 | 976 |
971 static dynamic _MethodMirror_owner(reflectee) | 977 static dynamic _MethodMirror_owner(reflectee) |
972 native "MethodMirror_owner"; | 978 native "MethodMirror_owner"; |
973 } | 979 } |
974 | 980 |
975 class _LocalVariableMirrorImpl extends _LocalMirrorImpl | 981 class _LocalVariableMirrorImpl extends _LocalDeclarationMirrorImpl |
976 implements VariableMirror { | 982 implements VariableMirror { |
977 _LocalVariableMirrorImpl(this._reflectee, | 983 _LocalVariableMirrorImpl(reflectee, |
978 String simpleName, | 984 String simpleName, |
979 this._owner, | 985 this._owner, |
980 this._type, | 986 this._type, |
981 this.isStatic, | 987 this.isStatic, |
982 this.isFinal) | 988 this.isFinal) |
983 : this.simpleName = _s(simpleName); | 989 : this.simpleName = _s(simpleName), |
| 990 super(reflectee); |
984 | 991 |
985 final _MirrorReference _reflectee; | |
986 final Symbol simpleName; | 992 final Symbol simpleName; |
987 | 993 |
988 Symbol _qualifiedName = null; | 994 Symbol _qualifiedName = null; |
989 Symbol get qualifiedName { | 995 Symbol get qualifiedName { |
990 if (_qualifiedName == null) { | 996 if (_qualifiedName == null) { |
991 _qualifiedName = _computeQualifiedName(owner, simpleName); | 997 _qualifiedName = _computeQualifiedName(owner, simpleName); |
992 } | 998 } |
993 return _qualifiedName; | 999 return _qualifiedName; |
994 } | 1000 } |
995 | 1001 |
(...skipping 22 matching lines...) Expand all Loading... |
1018 TypeMirror get type { | 1024 TypeMirror get type { |
1019 if (_type is! Mirror) { | 1025 if (_type is! Mirror) { |
1020 _type = _type.resolve(mirrors); | 1026 _type = _type.resolve(mirrors); |
1021 } | 1027 } |
1022 return _type; | 1028 return _type; |
1023 } | 1029 } |
1024 | 1030 |
1025 final bool isStatic; | 1031 final bool isStatic; |
1026 final bool isFinal; | 1032 final bool isFinal; |
1027 | 1033 |
1028 List<InstanceMirror> get metadata { | |
1029 // get the metadata objects, convert them into InstanceMirrors using | |
1030 // reflect() and then make them into a Dart list | |
1031 return _metadata(_reflectee).map(reflect).toList(); | |
1032 } | |
1033 | |
1034 String toString() => "VariableMirror on '${_n(simpleName)}'"; | 1034 String toString() => "VariableMirror on '${_n(simpleName)}'"; |
1035 } | 1035 } |
1036 | 1036 |
1037 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl | 1037 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl |
1038 implements ParameterMirror { | 1038 implements ParameterMirror { |
1039 _LocalParameterMirrorImpl(type, this.isOptional) | 1039 _LocalParameterMirrorImpl(type, this.isOptional) |
1040 : super(null, '<TODO:unnamed>', null, type, false, false) {} | 1040 : super(null, '<TODO:unnamed>', null, type, false, false) {} |
1041 | 1041 |
1042 final bool isOptional; | 1042 final bool isOptional; |
1043 | 1043 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); | 1132 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); |
1133 static ClassMirror reflectClass(Type key) { | 1133 static ClassMirror reflectClass(Type key) { |
1134 var classMirror = _classMirrorCache[key]; | 1134 var classMirror = _classMirrorCache[key]; |
1135 if (classMirror == null) { | 1135 if (classMirror == null) { |
1136 classMirror = makeLocalClassMirror(key); | 1136 classMirror = makeLocalClassMirror(key); |
1137 _classMirrorCache[key] = classMirror; | 1137 _classMirrorCache[key] = classMirror; |
1138 } | 1138 } |
1139 return classMirror; | 1139 return classMirror; |
1140 } | 1140 } |
1141 } | 1141 } |
OLD | NEW |