Chromium Code Reviews| 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 final emptyList = new UnmodifiableListView([]); | 9 final emptyList = new UnmodifiableListView([]); |
| 10 final emptyMap = new _UnmodifiableMapView({}); | 10 final emptyMap = new _UnmodifiableMapView({}); |
| (...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1201 | 1201 |
| 1202 bool get isPrivate => _n(simpleName).startsWith('_') || | 1202 bool get isPrivate => _n(simpleName).startsWith('_') || |
| 1203 _n(constructorName).startsWith('_'); | 1203 _n(constructorName).startsWith('_'); |
| 1204 | 1204 |
| 1205 bool get isTopLevel => owner is LibraryMirror; | 1205 bool get isTopLevel => owner is LibraryMirror; |
| 1206 | 1206 |
| 1207 SourceLocation get location { | 1207 SourceLocation get location { |
| 1208 throw new UnimplementedError('MethodMirror.location is not implemented'); | 1208 throw new UnimplementedError('MethodMirror.location is not implemented'); |
| 1209 } | 1209 } |
| 1210 | 1210 |
| 1211 Type get _instantiator => owner is ClassMirror ? owner._reflectedType : null; | |
| 1212 | |
| 1211 TypeMirror _returnType = null; | 1213 TypeMirror _returnType = null; |
| 1212 TypeMirror get returnType { | 1214 TypeMirror get returnType { |
| 1213 if (_returnType == null) { | 1215 if (_returnType == null) { |
| 1214 if (isConstructor) { | 1216 if (isConstructor) { |
| 1215 _returnType = owner; | 1217 _returnType = owner; |
|
regis
2013/11/06 19:06:07
Why don't you instantiate in this case?
| |
| 1216 } else { | 1218 } else { |
| 1217 _returnType = reflectType(_MethodMirror_return_type(_reflectee)); | 1219 _returnType = reflectType( |
| 1220 _MethodMirror_return_type(_reflectee, _instantiator)); | |
| 1218 } | 1221 } |
| 1219 _returnType = _returnType._instantiateInContextOf(owner); | |
| 1220 } | 1222 } |
| 1221 return _returnType; | 1223 return _returnType; |
| 1222 } | 1224 } |
| 1223 | 1225 |
| 1224 List<ParameterMirror> _parameters = null; | 1226 List<ParameterMirror> _parameters = null; |
| 1225 List<ParameterMirror> get parameters { | 1227 List<ParameterMirror> get parameters { |
| 1226 if (_parameters == null) { | 1228 if (_parameters == null) { |
| 1227 _parameters = _MethodMirror_parameters(_reflectee); | 1229 _parameters = _MethodMirror_parameters(_reflectee); |
| 1228 _parameters = new UnmodifiableListView(_parameters); | 1230 _parameters = new UnmodifiableListView(_parameters); |
| 1229 } | 1231 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1269 } else { | 1271 } else { |
| 1270 _simpleName = _s(ownerName + "." + cn); | 1272 _simpleName = _s(ownerName + "." + cn); |
| 1271 } | 1273 } |
| 1272 } | 1274 } |
| 1273 | 1275 |
| 1274 String toString() => "MethodMirror on '${MirrorSystem.getName(simpleName)}'"; | 1276 String toString() => "MethodMirror on '${MirrorSystem.getName(simpleName)}'"; |
| 1275 | 1277 |
| 1276 static dynamic _MethodMirror_owner(reflectee) | 1278 static dynamic _MethodMirror_owner(reflectee) |
| 1277 native "MethodMirror_owner"; | 1279 native "MethodMirror_owner"; |
| 1278 | 1280 |
| 1279 static dynamic _MethodMirror_return_type(reflectee) | 1281 static dynamic _MethodMirror_return_type(reflectee, instantiator) |
| 1280 native "MethodMirror_return_type"; | 1282 native "MethodMirror_return_type"; |
| 1281 | 1283 |
| 1282 List<ParameterMirror> _MethodMirror_parameters(reflectee) | 1284 List<ParameterMirror> _MethodMirror_parameters(reflectee) |
| 1283 native "MethodMirror_parameters"; | 1285 native "MethodMirror_parameters"; |
| 1284 | 1286 |
| 1285 static String _MethodMirror_source(reflectee) | 1287 static String _MethodMirror_source(reflectee) |
| 1286 native "MethodMirror_source"; | 1288 native "MethodMirror_source"; |
| 1287 } | 1289 } |
| 1288 | 1290 |
| 1289 class _LocalVariableMirrorImpl extends _LocalDeclarationMirrorImpl | 1291 class _LocalVariableMirrorImpl extends _LocalDeclarationMirrorImpl |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1301 final bool isFinal; | 1303 final bool isFinal; |
| 1302 | 1304 |
| 1303 bool get isPrivate => _n(simpleName).startsWith('_'); | 1305 bool get isPrivate => _n(simpleName).startsWith('_'); |
| 1304 | 1306 |
| 1305 bool get isTopLevel => owner is LibraryMirror; | 1307 bool get isTopLevel => owner is LibraryMirror; |
| 1306 | 1308 |
| 1307 SourceLocation get location { | 1309 SourceLocation get location { |
| 1308 throw new UnimplementedError('VariableMirror.location is not implemented'); | 1310 throw new UnimplementedError('VariableMirror.location is not implemented'); |
| 1309 } | 1311 } |
| 1310 | 1312 |
| 1313 Type get _instantiator => owner is ClassMirror ? owner._reflectedType : null; | |
| 1314 | |
| 1311 TypeMirror _type; | 1315 TypeMirror _type; |
| 1312 TypeMirror get type { | 1316 TypeMirror get type { |
| 1313 if (_type == null) { | 1317 if (_type == null) { |
| 1314 _type = reflectType(_VariableMirror_type(_reflectee)); | 1318 _type = reflectType(_VariableMirror_type(_reflectee, _instantiator)); |
| 1315 _type = _type._instantiateInContextOf(owner); | |
| 1316 } | 1319 } |
| 1317 return _type; | 1320 return _type; |
| 1318 } | 1321 } |
| 1319 | 1322 |
| 1320 String toString() => "VariableMirror on '${MirrorSystem.getName(simpleName)}'" ; | 1323 String toString() => "VariableMirror on '${MirrorSystem.getName(simpleName)}'" ; |
| 1321 | 1324 |
| 1322 static _VariableMirror_type(reflectee) | 1325 static _VariableMirror_type(reflectee, instantiator) |
| 1323 native "VariableMirror_type"; | 1326 native "VariableMirror_type"; |
| 1324 } | 1327 } |
| 1325 | 1328 |
| 1326 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl | 1329 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl |
| 1327 implements ParameterMirror { | 1330 implements ParameterMirror { |
| 1328 _LocalParameterMirrorImpl(reflectee, | 1331 _LocalParameterMirrorImpl(reflectee, |
| 1329 String simpleName, | 1332 String simpleName, |
| 1330 DeclarationMirror owner, | 1333 DeclarationMirror owner, |
| 1331 this._position, | 1334 this._position, |
| 1332 this.isOptional, | 1335 this.isOptional, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1354 } | 1357 } |
| 1355 if (_defaultValue == null) { | 1358 if (_defaultValue == null) { |
| 1356 _defaultValue = reflect(_defaultValueReflectee); | 1359 _defaultValue = reflect(_defaultValueReflectee); |
| 1357 } | 1360 } |
| 1358 return _defaultValue; | 1361 return _defaultValue; |
| 1359 } | 1362 } |
| 1360 | 1363 |
| 1361 bool get hasDefaultValue => _defaultValueReflectee != null; | 1364 bool get hasDefaultValue => _defaultValueReflectee != null; |
| 1362 | 1365 |
| 1363 List<InstanceMirror> get metadata { | 1366 List<InstanceMirror> get metadata { |
| 1364 if ( _unmirroredMetadata == null) return emptyList; | 1367 if (_unmirroredMetadata == null) return emptyList; |
| 1365 return new UnmodifiableListView(_unmirroredMetadata.map(reflect)); | 1368 return new UnmodifiableListView(_unmirroredMetadata.map(reflect)); |
| 1366 } | 1369 } |
| 1367 | 1370 |
| 1371 Type get _instantiator { | |
| 1372 return owner.owner is ClassMirror ? owner.owner._reflectedType : null; | |
| 1373 } | |
| 1374 | |
| 1368 TypeMirror _type = null; | 1375 TypeMirror _type = null; |
| 1369 TypeMirror get type { | 1376 TypeMirror get type { |
| 1370 if (_type == null) { | 1377 if (_type == null) { |
| 1371 _type = reflectType(_ParameterMirror_type(_reflectee, _position)); | 1378 _type = reflectType( |
| 1372 _type = _type._instantiateInContextOf(owner); | 1379 _ParameterMirror_type(_reflectee, _position, _instantiator)); |
| 1373 } | 1380 } |
| 1374 return _type; | 1381 return _type; |
| 1375 } | 1382 } |
| 1376 | 1383 |
| 1377 String toString() => "ParameterMirror on '${_n(simpleName)}'"; | 1384 String toString() => "ParameterMirror on '${_n(simpleName)}'"; |
| 1378 | 1385 |
| 1379 static Type _ParameterMirror_type(_reflectee, _position) | 1386 static Type _ParameterMirror_type(_reflectee, _position, instantiator) |
| 1380 native "ParameterMirror_type"; | 1387 native "ParameterMirror_type"; |
| 1381 } | 1388 } |
| 1382 | 1389 |
| 1383 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl | 1390 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl |
| 1384 implements TypeMirror, DeclarationMirror { | 1391 implements TypeMirror, DeclarationMirror { |
| 1385 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); | 1392 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); |
| 1386 | 1393 |
| 1387 final bool isPrivate = false; | 1394 final bool isPrivate = false; |
| 1388 final DeclarationMirror owner = null; | 1395 final DeclarationMirror owner = null; |
| 1389 final Symbol simpleName; | 1396 final Symbol simpleName; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1468 if (typeMirror == null) { | 1475 if (typeMirror == null) { |
| 1469 typeMirror = makeLocalTypeMirror(key); | 1476 typeMirror = makeLocalTypeMirror(key); |
| 1470 _instanitationCache[key] = typeMirror; | 1477 _instanitationCache[key] = typeMirror; |
| 1471 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1478 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
| 1472 _declarationCache[key] = typeMirror; | 1479 _declarationCache[key] = typeMirror; |
| 1473 } | 1480 } |
| 1474 } | 1481 } |
| 1475 return typeMirror; | 1482 return typeMirror; |
| 1476 } | 1483 } |
| 1477 } | 1484 } |
| OLD | NEW |