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 } |
11 | 11 |
12 Map _filterMap(Map old_map, bool filter(key, value)) { | 12 Map _filterMap(Map old_map, bool filter(key, value)) { |
13 Map new_map = new Map(); | 13 Map new_map = new Map(); |
14 old_map.forEach((key, value) { | 14 old_map.forEach((key, value) { |
15 if (filter(key, value)) { | 15 if (filter(key, value)) { |
16 new_map[key] = value; | 16 new_map[key] = value; |
17 } | 17 } |
18 }); | 18 }); |
19 return new_map; | 19 return new_map; |
20 } | 20 } |
21 | 21 |
22 // DO NOT SUBMIT: Find better solution for dealing with privacy. | |
23 class _PrivateSymbol implements Symbol { | |
ahe
2013/04/11 20:12:27
This part is work in progress. My intention is to
| |
24 final String _name; | |
25 | |
26 const _PrivateSymbol(this._name); | |
27 | |
28 bool operator ==(other) { | |
29 return other is _PrivateSymbol && _name == other._name; | |
30 } | |
31 | |
32 int get hashCode { | |
33 const arbitraryPrime = 664597; | |
34 return 0x1fffffff & (arbitraryPrime * _name.hashCode); | |
35 } | |
36 } | |
37 | |
38 String _n(Symbol symbol) { | |
ahe
2013/04/11 20:12:27
I should probably find a better name for this meth
| |
39 if (symbol is _PrivateSymbol) { | |
40 return symbol._name; | |
41 } else { | |
42 return Symbol.getName(symbol); | |
43 } | |
44 } | |
45 | |
46 Symbol _s(String name) { | |
47 if (name == null) return null; | |
48 if (name.startsWith('_')) return new _PrivateSymbol(name); | |
49 return new Symbol((name == '<TODO:unnamed>') ? '' : name); | |
ahe
2013/04/11 20:12:27
I need to be able to turn validation of Symbols of
| |
50 } | |
51 | |
52 Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) { | |
53 if (owner == null) return simpleName; | |
54 return _s('${_n(owner.qualifiedName)}.${_n(simpleName)}'); | |
55 } | |
56 | |
57 Map<Symbol, dynamic> _convertStringToSymbolMap(Map<String, dynamic> map) { | |
58 if (map == null) return null; | |
59 Map<Symbol, dynamic> result = new Map<Symbol, dynamic>(); | |
60 map.forEach((name, value) => result[_s(name)] = value); | |
61 return result; | |
62 } | |
63 | |
22 String _makeSignatureString(TypeMirror returnType, | 64 String _makeSignatureString(TypeMirror returnType, |
23 List<ParameterMirror> parameters) { | 65 List<ParameterMirror> parameters) { |
24 StringBuffer buf = new StringBuffer(); | 66 StringBuffer buf = new StringBuffer(); |
25 buf.write(returnType.qualifiedName); | 67 buf.write(_n(returnType.qualifiedName)); |
26 buf.write(' ('); | 68 buf.write(' ('); |
27 bool found_optional_param = false; | 69 bool found_optional_param = false; |
28 for (int i = 0; i < parameters.length; i++) { | 70 for (int i = 0; i < parameters.length; i++) { |
29 var param = parameters[i]; | 71 var param = parameters[i]; |
30 if (param.isOptional && !found_optional_param) { | 72 if (param.isOptional && !found_optional_param) { |
31 buf.write('['); | 73 buf.write('['); |
32 found_optional_param = true; | 74 found_optional_param = true; |
33 } | 75 } |
34 buf.write(param.type.qualifiedName); | 76 buf.write(_n(param.type.qualifiedName)); |
35 if (i < (parameters.length - 1)) { | 77 if (i < (parameters.length - 1)) { |
36 buf.write(', '); | 78 buf.write(', '); |
37 } | 79 } |
38 } | 80 } |
39 if (found_optional_param) { | 81 if (found_optional_param) { |
40 buf.write(']'); | 82 buf.write(']'); |
41 } | 83 } |
42 buf.write(')'); | 84 buf.write(')'); |
43 return buf.toString(); | 85 return buf.toString(); |
44 } | 86 } |
45 | 87 |
46 class _LocalMirrorSystemImpl implements MirrorSystem { | 88 class _LocalMirrorSystemImpl implements MirrorSystem { |
47 _LocalMirrorSystemImpl(this.libraries, this.isolate) | 89 // TODO(ahe): [libraries] should be Map<Uri, LibraryMirror>. |
48 : _functionTypes = new Map<String, FunctionTypeMirror>() {} | 90 // Change parameter back to "this.libraries" when native code is changed. |
91 _LocalMirrorSystemImpl(Map<String, LibraryMirror> libraries, this.isolate) | |
92 : _functionTypes = new Map<String, FunctionTypeMirror>(), | |
93 this.libraries = _convertStringToSymbolMap(libraries); | |
49 | 94 |
50 final Map<String, LibraryMirror> libraries; | 95 final Map<Symbol, LibraryMirror> libraries; |
51 final IsolateMirror isolate; | 96 final IsolateMirror isolate; |
52 | 97 |
53 TypeMirror _dynamicType = null; | 98 TypeMirror _dynamicType = null; |
54 | 99 |
55 TypeMirror get dynamicType { | 100 TypeMirror get dynamicType { |
56 if (_dynamicType == null) { | 101 if (_dynamicType == null) { |
57 _dynamicType = | 102 _dynamicType = |
58 new _LocalClassMirrorImpl( | 103 new _LocalClassMirrorImpl( |
59 null, 'dynamic', false, null, null, [], null, | 104 null, 'dynamic', false, null, null, [], null, |
60 const {}, const {}, const {}); | 105 const {}, const {}, const {}); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 // For now, all VMObjects hold a VMReference. We could consider | 177 // For now, all VMObjects hold a VMReference. We could consider |
133 // storing the Object reference itself here if the object is a Dart | 178 // storing the Object reference itself here if the object is a Dart |
134 // language objects (except for objects of type VMReference, of | 179 // language objects (except for objects of type VMReference, of |
135 // course). | 180 // course). |
136 VMReference _reference; | 181 VMReference _reference; |
137 } | 182 } |
138 | 183 |
139 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl | 184 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl |
140 implements ObjectMirror { | 185 implements ObjectMirror { |
141 _LocalObjectMirrorImpl(ref) : super(ref) {} | 186 _LocalObjectMirrorImpl(ref) : super(ref) {} |
142 | 187 |
143 Future<InstanceMirror> invokeAsync(String memberName, | 188 Future<InstanceMirror> invokeAsync(Symbol memberName, |
144 List positionalArguments, | 189 List positionalArguments, |
145 [Map<String,dynamic> namedArguments]) { | 190 [Map<Symbol, dynamic> namedArguments]) { |
146 if (namedArguments != null) { | 191 if (namedArguments != null) { |
147 throw new UnimplementedError( | 192 throw new UnimplementedError( |
148 'named argument support is not implemented'); | 193 'named argument support is not implemented'); |
149 } | 194 } |
150 // Walk the arguments and make sure they are legal. | 195 // Walk the arguments and make sure they are legal. |
151 for (int i = 0; i < positionalArguments.length; i++) { | 196 for (int i = 0; i < positionalArguments.length; i++) { |
152 var arg = positionalArguments[i]; | 197 var arg = positionalArguments[i]; |
153 _validateArgument(i, arg); | 198 _validateArgument(i, arg); |
154 } | 199 } |
155 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 200 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
156 try { | 201 try { |
157 completer.complete( | 202 completer.complete( |
158 _invoke(this, memberName, positionalArguments)); | 203 _invoke(this, memberName, positionalArguments)); |
159 } catch (exception, s) { | 204 } catch (exception, s) { |
160 completer.completeError(exception, s); | 205 completer.completeError(exception, s); |
161 } | 206 } |
162 return completer.future; | 207 return completer.future; |
163 } | 208 } |
164 | 209 |
165 Future<InstanceMirror> getFieldAsync(String fieldName) { | 210 Future<InstanceMirror> getFieldAsync(Symbol fieldName) { |
166 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 211 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
167 try { | 212 try { |
168 completer.complete(_getField(this, fieldName)); | 213 completer.complete(_getField(this, _n(fieldName))); |
169 } catch (exception, s) { | 214 } catch (exception, s) { |
170 completer.completeError(exception, s); | 215 completer.completeError(exception, s); |
171 } | 216 } |
172 return completer.future; | 217 return completer.future; |
173 } | 218 } |
174 | 219 |
175 Future<InstanceMirror> setFieldAsync(String fieldName, Object arg) { | 220 Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object arg) { |
176 _validateArgument(0, arg); | 221 _validateArgument(0, arg); |
177 | 222 |
178 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 223 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
179 try { | 224 try { |
180 completer.complete(_setField(this, fieldName, arg)); | 225 completer.complete(_setField(this, _n(fieldName), arg)); |
181 } catch (exception, s) { | 226 } catch (exception, s) { |
182 completer.completeError(exception, s); | 227 completer.completeError(exception, s); |
183 } | 228 } |
184 return completer.future; | 229 return completer.future; |
185 } | 230 } |
186 | 231 |
187 static _validateArgument(int i, Object arg) | 232 static _validateArgument(int i, Object arg) |
188 { | 233 { |
189 if (arg is Mirror) { | 234 if (arg is Mirror) { |
190 if (arg is! InstanceMirror) { | 235 if (arg is! InstanceMirror) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 this.function) : super(ref, type, reflectee) {} | 342 this.function) : super(ref, type, reflectee) {} |
298 | 343 |
299 final MethodMirror function; | 344 final MethodMirror function; |
300 | 345 |
301 String get source { | 346 String get source { |
302 throw new UnimplementedError( | 347 throw new UnimplementedError( |
303 'ClosureMirror.source is not implemented'); | 348 'ClosureMirror.source is not implemented'); |
304 } | 349 } |
305 | 350 |
306 Future<InstanceMirror> applyAsync(List<Object> positionalArguments, | 351 Future<InstanceMirror> applyAsync(List<Object> positionalArguments, |
307 [Map<String,Object> namedArguments]) { | 352 [Map<Symbol, Object> namedArguments]) { |
308 if (namedArguments != null) { | 353 if (namedArguments != null) { |
309 throw new UnimplementedError( | 354 throw new UnimplementedError( |
310 'named argument support is not implemented'); | 355 'named argument support is not implemented'); |
311 } | 356 } |
312 // Walk the arguments and make sure they are legal. | 357 // Walk the arguments and make sure they are legal. |
313 for (int i = 0; i < positionalArguments.length; i++) { | 358 for (int i = 0; i < positionalArguments.length; i++) { |
314 var arg = positionalArguments[i]; | 359 var arg = positionalArguments[i]; |
315 _LocalObjectMirrorImpl._validateArgument(i, arg); | 360 _LocalObjectMirrorImpl._validateArgument(i, arg); |
316 } | 361 } |
317 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 362 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
318 try { | 363 try { |
319 completer.complete( | 364 completer.complete( |
320 _apply(this, positionalArguments)); | 365 _apply(this, positionalArguments)); |
321 } catch (exception) { | 366 } catch (exception) { |
322 completer.completeError(exception); | 367 completer.completeError(exception); |
323 } | 368 } |
324 return completer.future; | 369 return completer.future; |
325 } | 370 } |
326 | 371 |
327 Future<InstanceMirror> findInContext(String name) { | 372 Future<InstanceMirror> findInContext(Symbol name) { |
328 throw new UnimplementedError( | 373 throw new UnimplementedError( |
329 'ClosureMirror.findInContext() is not implemented'); | 374 'ClosureMirror.findInContext() is not implemented'); |
330 } | 375 } |
331 | 376 |
332 static _apply(ref, positionalArguments) | 377 static _apply(ref, positionalArguments) |
333 native 'LocalClosureMirrorImpl_apply'; | 378 native 'LocalClosureMirrorImpl_apply'; |
334 } | 379 } |
335 | 380 |
336 class _LazyTypeMirror { | 381 class _LazyTypeMirror { |
337 _LazyTypeMirror(this.libraryName, this.typeName) {} | 382 _LazyTypeMirror(String libraryName, String typeName) |
383 : this.libraryName = _s(libraryName), | |
384 this.typeName = _s(typeName); | |
338 | 385 |
339 TypeMirror resolve(MirrorSystem mirrors) { | 386 TypeMirror resolve(MirrorSystem mirrors) { |
340 if (libraryName == null) { | 387 if (libraryName == null) { |
341 if (typeName == 'dynamic') { | 388 if (typeName == 'dynamic') { |
342 return mirrors.dynamicType; | 389 return mirrors.dynamicType; |
343 } else if (typeName == 'void') { | 390 } else if (typeName == 'void') { |
344 return mirrors.voidType; | 391 return mirrors.voidType; |
345 } else { | 392 } else { |
346 throw new UnimplementedError( | 393 throw new UnimplementedError( |
347 "Mirror for type '$typeName' is not implemented"); | 394 "Mirror for type '$typeName' is not implemented"); |
348 } | 395 } |
349 } | 396 } |
350 var resolved = mirrors.libraries[libraryName].members[typeName]; | 397 var resolved = mirrors.libraries[libraryName].members[typeName]; |
351 if (resolved == null) { | 398 if (resolved == null) { |
352 throw new UnimplementedError( | 399 throw new UnimplementedError( |
353 "Mirror for type '$typeName' is not implemented"); | 400 "Mirror for type '$typeName' is not implemented"); |
354 } | 401 } |
355 return resolved; | 402 return resolved; |
356 } | 403 } |
357 | 404 |
358 final String libraryName; | 405 final Symbol libraryName; |
359 final String typeName; | 406 final Symbol typeName; |
360 } | 407 } |
361 | 408 |
362 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl | 409 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl |
363 implements ClassMirror { | 410 implements ClassMirror { |
364 _LocalClassMirrorImpl(ref, | 411 _LocalClassMirrorImpl(ref, |
365 this.simpleName, | 412 String simpleName, |
366 this.isClass, | 413 this.isClass, |
367 this._owner, | 414 this._owner, |
368 this._superclass, | 415 this._superclass, |
369 this._superinterfaces, | 416 this._superinterfaces, |
370 this._defaultFactory, | 417 this._defaultFactory, |
371 this.members, | 418 Map<String, Mirror> members, |
372 this.constructors, | 419 Map<String, Mirror> constructors, |
373 this.typeVariables) : super(ref) {} | 420 Map<String, Mirror> typeVariables) |
421 : this.simpleName = _s(simpleName), | |
422 this.members = _convertStringToSymbolMap(members), | |
423 this.constructors = _convertStringToSymbolMap(constructors), | |
424 this.typeVariables = _convertStringToSymbolMap(typeVariables), | |
425 super(ref); | |
374 | 426 |
375 final String simpleName; | 427 final Symbol simpleName; |
376 | 428 |
377 String _qualifiedName = null; | 429 Symbol _qualifiedName = null; |
378 String get qualifiedName { | 430 Symbol get qualifiedName { |
379 if (_owner != null) { | 431 if (_qualifiedName == null) { |
380 if (_qualifiedName == null) { | 432 _qualifiedName = _computeQualifiedName(owner, simpleName); |
381 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; | |
382 } | |
383 } else { | |
384 // The owner of a ClassMirror is null in certain odd cases, like | |
385 // 'void', 'dynamic' and function type mirrors. | |
386 _qualifiedName = simpleName; | |
387 } | 433 } |
388 return _qualifiedName; | 434 return _qualifiedName; |
389 } | 435 } |
390 | 436 |
391 var _owner; | 437 var _owner; |
392 DeclarationMirror get owner { | 438 DeclarationMirror get owner { |
393 if (_owner != null && _owner is! Mirror) { | 439 if (_owner != null && _owner is! Mirror) { |
394 _owner = _owner.resolve(mirrors); | 440 _owner = _owner.resolve(mirrors); |
395 } | 441 } |
396 return _owner; | 442 return _owner; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 } | 475 } |
430 | 476 |
431 var _defaultFactory; | 477 var _defaultFactory; |
432 ClassMirror get defaultFactory { | 478 ClassMirror get defaultFactory { |
433 if (_defaultFactory != null && _defaultFactory is! Mirror) { | 479 if (_defaultFactory != null && _defaultFactory is! Mirror) { |
434 _defaultFactory = _defaultFactory.resolve(mirrors); | 480 _defaultFactory = _defaultFactory.resolve(mirrors); |
435 } | 481 } |
436 return _defaultFactory; | 482 return _defaultFactory; |
437 } | 483 } |
438 | 484 |
439 final Map<String, Mirror> members; | 485 final Map<Symbol, Mirror> members; |
440 | 486 |
441 Map<String, MethodMirror> _methods = null; | 487 Map<Symbol, MethodMirror> _methods = null; |
442 Map<String, MethodMirror> _getters = null; | 488 Map<Symbol, MethodMirror> _getters = null; |
443 Map<String, MethodMirror> _setters = null; | 489 Map<Symbol, MethodMirror> _setters = null; |
444 Map<String, VariableMirror> _variables = null; | 490 Map<Symbol, VariableMirror> _variables = null; |
445 | 491 |
446 Map<String, MethodMirror> get methods { | 492 Map<Symbol, MethodMirror> get methods { |
447 if (_methods == null) { | 493 if (_methods == null) { |
448 _methods = _filterMap( | 494 _methods = _filterMap( |
449 members, | 495 members, |
450 (key, value) => (value is MethodMirror && value.isRegularMethod)); | 496 (key, value) => (value is MethodMirror && value.isRegularMethod)); |
451 } | 497 } |
452 return _methods; | 498 return _methods; |
453 } | 499 } |
454 | 500 |
455 Map<String, MethodMirror> get getters { | 501 Map<Symbol, MethodMirror> get getters { |
456 if (_getters == null) { | 502 if (_getters == null) { |
457 _getters = _filterMap( | 503 _getters = _filterMap( |
458 members, | 504 members, |
459 (key, value) => (value is MethodMirror && value.isGetter)); | 505 (key, value) => (value is MethodMirror && value.isGetter)); |
460 } | 506 } |
461 return _getters; | 507 return _getters; |
462 } | 508 } |
463 | 509 |
464 Map<String, MethodMirror> get setters { | 510 Map<Symbol, MethodMirror> get setters { |
465 if (_setters == null) { | 511 if (_setters == null) { |
466 _setters = _filterMap( | 512 _setters = _filterMap( |
467 members, | 513 members, |
468 (key, value) => (value is MethodMirror && value.isSetter)); | 514 (key, value) => (value is MethodMirror && value.isSetter)); |
469 } | 515 } |
470 return _setters; | 516 return _setters; |
471 } | 517 } |
472 | 518 |
473 Map<String, VariableMirror> get variables { | 519 Map<Symbol, VariableMirror> get variables { |
474 if (_variables == null) { | 520 if (_variables == null) { |
475 _variables = _filterMap( | 521 _variables = _filterMap( |
476 members, | 522 members, |
477 (key, value) => (value is VariableMirror)); | 523 (key, value) => (value is VariableMirror)); |
478 } | 524 } |
479 return _variables; | 525 return _variables; |
480 } | 526 } |
481 | 527 |
482 Map<String, MethodMirror> constructors; | 528 Map<Symbol, MethodMirror> constructors; |
483 Map<String, TypeVariableMirror> typeVariables; | 529 Map<Symbol, TypeVariableMirror> typeVariables; |
484 | 530 |
485 Map<String, TypeMirror> get typeArguments { | 531 Map<Symbol, TypeMirror> get typeArguments { |
486 throw new UnimplementedError( | 532 throw new UnimplementedError( |
487 'ClassMirror.typeArguments is not implemented'); | 533 'ClassMirror.typeArguments is not implemented'); |
488 } | 534 } |
489 | 535 |
490 bool get isOriginalDeclaration { | 536 bool get isOriginalDeclaration { |
491 throw new UnimplementedError( | 537 throw new UnimplementedError( |
492 'ClassMirror.isOriginalDeclaration is not implemented'); | 538 'ClassMirror.isOriginalDeclaration is not implemented'); |
493 } | 539 } |
494 | 540 |
495 ClassMirror get genericDeclaration { | 541 ClassMirror get genericDeclaration { |
496 throw new UnimplementedError( | 542 throw new UnimplementedError( |
497 'ClassMirror.originalDeclaration is not implemented'); | 543 'ClassMirror.originalDeclaration is not implemented'); |
498 } | 544 } |
499 | 545 |
500 String toString() => "ClassMirror on '$simpleName'"; | 546 String toString() => "ClassMirror on '$simpleName'"; |
501 | 547 |
502 Future<InstanceMirror> newInstanceAsync(String constructorName, | 548 Future<InstanceMirror> newInstanceAsync(Symbol constructorName, |
503 List positionalArguments, | 549 List positionalArguments, |
504 [Map<String,dynamic> namedArguments]) { | 550 [Map<Symbol, dynamic> namedArguments]) { |
505 if (namedArguments != null) { | 551 if (namedArguments != null) { |
506 throw new UnimplementedError( | 552 throw new UnimplementedError( |
507 'named argument support is not implemented'); | 553 'named argument support is not implemented'); |
508 } | 554 } |
509 // Walk the arguments and make sure they are legal. | 555 // Walk the arguments and make sure they are legal. |
510 for (int i = 0; i < positionalArguments.length; i++) { | 556 for (int i = 0; i < positionalArguments.length; i++) { |
511 var arg = positionalArguments[i]; | 557 var arg = positionalArguments[i]; |
512 _LocalObjectMirrorImpl._validateArgument(i, arg); | 558 _LocalObjectMirrorImpl._validateArgument(i, arg); |
513 } | 559 } |
514 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 560 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
515 try { | 561 try { |
516 completer.complete( | 562 completer.complete( |
517 _invokeConstructor(this, constructorName, positionalArguments)); | 563 _invokeConstructor(this, _n(constructorName), positionalArguments)); |
518 } catch (exception) { | 564 } catch (exception) { |
519 completer.completeError(exception); | 565 completer.completeError(exception); |
520 } | 566 } |
521 return completer.future; | 567 return completer.future; |
522 } | 568 } |
523 | 569 |
524 static _invokeConstructor(ref, constructorName, positionalArguments) | 570 static _invokeConstructor(ref, constructorName, positionalArguments) |
525 native 'LocalClassMirrorImpl_invokeConstructor'; | 571 native 'LocalClassMirrorImpl_invokeConstructor'; |
526 } | 572 } |
527 | 573 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 | 615 |
570 | 616 |
571 class _LazyTypeVariableMirror { | 617 class _LazyTypeVariableMirror { |
572 _LazyTypeVariableMirror(this._variableName, this._owner) {} | 618 _LazyTypeVariableMirror(this._variableName, this._owner) {} |
573 | 619 |
574 TypeVariableMirror resolve(MirrorSystem mirrors) { | 620 TypeVariableMirror resolve(MirrorSystem mirrors) { |
575 ClassMirror owner = _owner.resolve(mirrors); | 621 ClassMirror owner = _owner.resolve(mirrors); |
576 return owner.typeVariables[_variableName]; | 622 return owner.typeVariables[_variableName]; |
577 } | 623 } |
578 | 624 |
625 // TODO(ahe): Symbol? | |
579 final String _variableName; | 626 final String _variableName; |
580 final _LazyTypeMirror _owner; | 627 final _LazyTypeMirror _owner; |
581 } | 628 } |
582 | 629 |
583 class _LocalTypeVariableMirrorImpl extends _LocalMirrorImpl | 630 class _LocalTypeVariableMirrorImpl extends _LocalMirrorImpl |
584 implements TypeVariableMirror { | 631 implements TypeVariableMirror { |
585 _LocalTypeVariableMirrorImpl(this.simpleName, | 632 _LocalTypeVariableMirrorImpl(String simpleName, |
586 this._owner, | 633 this._owner, |
587 this._upperBound) {} | 634 this._upperBound) |
588 final String simpleName; | 635 : this.simpleName = _s(simpleName); |
589 | 636 |
590 String _qualifiedName = null; | 637 final Symbol simpleName; |
591 String get qualifiedName { | 638 |
639 Symbol _qualifiedName = null; | |
640 Symbol get qualifiedName { | |
592 if (_qualifiedName == null) { | 641 if (_qualifiedName == null) { |
593 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; | 642 _qualifiedName = _computeQualifiedName(owner, simpleName); |
594 } | 643 } |
595 return _qualifiedName; | 644 return _qualifiedName; |
596 } | 645 } |
597 | 646 |
598 var _owner; | 647 var _owner; |
599 DeclarationMirror get owner { | 648 DeclarationMirror get owner { |
600 if (_owner is! Mirror) { | 649 if (_owner is! Mirror) { |
601 _owner = _owner.resolve(mirrors); | 650 _owner = _owner.resolve(mirrors); |
602 } | 651 } |
603 return _owner; | 652 return _owner; |
(...skipping 15 matching lines...) Expand all Loading... | |
619 } | 668 } |
620 return _upperBound; | 669 return _upperBound; |
621 } | 670 } |
622 | 671 |
623 String toString() => "TypeVariableMirror on '$simpleName'"; | 672 String toString() => "TypeVariableMirror on '$simpleName'"; |
624 } | 673 } |
625 | 674 |
626 | 675 |
627 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl | 676 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl |
628 implements TypedefMirror { | 677 implements TypedefMirror { |
629 _LocalTypedefMirrorImpl(this.simpleName, | 678 _LocalTypedefMirrorImpl(String simpleName, |
630 this._owner, | 679 this._owner, |
631 this._referent) {} | 680 this._referent) |
632 final String simpleName; | 681 : this.simpleName = _s(simpleName); |
633 | 682 |
634 String _qualifiedName = null; | 683 final Symbol simpleName; |
635 String get qualifiedName { | 684 |
685 Symbol _qualifiedName = null; | |
686 Symbol get qualifiedName { | |
636 if (_qualifiedName == null) { | 687 if (_qualifiedName == null) { |
637 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; | 688 _qualifiedName = _computeQualifiedName(owner, simpleName); |
638 } | 689 } |
639 return _qualifiedName; | 690 return _qualifiedName; |
640 } | 691 } |
641 | 692 |
642 var _owner; | 693 var _owner; |
643 DeclarationMirror get owner { | 694 DeclarationMirror get owner { |
644 if (_owner is! Mirror) { | 695 if (_owner is! Mirror) { |
645 _owner = _owner.resolve(mirrors); | 696 _owner = _owner.resolve(mirrors); |
646 } | 697 } |
647 return _owner; | 698 return _owner; |
(...skipping 14 matching lines...) Expand all Loading... | |
662 _referent = _referent.resolve(mirrors); | 713 _referent = _referent.resolve(mirrors); |
663 } | 714 } |
664 return _referent; | 715 return _referent; |
665 } | 716 } |
666 | 717 |
667 String toString() => "TypedefMirror on '$simpleName'"; | 718 String toString() => "TypedefMirror on '$simpleName'"; |
668 } | 719 } |
669 | 720 |
670 | 721 |
671 class _LazyLibraryMirror { | 722 class _LazyLibraryMirror { |
672 _LazyLibraryMirror(this.libraryName) {} | 723 _LazyLibraryMirror(String libraryName) |
724 : this.libraryName = _s(libraryName); | |
673 | 725 |
674 LibraryMirror resolve(MirrorSystem mirrors) { | 726 LibraryMirror resolve(MirrorSystem mirrors) { |
675 return mirrors.libraries[libraryName]; | 727 return mirrors.libraries[libraryName]; |
676 } | 728 } |
677 | 729 |
678 final String libraryName; | 730 final Symbol libraryName; |
679 } | 731 } |
680 | 732 |
681 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl | 733 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl |
682 implements LibraryMirror { | 734 implements LibraryMirror { |
683 _LocalLibraryMirrorImpl(ref, | 735 _LocalLibraryMirrorImpl(ref, |
684 this.simpleName, | 736 String simpleName, |
685 this.url, | 737 this.url, |
686 this.members) : super(ref) {} | 738 Map<String, Mirror> members) |
739 : this.simpleName = _s(simpleName), | |
740 this.members = _convertStringToSymbolMap(members), | |
741 super(ref); | |
687 | 742 |
688 final String simpleName; | 743 final Symbol simpleName; |
689 | 744 |
690 // The simple name and the qualified name are the same for a library. | 745 // The simple name and the qualified name are the same for a library. |
691 String get qualifiedName => simpleName; | 746 Symbol get qualifiedName => simpleName; |
692 | 747 |
693 // Always null for libraries. | 748 // Always null for libraries. |
694 final DeclarationMirror owner = null; | 749 final DeclarationMirror owner = null; |
695 | 750 |
696 // Always false for libraries. | 751 // Always false for libraries. |
697 final bool isPrivate = false; | 752 final bool isPrivate = false; |
698 | 753 |
699 // Always false for libraries. | 754 // Always false for libraries. |
700 final bool isTopLevel = false; | 755 final bool isTopLevel = false; |
701 | 756 |
702 SourceLocation get location { | 757 SourceLocation get location { |
703 throw new UnimplementedError( | 758 throw new UnimplementedError( |
704 'LibraryMirror.location is not implemented'); | 759 'LibraryMirror.location is not implemented'); |
705 } | 760 } |
706 | 761 |
707 final String url; | 762 final String url; |
708 final Map<String, Mirror> members; | 763 final Map<Symbol, Mirror> members; |
709 | 764 |
710 Map<String, ClassMirror> _classes = null; | 765 Map<Symbol, ClassMirror> _classes = null; |
711 Map<String, MethodMirror> _functions = null; | 766 Map<Symbol, MethodMirror> _functions = null; |
712 Map<String, MethodMirror> _getters = null; | 767 Map<Symbol, MethodMirror> _getters = null; |
713 Map<String, MethodMirror> _setters = null; | 768 Map<Symbol, MethodMirror> _setters = null; |
714 Map<String, VariableMirror> _variables = null; | 769 Map<Symbol, VariableMirror> _variables = null; |
715 | 770 |
716 Map<String, ClassMirror> get classes { | 771 Map<Symbol, ClassMirror> get classes { |
717 if (_classes == null) { | 772 if (_classes == null) { |
718 _classes = _filterMap(members, | 773 _classes = _filterMap(members, |
719 (key, value) => (value is ClassMirror)); | 774 (key, value) => (value is ClassMirror)); |
720 } | 775 } |
721 return _classes; | 776 return _classes; |
722 } | 777 } |
723 | 778 |
724 Map<String, MethodMirror> get functions { | 779 Map<Symbol, MethodMirror> get functions { |
725 if (_functions == null) { | 780 if (_functions == null) { |
726 _functions = _filterMap(members, | 781 _functions = _filterMap(members, |
727 (key, value) => (value is MethodMirror)); | 782 (key, value) => (value is MethodMirror)); |
728 } | 783 } |
729 return _functions; | 784 return _functions; |
730 } | 785 } |
731 | 786 |
732 Map<String, MethodMirror> get getters { | 787 Map<Symbol, MethodMirror> get getters { |
733 if (_getters == null) { | 788 if (_getters == null) { |
734 _getters = _filterMap(functions, | 789 _getters = _filterMap(functions, |
735 (key, value) => (value.isGetter)); | 790 (key, value) => (value.isGetter)); |
736 } | 791 } |
737 return _getters; | 792 return _getters; |
738 } | 793 } |
739 | 794 |
740 Map<String, MethodMirror> get setters { | 795 Map<Symbol, MethodMirror> get setters { |
741 if (_setters == null) { | 796 if (_setters == null) { |
742 _setters = _filterMap(functions, | 797 _setters = _filterMap(functions, |
743 (key, value) => (value.isSetter)); | 798 (key, value) => (value.isSetter)); |
744 } | 799 } |
745 return _setters; | 800 return _setters; |
746 } | 801 } |
747 | 802 |
748 Map<String, VariableMirror> get variables { | 803 Map<Symbol, VariableMirror> get variables { |
749 if (_variables == null) { | 804 if (_variables == null) { |
750 _variables = _filterMap(members, | 805 _variables = _filterMap(members, |
751 (key, value) => (value is VariableMirror)); | 806 (key, value) => (value is VariableMirror)); |
752 } | 807 } |
753 return _variables; | 808 return _variables; |
754 } | 809 } |
755 | 810 |
756 String toString() => "LibraryMirror on '$simpleName'"; | 811 String toString() => "LibraryMirror on '$simpleName'"; |
757 } | 812 } |
758 | 813 |
759 class _LocalMethodMirrorImpl extends _LocalMirrorImpl | 814 class _LocalMethodMirrorImpl extends _LocalMirrorImpl |
760 implements MethodMirror { | 815 implements MethodMirror { |
761 _LocalMethodMirrorImpl(this.simpleName, | 816 _LocalMethodMirrorImpl(String simpleName, |
762 this._owner, | 817 this._owner, |
763 this.parameters, | 818 this.parameters, |
764 this._returnType, | 819 this._returnType, |
765 this.isStatic, | 820 this.isStatic, |
766 this.isAbstract, | 821 this.isAbstract, |
767 this.isGetter, | 822 this.isGetter, |
768 this.isSetter, | 823 this.isSetter, |
769 this.isConstructor, | 824 this.isConstructor, |
770 this.isConstConstructor, | 825 this.isConstConstructor, |
771 this.isGenerativeConstructor, | 826 this.isGenerativeConstructor, |
772 this.isRedirectingConstructor, | 827 this.isRedirectingConstructor, |
773 this.isFactoryConstructor) {} | 828 this.isFactoryConstructor) |
829 : this.simpleName = _s(simpleName); | |
774 | 830 |
775 final String simpleName; | 831 final Symbol simpleName; |
776 | 832 |
777 String _qualifiedName = null; | 833 Symbol _qualifiedName = null; |
778 String get qualifiedName { | 834 Symbol get qualifiedName { |
779 if (_qualifiedName == null) { | 835 if (_qualifiedName == null) { |
780 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; | 836 _qualifiedName = _computeQualifiedName(owner, simpleName); |
781 } | 837 } |
782 return _qualifiedName; | 838 return _qualifiedName; |
783 } | 839 } |
784 | 840 |
785 var _owner; | 841 var _owner; |
786 DeclarationMirror get owner { | 842 DeclarationMirror get owner { |
787 if (_owner is! Mirror) { | 843 if (_owner is! Mirror) { |
788 _owner = _owner.resolve(mirrors); | 844 _owner = _owner.resolve(mirrors); |
789 } | 845 } |
790 return _owner; | 846 return _owner; |
(...skipping 28 matching lines...) Expand all Loading... | |
819 TypeMirror get isOperator { | 875 TypeMirror get isOperator { |
820 throw new UnimplementedError( | 876 throw new UnimplementedError( |
821 'MethodMirror.isOperator is not implemented'); | 877 'MethodMirror.isOperator is not implemented'); |
822 } | 878 } |
823 | 879 |
824 final bool isGetter; | 880 final bool isGetter; |
825 final bool isSetter; | 881 final bool isSetter; |
826 final bool isConstructor; | 882 final bool isConstructor; |
827 | 883 |
828 var _constructorName = null; | 884 var _constructorName = null; |
829 String get constructorName { | 885 Symbol get constructorName { |
830 if (_constructorName == null) { | 886 if (_constructorName == null) { |
831 if (!isConstructor) { | 887 if (!isConstructor) { |
832 _constructorName = ''; | 888 _constructorName = ''; |
833 } else { | 889 } else { |
834 var parts = simpleName.split('.'); | 890 var parts = simpleName.split('.'); |
835 if (parts.length > 2) { | 891 if (parts.length > 2) { |
836 throw new MirrorException( | 892 throw new MirrorException( |
837 'Internal error in MethodMirror.constructorName: ' | 893 'Internal error in MethodMirror.constructorName: ' |
838 'malformed name <$simpleName>'); | 894 'malformed name <$simpleName>'); |
839 } else if (parts.length == 2) { | 895 } else if (parts.length == 2) { |
840 _constructorName = parts[1]; | 896 _constructorName = parts[1]; |
841 } else { | 897 } else { |
842 _constructorName = ''; | 898 _constructorName = ''; |
843 } | 899 } |
844 } | 900 } |
845 } | 901 } |
846 return _constructorName; | 902 return _constructorName; |
847 } | 903 } |
848 | 904 |
849 final bool isConstConstructor; | 905 final bool isConstConstructor; |
850 final bool isGenerativeConstructor; | 906 final bool isGenerativeConstructor; |
851 final bool isRedirectingConstructor; | 907 final bool isRedirectingConstructor; |
852 final bool isFactoryConstructor; | 908 final bool isFactoryConstructor; |
853 | 909 |
854 String toString() => "MethodMirror on '$simpleName'"; | 910 String toString() => "MethodMirror on '$simpleName'"; |
855 } | 911 } |
856 | 912 |
857 class _LocalVariableMirrorImpl extends _LocalMirrorImpl | 913 class _LocalVariableMirrorImpl extends _LocalMirrorImpl |
858 implements VariableMirror { | 914 implements VariableMirror { |
859 _LocalVariableMirrorImpl(this.simpleName, | 915 _LocalVariableMirrorImpl(String simpleName, |
860 this._owner, | 916 this._owner, |
861 this._type, | 917 this._type, |
862 this.isStatic, | 918 this.isStatic, |
863 this.isFinal) {} | 919 this.isFinal) |
920 : this.simpleName = _s(simpleName); | |
864 | 921 |
865 final String simpleName; | 922 final Symbol simpleName; |
866 | 923 |
867 String _qualifiedName = null; | 924 Symbol _qualifiedName = null; |
868 String get qualifiedName { | 925 Symbol get qualifiedName { |
869 if (_qualifiedName == null) { | 926 if (_qualifiedName == null) { |
870 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; | 927 _qualifiedName = _computeQualifiedName(owner, simpleName); |
871 } | 928 } |
872 return _qualifiedName; | 929 return _qualifiedName; |
873 } | 930 } |
874 | 931 |
875 var _owner; | 932 var _owner; |
876 DeclarationMirror get owner { | 933 DeclarationMirror get owner { |
877 if (_owner is! Mirror) { | 934 if (_owner is! Mirror) { |
878 _owner = _owner.resolve(mirrors); | 935 _owner = _owner.resolve(mirrors); |
879 } | 936 } |
880 return _owner; | 937 return _owner; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
966 | 1023 |
967 // Creates a new local mirror for some Object. | 1024 // Creates a new local mirror for some Object. |
968 static InstanceMirror reflect(Object reflectee) { | 1025 static InstanceMirror reflect(Object reflectee) { |
969 return makeLocalInstanceMirror(reflectee); | 1026 return makeLocalInstanceMirror(reflectee); |
970 } | 1027 } |
971 | 1028 |
972 static ClassMirror reflectClass(Type reflectee) { | 1029 static ClassMirror reflectClass(Type reflectee) { |
973 throw new UnimplementedError('reflectClass is not implemented'); | 1030 throw new UnimplementedError('reflectClass is not implemented'); |
974 } | 1031 } |
975 } | 1032 } |
OLD | NEW |