| 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" show UnmodifiableListView, UnmodifiableMapView; | 7 import "dart:collection" show UnmodifiableListView, UnmodifiableMapView; |
| 8 import "dart:async" show Future; | 8 import "dart:async" show Future; |
| 9 | 9 |
| 10 var dirty = false; | 10 var dirty = false; |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 } | 364 } |
| 365 | 365 |
| 366 InstanceMirror getField(Symbol memberName) { | 366 InstanceMirror getField(Symbol memberName) { |
| 367 return reflect(this._invokeGetter(_reflectee, _n(memberName))); | 367 return reflect(this._invokeGetter(_reflectee, _n(memberName))); |
| 368 } | 368 } |
| 369 | 369 |
| 370 InstanceMirror setField(Symbol memberName, Object value) { | 370 InstanceMirror setField(Symbol memberName, Object value) { |
| 371 this._invokeSetter(_reflectee, _n(memberName), value); | 371 this._invokeSetter(_reflectee, _n(memberName), value); |
| 372 return reflect(value); | 372 return reflect(value); |
| 373 } | 373 } |
| 374 |
| 375 delegate(Invocation invocation) { |
| 376 if (invocation.isMethod) { |
| 377 return this.invoke(invocation.memberName, |
| 378 invocation.positionalArguments, |
| 379 invocation.namedArguments).reflectee; |
| 380 } |
| 381 if (invocation.isGetter) { |
| 382 return this.getField(invocation.memberName).reflectee; |
| 383 } |
| 384 if (invocation.isSetter) { |
| 385 var unwrapped = _n(invocation.memberName); |
| 386 var withoutEqual = _s(unwrapped.substring(0, unwrapped.length - 1)); |
| 387 var arg = invocation.positionalArguments[0]; |
| 388 this.setField(withoutEqual, arg).reflectee; |
| 389 return arg; |
| 390 } |
| 391 throw "UNREACHABLE"; |
| 392 } |
| 374 } | 393 } |
| 375 | 394 |
| 376 class _LocalInstanceMirror extends _LocalObjectMirror | 395 class _LocalInstanceMirror extends _LocalObjectMirror |
| 377 implements InstanceMirror { | 396 implements InstanceMirror { |
| 378 | 397 |
| 379 _LocalInstanceMirror(reflectee) : super(reflectee); | 398 _LocalInstanceMirror(reflectee) : super(reflectee); |
| 380 | 399 |
| 381 ClassMirror _type; | 400 ClassMirror _type; |
| 382 ClassMirror get type { | 401 ClassMirror get type { |
| 383 if (_type == null) { | 402 if (_type == null) { |
| 384 // Note it not safe to use reflectee.runtimeType because runtimeType may | 403 // Note it not safe to use reflectee.runtimeType because runtimeType may |
| 385 // be overridden. | 404 // be overridden. |
| 386 _type = reflectType(_computeType(reflectee)); | 405 _type = reflectType(_computeType(reflectee)); |
| 387 } | 406 } |
| 388 return _type; | 407 return _type; |
| 389 } | 408 } |
| 390 | 409 |
| 391 // LocalInstanceMirrors always reflect local instances | 410 // LocalInstanceMirrors always reflect local instances |
| 392 bool get hasReflectee => true; | 411 bool get hasReflectee => true; |
| 393 | 412 |
| 394 get reflectee => _reflectee; | 413 get reflectee => _reflectee; |
| 395 | 414 |
| 396 delegate(Invocation invocation) { | |
| 397 if (invocation.isMethod) { | |
| 398 return this.invoke(invocation.memberName, | |
| 399 invocation.positionalArguments, | |
| 400 invocation.namedArguments).reflectee; | |
| 401 } | |
| 402 if (invocation.isGetter) { | |
| 403 return this.getField(invocation.memberName).reflectee; | |
| 404 } | |
| 405 if (invocation.isSetter) { | |
| 406 var unwrapped = _n(invocation.memberName); | |
| 407 var withoutEqual = _s(unwrapped.substring(0, unwrapped.length - 1)); | |
| 408 var arg = invocation.positionalArguments[0]; | |
| 409 this.setField(withoutEqual, arg).reflectee; | |
| 410 return arg; | |
| 411 } | |
| 412 throw "UNREACHABLE"; | |
| 413 } | |
| 414 | |
| 415 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; | 415 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; |
| 416 | 416 |
| 417 bool operator ==(other) { | 417 bool operator ==(other) { |
| 418 return other is _LocalInstanceMirror && | 418 return other is _LocalInstanceMirror && |
| 419 identical(_reflectee, other._reflectee); | 419 identical(_reflectee, other._reflectee); |
| 420 } | 420 } |
| 421 | 421 |
| 422 int get hashCode { | 422 int get hashCode { |
| 423 // Avoid hash collisions with the reflectee. This constant is in Smi range | 423 // Avoid hash collisions with the reflectee. This constant is in Smi range |
| 424 // and happens to be the inner padding from RFC 2104. | 424 // and happens to be the inner padding from RFC 2104. |
| (...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1664 if (typeMirror == null) { | 1664 if (typeMirror == null) { |
| 1665 typeMirror = makeLocalTypeMirror(key); | 1665 typeMirror = makeLocalTypeMirror(key); |
| 1666 _instanitationCache[key] = typeMirror; | 1666 _instanitationCache[key] = typeMirror; |
| 1667 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1667 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
| 1668 _declarationCache[key] = typeMirror; | 1668 _declarationCache[key] = typeMirror; |
| 1669 } | 1669 } |
| 1670 } | 1670 } |
| 1671 return typeMirror; | 1671 return typeMirror; |
| 1672 } | 1672 } |
| 1673 } | 1673 } |
| OLD | NEW |