| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 Map<Symbol, dynamic> _convertStringToSymbolMap(Map<String, dynamic> map) { | 42 Map<Symbol, dynamic> _convertStringToSymbolMap(Map<String, dynamic> map) { |
| 43 if (map == null) return null; | 43 if (map == null) return null; |
| 44 Map<Symbol, dynamic> result = new Map<Symbol, dynamic>(); | 44 Map<Symbol, dynamic> result = new Map<Symbol, dynamic>(); |
| 45 map.forEach((name, value) => result[_s(name)] = value); | 45 map.forEach((name, value) => result[_s(name)] = value); |
| 46 return result; | 46 return result; |
| 47 } | 47 } |
| 48 | 48 |
| 49 String _makeSignatureString(TypeMirror returnType, | 49 String _makeSignatureString(TypeMirror returnType, |
| 50 List<ParameterMirror> parameters) { | 50 List<ParameterMirror> parameters) { |
| 51 StringBuffer buf = new StringBuffer(); | 51 StringBuffer buf = new StringBuffer(); |
| 52 buf.write(_n(returnType.qualifiedName)); | 52 buf.write('('); |
| 53 buf.write(' ('); | 53 bool found_optional_positional = false; |
| 54 bool found_optional_param = false; | 54 bool found_optional_named = false; |
| 55 |
| 55 for (int i = 0; i < parameters.length; i++) { | 56 for (int i = 0; i < parameters.length; i++) { |
| 56 var param = parameters[i]; | 57 var param = parameters[i]; |
| 57 if (param.isOptional && !found_optional_param) { | 58 if (param.isOptional && param.isNamed && !found_optional_named) { |
| 59 buf.write('{'); |
| 60 found_optional_named = true; |
| 61 } |
| 62 if (param.isOptional && !param.isNamed && !found_optional_positional) { |
| 58 buf.write('['); | 63 buf.write('['); |
| 59 found_optional_param = true; | 64 found_optional_positional = true; |
| 65 } |
| 66 if (param.isNamed) { |
| 67 buf.write(_n(param.simpleName)); |
| 68 buf.write(': '); |
| 60 } | 69 } |
| 61 buf.write(_n(param.type.qualifiedName)); | 70 buf.write(_n(param.type.qualifiedName)); |
| 62 if (i < (parameters.length - 1)) { | 71 if (i < (parameters.length - 1)) { |
| 63 buf.write(', '); | 72 buf.write(', '); |
| 64 } | 73 } |
| 65 } | 74 } |
| 66 if (found_optional_param) { | 75 if (found_optional_named) { |
| 76 buf.write('}'); |
| 77 } |
| 78 if (found_optional_positional) { |
| 67 buf.write(']'); | 79 buf.write(']'); |
| 68 } | 80 } |
| 69 buf.write(')'); | 81 buf.write(') -> '); |
| 82 buf.write(_n(returnType.qualifiedName)); |
| 70 return buf.toString(); | 83 return buf.toString(); |
| 71 } | 84 } |
| 72 | 85 |
| 73 Map<Uri, LibraryMirror> _createLibrariesMap(List<LibraryMirror> list) { | 86 Map<Uri, LibraryMirror> _createLibrariesMap(List<LibraryMirror> list) { |
| 74 var map = new Map<Uri, LibraryMirror>(); | 87 var map = new Map<Uri, LibraryMirror>(); |
| 75 list.forEach((LibraryMirror mirror) => map[mirror.uri] = mirror); | 88 list.forEach((LibraryMirror mirror) => map[mirror.uri] = mirror); |
| 76 return map; | 89 return map; |
| 77 } | 90 } |
| 78 | 91 |
| 79 List _metadata(reflectee) | 92 List _metadata(reflectee) |
| (...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 | 1272 |
| 1260 TypeMirror _type = null; | 1273 TypeMirror _type = null; |
| 1261 TypeMirror get type { | 1274 TypeMirror get type { |
| 1262 if (_type == null) { | 1275 if (_type == null) { |
| 1263 _type = | 1276 _type = |
| 1264 _Mirrors._reflectType(_ParameterMirror_type(_reflectee, _position)); | 1277 _Mirrors._reflectType(_ParameterMirror_type(_reflectee, _position)); |
| 1265 } | 1278 } |
| 1266 return _type; | 1279 return _type; |
| 1267 } | 1280 } |
| 1268 | 1281 |
| 1282 String toString() => "ParameterMirror on '${_n(simpleName)}'"; |
| 1283 |
| 1269 static Type _ParameterMirror_type(_reflectee, _position) | 1284 static Type _ParameterMirror_type(_reflectee, _position) |
| 1270 native "ParameterMirror_type"; | 1285 native "ParameterMirror_type"; |
| 1271 } | 1286 } |
| 1272 | 1287 |
| 1273 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl | 1288 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl |
| 1274 implements TypeMirror, DeclarationMirror { | 1289 implements TypeMirror, DeclarationMirror { |
| 1275 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); | 1290 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); |
| 1276 | 1291 |
| 1277 final bool isPrivate = false; | 1292 final bool isPrivate = false; |
| 1278 final bool isTopLevel = true; | 1293 final bool isTopLevel = true; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1371 if (typeMirror == null) { | 1386 if (typeMirror == null) { |
| 1372 typeMirror = makeLocalTypeMirror(key); | 1387 typeMirror = makeLocalTypeMirror(key); |
| 1373 _instanitationCache[key] = typeMirror; | 1388 _instanitationCache[key] = typeMirror; |
| 1374 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1389 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
| 1375 _declarationCache[key] = typeMirror; | 1390 _declarationCache[key] = typeMirror; |
| 1376 } | 1391 } |
| 1377 } | 1392 } |
| 1378 return typeMirror; | 1393 return typeMirror; |
| 1379 } | 1394 } |
| 1380 } | 1395 } |
| OLD | NEW |