| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this | 1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in | 2 // source code is governed by a BSD-style license that can be found in |
| 3 // the LICENSE file. | 3 // the LICENSE file. |
| 4 | 4 |
| 5 // TODO(sigurdm) doc: Make NoSuchCapability messages streamlined (the same in | 5 // TODO(sigurdm) doc: Make NoSuchCapability messages streamlined (the same in |
| 6 // both `reflectable_mirror_based.dart` and | 6 // both `reflectable_mirror_based.dart` and |
| 7 // `reflectable_transformer_based.dart`, and explaining as well as possible | 7 // `reflectable_transformer_based.dart`, and explaining as well as possible |
| 8 // which capability is missing.) | 8 // which capability is missing.) |
| 9 | 9 |
| 10 /// Implementation of the reflectable interface using dart mirrors. | 10 /// Implementation of the reflectable interface using dart mirrors. |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 | 791 |
| 792 class ClassMirrorImpl extends _TypeMirrorImpl | 792 class ClassMirrorImpl extends _TypeMirrorImpl |
| 793 with _ObjectMirrorImplMixin | 793 with _ObjectMirrorImplMixin |
| 794 implements rm.ClassMirror { | 794 implements rm.ClassMirror { |
| 795 dm.ClassMirror get _classMirror => _declarationMirror; | 795 dm.ClassMirror get _classMirror => _declarationMirror; |
| 796 | 796 |
| 797 ClassMirrorImpl(dm.ClassMirror classMirror, ReflectableImpl reflectable) | 797 ClassMirrorImpl(dm.ClassMirror classMirror, ReflectableImpl reflectable) |
| 798 : super(classMirror, reflectable) {} | 798 : super(classMirror, reflectable) {} |
| 799 | 799 |
| 800 @override | 800 @override |
| 801 bool get hasDynamicReflectedType => _classMirror.typeVariables.isEmpty; |
| 802 |
| 803 @override |
| 804 Type get dynamicReflectedType { |
| 805 if (!hasDynamicReflectedType) { |
| 806 /// We cannot hope to implement this based on 'dart:mirrors' for generic |
| 807 /// classes, because there is no support for obtaining one instantiation |
| 808 /// of a generic class based on a different one (we cannot obtain |
| 809 /// `List<dynamic>` from `List<int>` or any such thing); and when |
| 810 /// `isOriginalDeclaration` is true we do not have a `reflectedType` at |
| 811 /// all. |
| 812 throw new UnsupportedError( |
| 813 "Attempt to get dynamicReflectedType on $_classMirror"); |
| 814 } |
| 815 return reflectedType; |
| 816 } |
| 817 |
| 818 @override |
| 801 List<rm.TypeVariableMirror> get typeVariables { | 819 List<rm.TypeVariableMirror> get typeVariables { |
| 802 if (!reflectableSupportsDeclarations(_reflectable)) { | 820 if (!reflectableSupportsDeclarations(_reflectable)) { |
| 803 throw new NoSuchCapabilityError( | 821 throw new NoSuchCapabilityError( |
| 804 "Attempt to get typeVariables without `declarationsCapability`"); | 822 "Attempt to get typeVariables without `declarationsCapability`"); |
| 805 } | 823 } |
| 806 return _classMirror.typeVariables.map((v) { | 824 return _classMirror.typeVariables.map((v) { |
| 807 return new _TypeVariableMirrorImpl(v, _reflectable); | 825 return new _TypeVariableMirrorImpl(v, _reflectable); |
| 808 }).toList(); | 826 }).toList(); |
| 809 } | 827 } |
| 810 | 828 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 | 1067 |
| 1050 class _FunctionTypeMirrorImpl extends ClassMirrorImpl | 1068 class _FunctionTypeMirrorImpl extends ClassMirrorImpl |
| 1051 implements rm.FunctionTypeMirror { | 1069 implements rm.FunctionTypeMirror { |
| 1052 dm.FunctionTypeMirror get _functionTypeMirror => _classMirror; | 1070 dm.FunctionTypeMirror get _functionTypeMirror => _classMirror; |
| 1053 | 1071 |
| 1054 _FunctionTypeMirrorImpl( | 1072 _FunctionTypeMirrorImpl( |
| 1055 dm.FunctionTypeMirror functionTypeMirror, ReflectableImpl reflectable) | 1073 dm.FunctionTypeMirror functionTypeMirror, ReflectableImpl reflectable) |
| 1056 : super(functionTypeMirror, reflectable); | 1074 : super(functionTypeMirror, reflectable); |
| 1057 | 1075 |
| 1058 @override | 1076 @override |
| 1077 bool get hasDynamicReflectedType => false; |
| 1078 |
| 1079 @override |
| 1080 Type get dynamicReflectedType => throw unimplementedError( |
| 1081 "Attempt to get dynamicReflectedType on a function type mirror"); |
| 1082 |
| 1083 @override |
| 1059 rm.MethodMirror get callMethod { | 1084 rm.MethodMirror get callMethod { |
| 1060 return new MethodMirrorImpl(_functionTypeMirror.callMethod, _reflectable); | 1085 return new MethodMirrorImpl(_functionTypeMirror.callMethod, _reflectable); |
| 1061 } | 1086 } |
| 1062 | 1087 |
| 1063 @override | 1088 @override |
| 1064 List<rm.ParameterMirror> get parameters { | 1089 List<rm.ParameterMirror> get parameters { |
| 1065 return _functionTypeMirror.parameters | 1090 return _functionTypeMirror.parameters |
| 1066 .map((dm.ParameterMirror parameterMirror) { | 1091 .map((dm.ParameterMirror parameterMirror) { |
| 1067 return new _ParameterMirrorImpl(parameterMirror, _reflectable); | 1092 return new _ParameterMirrorImpl(parameterMirror, _reflectable); |
| 1068 }); | 1093 }); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 @override | 1178 @override |
| 1154 Type get reflectedReturnType { | 1179 Type get reflectedReturnType { |
| 1155 if (impliesReflectedType(_reflectable.capabilities)) { | 1180 if (impliesReflectedType(_reflectable.capabilities)) { |
| 1156 return _methodMirror.returnType.reflectedType; | 1181 return _methodMirror.returnType.reflectedType; |
| 1157 } | 1182 } |
| 1158 throw new NoSuchCapabilityError( | 1183 throw new NoSuchCapabilityError( |
| 1159 "Attempt to get reflectedReturnType without capability"); | 1184 "Attempt to get reflectedReturnType without capability"); |
| 1160 } | 1185 } |
| 1161 | 1186 |
| 1162 @override | 1187 @override |
| 1188 bool get hasDynamicReflectedReturnType { |
| 1189 if (impliesReflectedType(_reflectable.capabilities)) { |
| 1190 return _methodMirror.returnType.typeVariables.isEmpty && |
| 1191 _methodMirror.returnType.hasReflectedType; |
| 1192 } |
| 1193 throw new NoSuchCapabilityError("Attempt to get " |
| 1194 "hasDynamicReflectedReturnType without `reflectedTypeCapability`"); |
| 1195 } |
| 1196 |
| 1197 @override |
| 1198 Type get dynamicReflectedReturnType { |
| 1199 if (impliesReflectedType(_reflectable.capabilities)) { |
| 1200 if (_methodMirror.returnType.typeVariables.isEmpty) { |
| 1201 return _methodMirror.returnType.reflectedType; |
| 1202 } else { |
| 1203 // The value returned by `hasDynamicReflectedReturnType` is false, so |
| 1204 // even though this is unimplemented and may be implemented if we get |
| 1205 // the required runtime support, it is currently an `UnsupportedError`. |
| 1206 throw new UnsupportedError("Attempt to obtain the " |
| 1207 "dynamicReflectedReturnType of a generic type " |
| 1208 "${_methodMirror.returnType}"); |
| 1209 } |
| 1210 } |
| 1211 throw new NoSuchCapabilityError("Attempt to get dynamicReflectedReturnType " |
| 1212 "without `reflectedTypeCapability`"); |
| 1213 } |
| 1214 |
| 1215 @override |
| 1163 String get source => _methodMirror.source; | 1216 String get source => _methodMirror.source; |
| 1164 | 1217 |
| 1165 @override | 1218 @override |
| 1166 List<rm.ParameterMirror> get parameters { | 1219 List<rm.ParameterMirror> get parameters { |
| 1167 return _methodMirror.parameters.map((p) { | 1220 return _methodMirror.parameters.map((p) { |
| 1168 return new _ParameterMirrorImpl(p, _reflectable); | 1221 return new _ParameterMirrorImpl(p, _reflectable); |
| 1169 }).toList(); | 1222 }).toList(); |
| 1170 } | 1223 } |
| 1171 | 1224 |
| 1172 @override | 1225 @override |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 @override | 1327 @override |
| 1275 Type get reflectedType { | 1328 Type get reflectedType { |
| 1276 if (impliesReflectedType(_reflectable.capabilities)) { | 1329 if (impliesReflectedType(_reflectable.capabilities)) { |
| 1277 return _variableMirror.type.reflectedType; | 1330 return _variableMirror.type.reflectedType; |
| 1278 } | 1331 } |
| 1279 throw new NoSuchCapabilityError( | 1332 throw new NoSuchCapabilityError( |
| 1280 "Attempt to get reflectedType without `reflectedTypeCapability`"); | 1333 "Attempt to get reflectedType without `reflectedTypeCapability`"); |
| 1281 } | 1334 } |
| 1282 | 1335 |
| 1283 @override | 1336 @override |
| 1337 bool get hasDynamicReflectedType { |
| 1338 if (impliesReflectedType(_reflectable.capabilities)) { |
| 1339 return _variableMirror.type.typeVariables.isEmpty && |
| 1340 _variableMirror.type.hasReflectedType; |
| 1341 } |
| 1342 throw new NoSuchCapabilityError("Attempt to get hasDynamicReflectedType " |
| 1343 "without `reflectedTypeCapability`"); |
| 1344 } |
| 1345 |
| 1346 @override |
| 1347 Type get dynamicReflectedType { |
| 1348 if (impliesReflectedType(_reflectable.capabilities)) { |
| 1349 if (_variableMirror.type.typeVariables.isEmpty) { |
| 1350 return _variableMirror.type.reflectedType; |
| 1351 } else { |
| 1352 // The value returned by `hasDynamicReflectedReturnType` is false, so |
| 1353 // even though this is unimplemented and may be implemented if we get |
| 1354 // the required runtime support, it is currently an `UnsupportedError`. |
| 1355 throw new UnsupportedError("Attempt to obtain the dynamicReflectedType " |
| 1356 "of a generic type ${_variableMirror.type}"); |
| 1357 } |
| 1358 } |
| 1359 throw new NoSuchCapabilityError("Attempt to get dynamicReflectedType " |
| 1360 "without `reflectedTypeCapability`"); |
| 1361 } |
| 1362 |
| 1363 @override |
| 1284 bool get isStatic => _variableMirror.isStatic; | 1364 bool get isStatic => _variableMirror.isStatic; |
| 1285 | 1365 |
| 1286 @override | 1366 @override |
| 1287 bool get isFinal => _variableMirror.isFinal; | 1367 bool get isFinal => _variableMirror.isFinal; |
| 1288 | 1368 |
| 1289 @override | 1369 @override |
| 1290 bool get isConst => _variableMirror.isConst; | 1370 bool get isConst => _variableMirror.isConst; |
| 1291 | 1371 |
| 1292 @override | 1372 @override |
| 1293 bool operator ==(other) => other is VariableMirrorImpl | 1373 bool operator ==(other) => other is VariableMirrorImpl |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1978 } | 2058 } |
| 1979 } | 2059 } |
| 1980 } | 2060 } |
| 1981 | 2061 |
| 1982 bool _isSetterName(String name) => name.endsWith("="); | 2062 bool _isSetterName(String name) => name.endsWith("="); |
| 1983 | 2063 |
| 1984 String _setterNameToGetterName(String name) { | 2064 String _setterNameToGetterName(String name) { |
| 1985 assert(_isSetterName(name)); | 2065 assert(_isSetterName(name)); |
| 1986 return name.substring(0, name.length - 1); | 2066 return name.substring(0, name.length - 1); |
| 1987 } | 2067 } |
| OLD | NEW |