| 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 // TODO(ahe): This is a hack, see delegate below. | 262 // TODO(ahe): This is a hack, see delegate below. |
| 263 static Function _invokeOnClosure; | 263 static Function _invokeOnClosure; |
| 264 | 264 |
| 265 _LocalInstanceMirrorImpl(reflectee) : super(reflectee); | 265 _LocalInstanceMirrorImpl(reflectee) : super(reflectee); |
| 266 | 266 |
| 267 ClassMirror _type; | 267 ClassMirror _type; |
| 268 ClassMirror get type { | 268 ClassMirror get type { |
| 269 if (_type == null) { | 269 if (_type == null) { |
| 270 // Note it not safe to use reflectee.runtimeType because runtimeType may | 270 // Note it not safe to use reflectee.runtimeType because runtimeType may |
| 271 // be overridden. | 271 // be overridden. |
| 272 _type = _Mirrors._reflectType(_computeType(reflectee)); | 272 _type = reflectType(_computeType(reflectee)); |
| 273 } | 273 } |
| 274 return _type; | 274 return _type; |
| 275 } | 275 } |
| 276 | 276 |
| 277 // LocalInstanceMirrors always reflect local instances | 277 // LocalInstanceMirrors always reflect local instances |
| 278 bool hasReflectee = true; | 278 bool hasReflectee = true; |
| 279 | 279 |
| 280 get reflectee => _reflectee; | 280 get reflectee => _reflectee; |
| 281 | 281 |
| 282 delegate(Invocation invocation) { | 282 delegate(Invocation invocation) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 ClassMirror get defaultFactory => null; | 481 ClassMirror get defaultFactory => null; |
| 482 | 482 |
| 483 ClassMirror _trueSuperclassField; | 483 ClassMirror _trueSuperclassField; |
| 484 ClassMirror get _trueSuperclass { | 484 ClassMirror get _trueSuperclass { |
| 485 if (_trueSuperclassField == null) { | 485 if (_trueSuperclassField == null) { |
| 486 Type supertype = _supertype(_reflectee); | 486 Type supertype = _supertype(_reflectee); |
| 487 if (supertype == null) { | 487 if (supertype == null) { |
| 488 // Object has no superclass. | 488 // Object has no superclass. |
| 489 return null; | 489 return null; |
| 490 } | 490 } |
| 491 _trueSuperclassField = _Mirrors._reflectType(supertype); | 491 _trueSuperclassField = reflectType(supertype); |
| 492 } | 492 } |
| 493 return _trueSuperclassField; | 493 return _trueSuperclassField; |
| 494 } | 494 } |
| 495 ClassMirror get superclass { | 495 ClassMirror get superclass { |
| 496 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass; | 496 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass; |
| 497 } | 497 } |
| 498 | 498 |
| 499 var _superinterfaces; | 499 var _superinterfaces; |
| 500 List<ClassMirror> get superinterfaces { | 500 List<ClassMirror> get superinterfaces { |
| 501 if (_superinterfaces == null) { | 501 if (_superinterfaces == null) { |
| 502 _superinterfaces = _interfaces(_reflectee) | 502 _superinterfaces = _interfaces(_reflectee) |
| 503 .map((i) => _Mirrors._reflectType(i)).toList(growable:false); | 503 .map((i) => reflectType(i)).toList(growable:false); |
| 504 } | 504 } |
| 505 return _superinterfaces; | 505 return _superinterfaces; |
| 506 } | 506 } |
| 507 | 507 |
| 508 get _mixinApplicationName { | 508 get _mixinApplicationName { |
| 509 var mixins = new List<ClassMirror>(); | 509 var mixins = new List<ClassMirror>(); |
| 510 var klass = this; | 510 var klass = this; |
| 511 while (_computeMixin(klass._reflectee) != null) { | 511 while (_computeMixin(klass._reflectee) != null) { |
| 512 mixins.add(klass.mixin); | 512 mixins.add(klass.mixin); |
| 513 klass = klass.superclass; | 513 klass = klass.superclass; |
| 514 } | 514 } |
| 515 return _s( | 515 return _s( |
| 516 _n(klass.qualifiedName) | 516 _n(klass.qualifiedName) |
| 517 + ' with ' | 517 + ' with ' |
| 518 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', ')); | 518 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', ')); |
| 519 } | 519 } |
| 520 | 520 |
| 521 var _mixin; | 521 var _mixin; |
| 522 ClassMirror get mixin { | 522 ClassMirror get mixin { |
| 523 if (_mixin == null) { | 523 if (_mixin == null) { |
| 524 if (_isMixinTypedef) { | 524 if (_isMixinTypedef) { |
| 525 _mixin = _trueSuperclass.mixin; | 525 _mixin = _trueSuperclass.mixin; |
| 526 } else { | 526 } else { |
| 527 var mixinType = _computeMixin(_reflectee); | 527 var mixinType = _computeMixin(_reflectee); |
| 528 if (mixinType == null) { | 528 if (mixinType == null) { |
| 529 // The reflectee is not a mixin application. | 529 // The reflectee is not a mixin application. |
| 530 _mixin = this; | 530 _mixin = this; |
| 531 } else { | 531 } else { |
| 532 _mixin = _Mirrors._reflectType(mixinType); | 532 _mixin = reflectType(mixinType); |
| 533 } | 533 } |
| 534 } | 534 } |
| 535 } | 535 } |
| 536 return _mixin; | 536 return _mixin; |
| 537 } | 537 } |
| 538 | 538 |
| 539 Map<Symbol, Mirror> _members; | 539 Map<Symbol, Mirror> _members; |
| 540 Map<Symbol, Mirror> get members { | 540 Map<Symbol, Mirror> get members { |
| 541 if (_members == null) { | 541 if (_members == null) { |
| 542 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this; | 542 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 if (_callMethod == null) { | 744 if (_callMethod == null) { |
| 745 _callMethod = this._FunctionTypeMirror_call_method(_reflectee); | 745 _callMethod = this._FunctionTypeMirror_call_method(_reflectee); |
| 746 } | 746 } |
| 747 return _callMethod; | 747 return _callMethod; |
| 748 } | 748 } |
| 749 | 749 |
| 750 TypeMirror _returnType = null; | 750 TypeMirror _returnType = null; |
| 751 TypeMirror get returnType { | 751 TypeMirror get returnType { |
| 752 if (_returnType == null) { | 752 if (_returnType == null) { |
| 753 _returnType = | 753 _returnType = |
| 754 _Mirrors._reflectType(_FunctionTypeMirror_return_type(_reflectee)); | 754 reflectType(_FunctionTypeMirror_return_type(_reflectee)); |
| 755 } | 755 } |
| 756 return _returnType; | 756 return _returnType; |
| 757 } | 757 } |
| 758 | 758 |
| 759 List<ParameterMirror> _parameters = null; | 759 List<ParameterMirror> _parameters = null; |
| 760 List<ParameterMirror> get parameters { | 760 List<ParameterMirror> get parameters { |
| 761 if (_parameters == null) { | 761 if (_parameters == null) { |
| 762 _parameters = _FunctionTypeMirror_parameters(_reflectee); | 762 _parameters = _FunctionTypeMirror_parameters(_reflectee); |
| 763 } | 763 } |
| 764 return _parameters; | 764 return _parameters; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 final bool isTopLevel = false; | 830 final bool isTopLevel = false; |
| 831 | 831 |
| 832 SourceLocation get location { | 832 SourceLocation get location { |
| 833 throw new UnimplementedError( | 833 throw new UnimplementedError( |
| 834 'TypeVariableMirror.location is not implemented'); | 834 'TypeVariableMirror.location is not implemented'); |
| 835 } | 835 } |
| 836 | 836 |
| 837 TypeMirror _upperBound = null; | 837 TypeMirror _upperBound = null; |
| 838 TypeMirror get upperBound { | 838 TypeMirror get upperBound { |
| 839 if (_upperBound == null) { | 839 if (_upperBound == null) { |
| 840 _upperBound = | 840 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee)); |
| 841 _Mirrors._reflectType(_TypeVariableMirror_upper_bound(_reflectee)); | |
| 842 } | 841 } |
| 843 return _upperBound; | 842 return _upperBound; |
| 844 } | 843 } |
| 845 | 844 |
| 846 bool get isOriginalDeclaration => true; | 845 bool get isOriginalDeclaration => true; |
| 847 ClassMirror get originalDeclaration => this; | 846 ClassMirror get originalDeclaration => this; |
| 848 | 847 |
| 849 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; | 848 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; |
| 850 | 849 |
| 851 static DeclarationMirror _TypeVariableMirror_owner(reflectee) | 850 static DeclarationMirror _TypeVariableMirror_owner(reflectee) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 final Uri uri; | 927 final Uri uri; |
| 929 | 928 |
| 930 Map<Symbol, Mirror> _members; | 929 Map<Symbol, Mirror> _members; |
| 931 Map<Symbol, Mirror> get members { | 930 Map<Symbol, Mirror> get members { |
| 932 if (_members == null) { | 931 if (_members == null) { |
| 933 _members = _makeMemberMap(_computeMembers(_reflectee)); | 932 _members = _makeMemberMap(_computeMembers(_reflectee)); |
| 934 } | 933 } |
| 935 return _members; | 934 return _members; |
| 936 } | 935 } |
| 937 | 936 |
| 937 Map<Symbol, ClassMirror> _types; |
| 938 Map<Symbol, TypeMirror> get types { |
| 939 if (_types == null) { |
| 940 _types = _filterMap(members, (key, value) => (value is TypeMirror)); |
| 941 } |
| 942 return _types; |
| 943 } |
| 944 |
| 938 Map<Symbol, ClassMirror> _classes; | 945 Map<Symbol, ClassMirror> _classes; |
| 939 Map<Symbol, ClassMirror> get classes { | 946 Map<Symbol, ClassMirror> get classes { |
| 940 if (_classes == null) { | 947 if (_classes == null) { |
| 941 _classes = _filterMap(members, | 948 _classes = _filterMap(members, |
| 942 (key, value) => (value is ClassMirror)); | 949 (key, value) => (value is ClassMirror)); |
| 943 } | 950 } |
| 944 return _classes; | 951 return _classes; |
| 945 } | 952 } |
| 946 | 953 |
| 947 Map<Symbol, MethodMirror> _functions; | 954 Map<Symbol, MethodMirror> _functions; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 SourceLocation get location { | 1061 SourceLocation get location { |
| 1055 throw new UnimplementedError('MethodMirror.location is not implemented'); | 1062 throw new UnimplementedError('MethodMirror.location is not implemented'); |
| 1056 } | 1063 } |
| 1057 | 1064 |
| 1058 TypeMirror _returnType = null; | 1065 TypeMirror _returnType = null; |
| 1059 TypeMirror get returnType { | 1066 TypeMirror get returnType { |
| 1060 if (_returnType == null) { | 1067 if (_returnType == null) { |
| 1061 if (isConstructor) { | 1068 if (isConstructor) { |
| 1062 _returnType = owner; | 1069 _returnType = owner; |
| 1063 } else { | 1070 } else { |
| 1064 _returnType = | 1071 _returnType = reflectType(_MethodMirror_return_type(_reflectee)); |
| 1065 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee)); | |
| 1066 } | 1072 } |
| 1067 } | 1073 } |
| 1068 return _returnType; | 1074 return _returnType; |
| 1069 } | 1075 } |
| 1070 | 1076 |
| 1071 List<ParameterMirror> _parameters = null; | 1077 List<ParameterMirror> _parameters = null; |
| 1072 List<ParameterMirror> get parameters { | 1078 List<ParameterMirror> get parameters { |
| 1073 if (_parameters == null) { | 1079 if (_parameters == null) { |
| 1074 _parameters = _MethodMirror_parameters(_reflectee); | 1080 _parameters = _MethodMirror_parameters(_reflectee); |
| 1075 } | 1081 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 | 1156 |
| 1151 bool get isTopLevel => owner is LibraryMirror; | 1157 bool get isTopLevel => owner is LibraryMirror; |
| 1152 | 1158 |
| 1153 SourceLocation get location { | 1159 SourceLocation get location { |
| 1154 throw new UnimplementedError('VariableMirror.location is not implemented'); | 1160 throw new UnimplementedError('VariableMirror.location is not implemented'); |
| 1155 } | 1161 } |
| 1156 | 1162 |
| 1157 TypeMirror _type; | 1163 TypeMirror _type; |
| 1158 TypeMirror get type { | 1164 TypeMirror get type { |
| 1159 if (_type == null) { | 1165 if (_type == null) { |
| 1160 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee)); | 1166 _type = reflectType(_VariableMirror_type(_reflectee)); |
| 1161 } | 1167 } |
| 1162 return _type; | 1168 return _type; |
| 1163 } | 1169 } |
| 1164 | 1170 |
| 1165 String toString() => "VariableMirror on '${_n(simpleName)}'"; | 1171 String toString() => "VariableMirror on '${_n(simpleName)}'"; |
| 1166 | 1172 |
| 1167 static _VariableMirror_type(reflectee) | 1173 static _VariableMirror_type(reflectee) |
| 1168 native "VariableMirror_type"; | 1174 native "VariableMirror_type"; |
| 1169 } | 1175 } |
| 1170 | 1176 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 bool get hasDefaultValue => _defaultValueReflectee != null; | 1212 bool get hasDefaultValue => _defaultValueReflectee != null; |
| 1207 | 1213 |
| 1208 List<InstanceMirror> get metadata { | 1214 List<InstanceMirror> get metadata { |
| 1209 if ( _unmirroredMetadata == null) return const []; | 1215 if ( _unmirroredMetadata == null) return const []; |
| 1210 return _unmirroredMetadata.map(reflect).toList(growable:false); | 1216 return _unmirroredMetadata.map(reflect).toList(growable:false); |
| 1211 } | 1217 } |
| 1212 | 1218 |
| 1213 TypeMirror _type = null; | 1219 TypeMirror _type = null; |
| 1214 TypeMirror get type { | 1220 TypeMirror get type { |
| 1215 if (_type == null) { | 1221 if (_type == null) { |
| 1216 _type = | 1222 _type = reflectType(_ParameterMirror_type(_reflectee, _position)); |
| 1217 _Mirrors._reflectType(_ParameterMirror_type(_reflectee, _position)); | |
| 1218 } | 1223 } |
| 1219 return _type; | 1224 return _type; |
| 1220 } | 1225 } |
| 1221 | 1226 |
| 1222 String toString() => "ParameterMirror on '${_n(simpleName)}'"; | 1227 String toString() => "ParameterMirror on '${_n(simpleName)}'"; |
| 1223 | 1228 |
| 1224 static Type _ParameterMirror_type(_reflectee, _position) | 1229 static Type _ParameterMirror_type(_reflectee, _position) |
| 1225 native "ParameterMirror_type"; | 1230 native "ParameterMirror_type"; |
| 1226 } | 1231 } |
| 1227 | 1232 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 ? new _LocalClosureMirrorImpl(reflectee) | 1300 ? new _LocalClosureMirrorImpl(reflectee) |
| 1296 : new _LocalInstanceMirrorImpl(reflectee); | 1301 : new _LocalInstanceMirrorImpl(reflectee); |
| 1297 } | 1302 } |
| 1298 | 1303 |
| 1299 static ClassMirror makeLocalClassMirror(Type key) | 1304 static ClassMirror makeLocalClassMirror(Type key) |
| 1300 native "Mirrors_makeLocalClassMirror"; | 1305 native "Mirrors_makeLocalClassMirror"; |
| 1301 static TypeMirror makeLocalTypeMirror(Type key) | 1306 static TypeMirror makeLocalTypeMirror(Type key) |
| 1302 native "Mirrors_makeLocalTypeMirror"; | 1307 native "Mirrors_makeLocalTypeMirror"; |
| 1303 | 1308 |
| 1304 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror"); | 1309 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror"); |
| 1305 static Expando<ClassMirror> _instanitationCache = new Expando("TypeMirror"); | 1310 static Expando<TypeMirror> _instanitationCache = new Expando("TypeMirror"); |
| 1306 | 1311 |
| 1307 static ClassMirror reflectClass(Type key) { | 1312 static ClassMirror reflectClass(Type key) { |
| 1308 var classMirror = _declarationCache[key]; | 1313 var classMirror = _declarationCache[key]; |
| 1309 if (classMirror == null) { | 1314 if (classMirror == null) { |
| 1310 classMirror = makeLocalClassMirror(key); | 1315 classMirror = makeLocalClassMirror(key); |
| 1311 _declarationCache[key] = classMirror; | 1316 _declarationCache[key] = classMirror; |
| 1312 if (!classMirror._isGeneric) { | 1317 if (!classMirror._isGeneric) { |
| 1313 _instanitationCache[key] = classMirror; | 1318 _instanitationCache[key] = classMirror; |
| 1314 } | 1319 } |
| 1315 } | 1320 } |
| 1316 return classMirror; | 1321 return classMirror; |
| 1317 } | 1322 } |
| 1318 | 1323 |
| 1319 static TypeMirror _reflectType(Type key) { | 1324 static TypeMirror reflectType(Type key) { |
| 1320 var typeMirror = _instanitationCache[key]; | 1325 var typeMirror = _instanitationCache[key]; |
| 1321 if (typeMirror == null) { | 1326 if (typeMirror == null) { |
| 1322 typeMirror = makeLocalTypeMirror(key); | 1327 typeMirror = makeLocalTypeMirror(key); |
| 1323 _instanitationCache[key] = typeMirror; | 1328 _instanitationCache[key] = typeMirror; |
| 1324 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1329 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
| 1325 _declarationCache[key] = typeMirror; | 1330 _declarationCache[key] = typeMirror; |
| 1326 } | 1331 } |
| 1327 } | 1332 } |
| 1328 return typeMirror; | 1333 return typeMirror; |
| 1329 } | 1334 } |
| 1330 } | 1335 } |
| OLD | NEW |