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 610 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 | |
siva
2013/07/18 20:46:15
"Get"
| |
638 // reflect() and then make them into a Dart list | |
siva
2013/07/18 20:46:15
missing "."
| |
639 return _metadata(_reflectee).map(reflect).toList(); | |
siva
2013/07/18 20:46:15
toList(false) here? does it need to be a growable
rmacnak
2013/07/18 21:04:50
Switched to fixed size.
| |
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 } | 956 } |
944 } | 957 } |
945 return _constructorName; | 958 return _constructorName; |
946 } | 959 } |
947 | 960 |
948 final bool isConstConstructor; | 961 final bool isConstConstructor; |
949 final bool isGenerativeConstructor; | 962 final bool isGenerativeConstructor; |
950 final bool isRedirectingConstructor; | 963 final bool isRedirectingConstructor; |
951 final bool isFactoryConstructor; | 964 final bool isFactoryConstructor; |
952 | 965 |
953 List<InstanceMirror> get metadata { | |
954 owner; // ensure owner is computed | |
955 // get the metadata objects, convert them into InstanceMirrors using | |
956 // reflect() and then make them into a Dart list | |
957 return _metadata(_reflectee).map(reflect).toList(); | |
958 } | |
959 | |
960 String toString() => "MethodMirror on '${_n(simpleName)}'"; | 966 String toString() => "MethodMirror on '${_n(simpleName)}'"; |
961 | 967 |
962 static String _MethodMirror_name(reflectee) | 968 static String _MethodMirror_name(reflectee) |
963 native "MethodMirror_name"; | 969 native "MethodMirror_name"; |
964 } | 970 } |
965 | 971 |
966 class _LocalVariableMirrorImpl extends _LocalMirrorImpl | 972 class _LocalVariableMirrorImpl extends _LocalDeclarationMirrorImpl |
967 implements VariableMirror { | 973 implements VariableMirror { |
968 _LocalVariableMirrorImpl(this._reflectee, | 974 _LocalVariableMirrorImpl(reflectee, |
969 String simpleName, | 975 String simpleName, |
970 this._owner, | 976 this._owner, |
971 this._type, | 977 this._type, |
972 this.isStatic, | 978 this.isStatic, |
973 this.isFinal) | 979 this.isFinal) |
974 : this.simpleName = _s(simpleName); | 980 : this.simpleName = _s(simpleName), |
981 super(reflectee); | |
975 | 982 |
976 final _MirrorReference _reflectee; | |
977 final Symbol simpleName; | 983 final Symbol simpleName; |
978 | 984 |
979 Symbol _qualifiedName = null; | 985 Symbol _qualifiedName = null; |
980 Symbol get qualifiedName { | 986 Symbol get qualifiedName { |
981 if (_qualifiedName == null) { | 987 if (_qualifiedName == null) { |
982 _qualifiedName = _computeQualifiedName(owner, simpleName); | 988 _qualifiedName = _computeQualifiedName(owner, simpleName); |
983 } | 989 } |
984 return _qualifiedName; | 990 return _qualifiedName; |
985 } | 991 } |
986 | 992 |
(...skipping 22 matching lines...) Expand all Loading... | |
1009 TypeMirror get type { | 1015 TypeMirror get type { |
1010 if (_type is! Mirror) { | 1016 if (_type is! Mirror) { |
1011 _type = _type.resolve(mirrors); | 1017 _type = _type.resolve(mirrors); |
1012 } | 1018 } |
1013 return _type; | 1019 return _type; |
1014 } | 1020 } |
1015 | 1021 |
1016 final bool isStatic; | 1022 final bool isStatic; |
1017 final bool isFinal; | 1023 final bool isFinal; |
1018 | 1024 |
1019 List<InstanceMirror> get metadata { | |
1020 // get the metadata objects, convert them into InstanceMirrors using | |
1021 // reflect() and then make them into a Dart list | |
1022 return _metadata(_reflectee).map(reflect).toList(); | |
1023 } | |
1024 | |
1025 String toString() => "VariableMirror on '${_n(simpleName)}'"; | 1025 String toString() => "VariableMirror on '${_n(simpleName)}'"; |
1026 } | 1026 } |
1027 | 1027 |
1028 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl | 1028 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl |
1029 implements ParameterMirror { | 1029 implements ParameterMirror { |
1030 _LocalParameterMirrorImpl(type, this.isOptional) | 1030 _LocalParameterMirrorImpl(type, this.isOptional) |
1031 : super(null, '<TODO:unnamed>', null, type, false, false) {} | 1031 : super(null, '<TODO:unnamed>', null, type, false, false) {} |
1032 | 1032 |
1033 final bool isOptional; | 1033 final bool isOptional; |
1034 | 1034 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1117 } | 1117 } |
1118 | 1118 |
1119 // Creates a new local ClassMirror. | 1119 // Creates a new local ClassMirror. |
1120 static ClassMirror makeLocalClassMirror(Type key) | 1120 static ClassMirror makeLocalClassMirror(Type key) |
1121 native "Mirrors_makeLocalClassMirror"; | 1121 native "Mirrors_makeLocalClassMirror"; |
1122 | 1122 |
1123 static ClassMirror reflectClass(Type key) { | 1123 static ClassMirror reflectClass(Type key) { |
1124 return makeLocalClassMirror(key); | 1124 return makeLocalClassMirror(key); |
1125 } | 1125 } |
1126 } | 1126 } |
OLD | NEW |