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 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 | 860 |
861 _invokeSetter(reflectee, setterName, value) | 861 _invokeSetter(reflectee, setterName, value) |
862 native 'LibraryMirror_invokeSetter'; | 862 native 'LibraryMirror_invokeSetter'; |
863 } | 863 } |
864 | 864 |
865 class _LocalMethodMirrorImpl extends _LocalMirrorImpl | 865 class _LocalMethodMirrorImpl extends _LocalMirrorImpl |
866 implements MethodMirror { | 866 implements MethodMirror { |
867 _LocalMethodMirrorImpl(this._reflectee, | 867 _LocalMethodMirrorImpl(this._reflectee, |
868 this._owner, | 868 this._owner, |
869 this.parameters, | 869 this.parameters, |
870 this._returnType, | 870 this._returnType); |
871 this.isStatic, | |
872 this.isAbstract, | |
873 this.isGetter, | |
874 this.isSetter, | |
875 this.isConstructor, | |
876 this.isConstConstructor, | |
877 this.isGenerativeConstructor, | |
878 this.isRedirectingConstructor, | |
879 this.isFactoryConstructor); | |
880 | 871 |
881 final _MirrorReference _reflectee; | 872 final _MirrorReference _reflectee; |
882 | 873 |
| 874 // Keep in sync with MethodMirrorProperty in mirrors.cc. |
| 875 static const int _propertyIsStatic = 0; |
| 876 static const int _propertyIsAbstract = 1; |
| 877 static const int _propertyIsGetter = 2; |
| 878 static const int _propertyIsSetter = 3; |
| 879 static const int _propertyIsConstructor = 4; |
| 880 |
883 Symbol _simpleName = null; | 881 Symbol _simpleName = null; |
884 Symbol get simpleName { | 882 Symbol get simpleName { |
885 if (_simpleName == null) { | 883 if (_simpleName == null) { |
886 _simpleName = _s(_MethodMirror_name(_reflectee)); | 884 _simpleName = _s(_MethodMirror_name(_reflectee)); |
887 } | 885 } |
888 return _simpleName; | 886 return _simpleName; |
889 } | 887 } |
890 | 888 |
891 Symbol _qualifiedName = null; | 889 Symbol _qualifiedName = null; |
892 Symbol get qualifiedName { | 890 Symbol get qualifiedName { |
(...skipping 26 matching lines...) Expand all Loading... |
919 var _returnType; | 917 var _returnType; |
920 TypeMirror get returnType { | 918 TypeMirror get returnType { |
921 if (_returnType is! Mirror) { | 919 if (_returnType is! Mirror) { |
922 _returnType = _returnType.resolve(mirrors); | 920 _returnType = _returnType.resolve(mirrors); |
923 } | 921 } |
924 return _returnType; | 922 return _returnType; |
925 } | 923 } |
926 | 924 |
927 final List<ParameterMirror> parameters; | 925 final List<ParameterMirror> parameters; |
928 | 926 |
929 final bool isStatic; | 927 bool _isStatic = null; |
930 final bool isAbstract; | 928 bool get isStatic { |
| 929 if (_isStatic == null) { |
| 930 _isStatic = _MethodMirror_get_property(_reflectee, _propertyIsStatic); |
| 931 } |
| 932 return _isStatic; |
| 933 } |
| 934 |
| 935 bool _isAbstract; |
| 936 bool get isAbstract { |
| 937 if (_isAbstract == null) { |
| 938 _isAbstract = _MethodMirror_get_property(_reflectee, _propertyIsAbstract); |
| 939 } |
| 940 return _isAbstract; |
| 941 } |
931 | 942 |
932 bool get isRegularMethod => !isGetter && !isSetter && !isConstructor; | 943 bool get isRegularMethod => !isGetter && !isSetter && !isConstructor; |
933 | 944 |
934 TypeMirror get isOperator { | 945 TypeMirror get isOperator { |
935 throw new UnimplementedError( | 946 throw new UnimplementedError( |
936 'MethodMirror.isOperator is not implemented'); | 947 'MethodMirror.isOperator is not implemented'); |
937 } | 948 } |
938 | 949 |
939 final bool isGetter; | 950 bool _isGetter = null; |
940 final bool isSetter; | 951 bool get isGetter { |
941 final bool isConstructor; | 952 if (_isGetter == null) { |
| 953 _isGetter = _MethodMirror_get_property(_reflectee, _propertyIsGetter); |
| 954 } |
| 955 return _isGetter; |
| 956 } |
| 957 |
| 958 bool _isSetter = null; |
| 959 bool get isSetter { |
| 960 if (_isSetter == null) { |
| 961 _isSetter = _MethodMirror_get_property(_reflectee, _propertyIsSetter); |
| 962 } |
| 963 return _isSetter; |
| 964 } |
| 965 |
| 966 bool _isConstructor = null; |
| 967 bool get isConstructor { |
| 968 if (_isConstructor == null) { |
| 969 _isConstructor = _MethodMirror_get_property(_reflectee, |
| 970 _propertyIsConstructor); |
| 971 } |
| 972 return _isConstructor; |
| 973 } |
942 | 974 |
943 Symbol _constructorName = null; | 975 Symbol _constructorName = null; |
944 Symbol get constructorName { | 976 Symbol get constructorName { |
945 if (_constructorName == null) { | 977 if (_constructorName == null) { |
946 if (!isConstructor) { | 978 if (!isConstructor) { |
947 _constructorName = _s(''); | 979 _constructorName = _s(''); |
948 } else { | 980 } else { |
949 var parts = _n(simpleName).split('.'); | 981 var parts = _n(simpleName).split('.'); |
950 if (parts.length > 2) { | 982 if (parts.length > 2) { |
951 throw new MirrorException( | 983 throw new MirrorException( |
952 'Internal error in MethodMirror.constructorName: ' | 984 'Internal error in MethodMirror.constructorName: ' |
953 'malformed name <$simpleName>'); | 985 'malformed name <$simpleName>'); |
954 } else if (parts.length == 2) { | 986 } else if (parts.length == 2) { |
955 _constructorName = _s(parts[1]); | 987 _constructorName = _s(parts[1]); |
956 } else { | 988 } else { |
957 _constructorName = _s(''); | 989 _constructorName = _s(''); |
958 } | 990 } |
959 } | 991 } |
960 } | 992 } |
961 return _constructorName; | 993 return _constructorName; |
962 } | 994 } |
963 | 995 |
964 final bool isConstConstructor; | 996 // TODO(mlippautz): Implement constructor kinds. |
965 final bool isGenerativeConstructor; | 997 final bool isConstConstructor = false; |
966 final bool isRedirectingConstructor; | 998 final bool isGenerativeConstructor = false; |
967 final bool isFactoryConstructor; | 999 final bool isRedirectingConstructor = false; |
| 1000 final bool isFactoryConstructor = false; |
968 | 1001 |
969 List<InstanceMirror> get metadata { | 1002 List<InstanceMirror> get metadata { |
970 owner; // ensure owner is computed | 1003 owner; // ensure owner is computed |
971 // get the metadata objects, convert them into InstanceMirrors using | 1004 // get the metadata objects, convert them into InstanceMirrors using |
972 // reflect() and then make them into a Dart list | 1005 // reflect() and then make them into a Dart list |
973 return _metadata(this).map(reflect).toList(); | 1006 return _metadata(this).map(reflect).toList(); |
974 } | 1007 } |
975 | 1008 |
976 String toString() => "MethodMirror on '${_n(simpleName)}'"; | 1009 String toString() => "MethodMirror on '${_n(simpleName)}'"; |
977 | 1010 |
978 static String _MethodMirror_name(reflectee) | 1011 static String _MethodMirror_name(reflectee) |
979 native "MethodMirror_name"; | 1012 native "MethodMirror_name"; |
| 1013 |
| 1014 static bool _MethodMirror_get_property(reflectee, property) |
| 1015 native "MethodMirror_get_property"; |
980 } | 1016 } |
981 | 1017 |
982 class _LocalVariableMirrorImpl extends _LocalMirrorImpl | 1018 class _LocalVariableMirrorImpl extends _LocalMirrorImpl |
983 implements VariableMirror { | 1019 implements VariableMirror { |
984 _LocalVariableMirrorImpl(String simpleName, | 1020 _LocalVariableMirrorImpl(String simpleName, |
985 this._owner, | 1021 this._owner, |
986 this._type, | 1022 this._type, |
987 this.isStatic, | 1023 this.isStatic, |
988 this.isFinal) | 1024 this.isFinal) |
989 : this.simpleName = _s(simpleName); | 1025 : this.simpleName = _s(simpleName); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 } | 1162 } |
1127 | 1163 |
1128 // Creates a new local ClassMirror. | 1164 // Creates a new local ClassMirror. |
1129 static ClassMirror makeLocalClassMirror(Type key) | 1165 static ClassMirror makeLocalClassMirror(Type key) |
1130 native "Mirrors_makeLocalClassMirror"; | 1166 native "Mirrors_makeLocalClassMirror"; |
1131 | 1167 |
1132 static ClassMirror reflectClass(Type key) { | 1168 static ClassMirror reflectClass(Type key) { |
1133 return makeLocalClassMirror(key); | 1169 return makeLocalClassMirror(key); |
1134 } | 1170 } |
1135 } | 1171 } |
OLD | NEW |