| 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 // For the purposes of the mirrors library, we adopt a naming | 5 // For the purposes of the mirrors library, we adopt a naming |
| 6 // convention with respect to getters and setters. Specifically, for | 6 // convention with respect to getters and setters. Specifically, for |
| 7 // some variable or field... | 7 // some variable or field... |
| 8 // | 8 // |
| 9 // var myField; | 9 // var myField; |
| 10 // | 10 // |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 */ | 118 */ |
| 119 external static Symbol getSymbol(String name, [LibraryMirror library]); | 119 external static Symbol getSymbol(String name, [LibraryMirror library]); |
| 120 } | 120 } |
| 121 | 121 |
| 122 /** | 122 /** |
| 123 * Returns a [MirrorSystem] for the current isolate. | 123 * Returns a [MirrorSystem] for the current isolate. |
| 124 */ | 124 */ |
| 125 external MirrorSystem currentMirrorSystem(); | 125 external MirrorSystem currentMirrorSystem(); |
| 126 | 126 |
| 127 /** | 127 /** |
| 128 * Creates a [MirrorSystem] for the isolate which is listening on | |
| 129 * the [SendPort]. | |
| 130 */ | |
| 131 external Future<MirrorSystem> mirrorSystemOf(SendPort port); | |
| 132 | |
| 133 /** | |
| 134 * Reflects an instance. | 128 * Reflects an instance. |
| 135 * Returns an [InstanceMirror] reflecting [reflectee]. | 129 * Returns an [InstanceMirror] reflecting [reflectee]. |
| 136 * If [reflectee] is a function or an instance of a class | 130 * If [reflectee] is a function or an instance of a class |
| 137 * that has a [:call:] method, the returned instance mirror | 131 * that has a [:call:] method, the returned instance mirror |
| 138 * will be a [ClosureMirror]. | 132 * will be a [ClosureMirror]. |
| 139 * | 133 * |
| 140 * Note that since one cannot obtain an object from | 134 * Note that since one cannot obtain an object from |
| 141 * another isolate, this function can only be used to | 135 * another isolate, this function can only be used to |
| 142 * obtain mirrors on objects of the current isolate. | 136 * obtain mirrors on objects of the current isolate. |
| 143 */ | 137 */ |
| (...skipping 26 matching lines...) Expand all Loading... |
| 170 * another isolate, this function can only be used to | 164 * another isolate, this function can only be used to |
| 171 * obtain type mirrors on types of the current isolate. | 165 * obtain type mirrors on types of the current isolate. |
| 172 */ | 166 */ |
| 173 external TypeMirror reflectType(Type key); | 167 external TypeMirror reflectType(Type key); |
| 174 | 168 |
| 175 /** | 169 /** |
| 176 * A [Mirror] reflects some Dart language entity. | 170 * A [Mirror] reflects some Dart language entity. |
| 177 * | 171 * |
| 178 * Every [Mirror] originates from some [MirrorSystem]. | 172 * Every [Mirror] originates from some [MirrorSystem]. |
| 179 */ | 173 */ |
| 180 abstract class Mirror { | 174 abstract class Mirror {} |
| 181 /** | |
| 182 * The [MirrorSystem] that contains this mirror. | |
| 183 */ | |
| 184 MirrorSystem get mirrors; | |
| 185 } | |
| 186 | 175 |
| 187 /** | 176 /** |
| 188 * An [IsolateMirror] reflects an isolate. | 177 * An [IsolateMirror] reflects an isolate. |
| 189 */ | 178 */ |
| 190 abstract class IsolateMirror implements Mirror { | 179 abstract class IsolateMirror implements Mirror { |
| 191 /** | 180 /** |
| 192 * Returns a unique name used to refer to an isolate | 181 * Returns a unique name used to refer to an isolate |
| 193 * in debugging messages. | 182 * in debugging messages. |
| 194 */ | 183 */ |
| 195 String get debugName; | 184 String get debugName; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 * If the invocation returns a result *r*, this method returns | 401 * If the invocation returns a result *r*, this method returns |
| 413 * the result of calling [reflect]([value]). | 402 * the result of calling [reflect]([value]). |
| 414 * If the invocation causes a compilation error | 403 * If the invocation causes a compilation error |
| 415 * the effect is the same as if a non-reflective compilation error | 404 * the effect is the same as if a non-reflective compilation error |
| 416 * had been encountered. | 405 * had been encountered. |
| 417 * If the invocation throws an exception *e* (that it does not catch) | 406 * If the invocation throws an exception *e* (that it does not catch) |
| 418 * this method throws *e*. | 407 * this method throws *e*. |
| 419 */ | 408 */ |
| 420 /* TODO(turnidge): Handle ambiguous names.*/ | 409 /* TODO(turnidge): Handle ambiguous names.*/ |
| 421 InstanceMirror setField(Symbol fieldName, Object value); | 410 InstanceMirror setField(Symbol fieldName, Object value); |
| 422 | |
| 423 /** | |
| 424 * Invokes the named function and returns a mirror on the result. | |
| 425 * The arguments must be instances of [InstanceMirror], or of | |
| 426 * a type that is serializable across isolates (currently [num], | |
| 427 * [String], or [bool]). | |
| 428 * | |
| 429 * Let *o* be the object reflected by this mirror, let | |
| 430 * *f* be the simple name of the member denoted by [memberName], | |
| 431 * let *a1, ..., an* be the elements of [positionalArguments] | |
| 432 * let *k1, ..., km* be the identifiers denoted by the elements of | |
| 433 * [namedArguments.keys] | |
| 434 * and let *v1, ..., vm* be the elements of [namedArguments.values]. | |
| 435 * For each *ai*, if *ai* is an instance of [InstanceMirror], let *pi* | |
| 436 * be the object reflected by *ai*; otherwise let *pi = ai, i in 1 ...n*. | |
| 437 * Likewise, for each *vj*, if *vj* is an instance of [InstanceMirror], let *q
j* | |
| 438 * be the object reflected by *vj*; otherwise let *qj = vj, j in 1 ...m*. | |
| 439 * If any of the *pi, qj* is not an instance of [InstanceMirror] and | |
| 440 * is not serializable across isolates, an exception is thrown. | |
| 441 * Then this method will perform the method invocation | |
| 442 * *o.f(p1, ..., pn, k1: q1, ..., km: qm)* | |
| 443 * in a scope that has access to the private members | |
| 444 * of *o* (if *o* is a class or library) or the private members of the | |
| 445 * class of *o*(otherwise). | |
| 446 * The method returns a future *k*. | |
| 447 * If the invocation returns a result *r*, *k* will be completed | |
| 448 * with the result of calling [reflect](*r*). | |
| 449 * If the invocation throws an exception *e* (that it does not catch) | |
| 450 * then *k* is completed with a [MirrorError] wrapping *e*. | |
| 451 */ | |
| 452 /* | |
| 453 * TODO(turnidge): Handle ambiguous names. | |
| 454 * TODO(turnidge): Handle optional & named arguments. | |
| 455 */ | |
| 456 Future<InstanceMirror> invokeAsync(Symbol memberName, | |
| 457 List positionalArguments, | |
| 458 [Map<Symbol, dynamic> namedArguments]); | |
| 459 | |
| 460 /** | |
| 461 * Invokes a getter and returns a mirror on the result. The getter | |
| 462 * can be the implicit getter for a field or a user-defined getter | |
| 463 * method. | |
| 464 * | |
| 465 * Let *o* be the object reflected by this mirror, let | |
| 466 * *f* be the simple name of the getter denoted by [fieldName], | |
| 467 * Then this method will perform the getter invocation | |
| 468 * *o.f* | |
| 469 * in a scope that has access to the private members | |
| 470 * of *o* (if *o* is a class or library) or the private members of the | |
| 471 * class of *o*(otherwise). | |
| 472 * | |
| 473 * If this mirror is an [InstanceMirror], and [fieldName] denotes an instance | |
| 474 * method on its reflectee, the result of the invocation is an instance | |
| 475 * mirror on a closure corresponding to that method. | |
| 476 * | |
| 477 * If this mirror is a [LibraryMirror], and [fieldName] denotes a top-level | |
| 478 * method in the corresponding library, the result of the invocation is an | |
| 479 * instance mirror on a closure corresponding to that method. | |
| 480 * | |
| 481 * If this mirror is a [ClassMirror], and [fieldName] denotes a static method | |
| 482 * in the corresponding class, the result of the invocation is an instance | |
| 483 * mirror on a closure corresponding to that method. | |
| 484 * | |
| 485 * The method returns a future *k*. | |
| 486 * If the invocation returns a result *r*, *k* will be completed | |
| 487 * with the result of calling [reflect](*r*). | |
| 488 * If the invocation throws an exception *e* (that it does not catch) | |
| 489 * then *k* is completed with a [MirrorError] wrapping *e*. | |
| 490 */ | |
| 491 /* TODO(turnidge): Handle ambiguous names.*/ | |
| 492 Future<InstanceMirror> getFieldAsync(Symbol fieldName); | |
| 493 | |
| 494 /** | |
| 495 * Invokes a setter and returns a mirror on the result. The setter | |
| 496 * may be either the implicit setter for a non-final field or a | |
| 497 * user-defined setter method. | |
| 498 * The second argument must be an instance of [InstanceMirror], or of | |
| 499 * a type that is serializable across isolates (currently [num], | |
| 500 * [String], or [bool]). | |
| 501 * | |
| 502 * Let *o* be the object reflected by this mirror, let | |
| 503 * *f* be the simple name of the getter denoted by [fieldName], | |
| 504 * and let a be the object bound to [value]. If *a* is an instance of | |
| 505 * [InstanceMirror] let *p* be the object | |
| 506 * reflected by *a*, otherwise let *p =a*. | |
| 507 * If *p* is not an instance of [InstanceMirror], *p* must be | |
| 508 * serializable across isolates or an exception is thrown. | |
| 509 * Then this method will perform the setter invocation | |
| 510 * *o.f = a* | |
| 511 * in a scope that has access to the private members | |
| 512 * of *o* (if *o* is a class or library) or the private members of the | |
| 513 * class of *o*(otherwise). | |
| 514 * The method returns a future *k*. | |
| 515 * If the invocation returns a result *r*, *k* will be completed | |
| 516 * with the result of calling [reflect](*r*). | |
| 517 * If the invocation throws an exception *e* (that it does not catch) | |
| 518 * then *k* is completed with a [MirrorError} wrapping *e*. | |
| 519 */ | |
| 520 /* TODO(turnidge): Handle ambiguous names.*/ | |
| 521 Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object value); | |
| 522 } | 411 } |
| 523 | 412 |
| 524 /** | 413 /** |
| 525 * An [InstanceMirror] reflects an instance of a Dart language object. | 414 * An [InstanceMirror] reflects an instance of a Dart language object. |
| 526 */ | 415 */ |
| 527 abstract class InstanceMirror implements ObjectMirror { | 416 abstract class InstanceMirror implements ObjectMirror { |
| 528 /** | 417 /** |
| 529 * A mirror on the type of the reflectee. | 418 * A mirror on the type of the reflectee. |
| 530 * | 419 * |
| 531 * Returns a mirror on the actual class of the reflectee. | 420 * Returns a mirror on the actual class of the reflectee. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 * the result of calling [reflect](*r*). | 498 * the result of calling [reflect](*r*). |
| 610 * If the invocation causes a compilation error | 499 * If the invocation causes a compilation error |
| 611 * this method throws a [MirrorError]. | 500 * this method throws a [MirrorError]. |
| 612 * If the invocation throws an exception *e* (that it does not catch) | 501 * If the invocation throws an exception *e* (that it does not catch) |
| 613 * this method throws *e*. | 502 * this method throws *e*. |
| 614 */ | 503 */ |
| 615 InstanceMirror apply(List positionalArguments, | 504 InstanceMirror apply(List positionalArguments, |
| 616 [Map<Symbol, dynamic> namedArguments]); | 505 [Map<Symbol, dynamic> namedArguments]); |
| 617 | 506 |
| 618 /** | 507 /** |
| 619 * Executes the closure and returns a mirror on the result. | |
| 620 * | |
| 621 * Let *f* be the closure reflected by this mirror, | |
| 622 * let *a1, ..., an* be the elements of [positionalArguments] | |
| 623 * let *k1, ..., km* be the identifiers denoted by the elements of | |
| 624 * [namedArguments.keys] | |
| 625 * and let *v1, ..., vm* be the elements of [namedArguments.values]. | |
| 626 * For each *ai*, if *ai* is an instance of [InstanceMirror], let *pi* | |
| 627 * be the object reflected by *ai*; otherwise let *pi = ai, i in 1 ...n*. | |
| 628 * Likewise, for each *vj*, if *vj* is an instance of [InstanceMirror], let | |
| 629 * *qj* | |
| 630 * be the object reflected by *vj*; otherwise let *qj = vj, j in 1 ...m*. | |
| 631 * If any of the *pi, qj* is not an instance of [InstanceMirror] and | |
| 632 * is not serializable across isolates, an exception is thrown. | |
| 633 * Then this method will perform the function invocation | |
| 634 * *f(p1, ..., pn, k1: q1, ..., km: qm)* | |
| 635 * The method returns a future *k*. | |
| 636 * If the invocation returns a result *r*, *k* will be completed | |
| 637 * with the result of calling [reflect](*r*). | |
| 638 * If the invocation throws an exception *e* (that it does not catch) | |
| 639 * then *k* is completed with a [MirrorError] wrapping *e*. | |
| 640 * | |
| 641 * The arguments must be instances of [InstanceMirror], or of | |
| 642 * a type that is serializable across isolates (currently [num], | |
| 643 * [String], or [bool]). | |
| 644 */ | |
| 645 Future<InstanceMirror> applyAsync(List positionalArguments, | |
| 646 [Map<Symbol, dynamic> namedArguments]); | |
| 647 | |
| 648 /** | |
| 649 * Looks up the value of a name in the scope of the closure. The | 508 * Looks up the value of a name in the scope of the closure. The |
| 650 * result is a mirror on that value. | 509 * result is a mirror on that value. |
| 651 * | 510 * |
| 652 * Let *s* be the contents of the string used to construct the symbol [name]. | 511 * Let *s* be the contents of the string used to construct the symbol [name]. |
| 653 * | 512 * |
| 654 * If the expression *s* occurs within the source code of the reflectee, | 513 * If the expression *s* occurs within the source code of the reflectee, |
| 655 * and if any such occurrence refers to a declaration outside the reflectee, | 514 * and if any such occurrence refers to a declaration outside the reflectee, |
| 656 * then let *v* be the result of evaluating the expression *s* at such | 515 * then let *v* be the result of evaluating the expression *s* at such |
| 657 * an occurrence. | 516 * an occurrence. |
| 658 * If *s = this*, and the reflectee was defined within the instance scope of | 517 * If *s = this*, and the reflectee was defined within the instance scope of |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 * the effect is the same as if a non-reflective compilation error | 773 * the effect is the same as if a non-reflective compilation error |
| 915 * had been encountered. | 774 * had been encountered. |
| 916 * If evaluating the expression throws an exception *e* | 775 * If evaluating the expression throws an exception *e* |
| 917 * (that it does not catch) | 776 * (that it does not catch) |
| 918 * this method throws *e*. | 777 * this method throws *e*. |
| 919 */ | 778 */ |
| 920 InstanceMirror newInstance(Symbol constructorName, | 779 InstanceMirror newInstance(Symbol constructorName, |
| 921 List positionalArguments, | 780 List positionalArguments, |
| 922 [Map<Symbol,dynamic> namedArguments]); | 781 [Map<Symbol,dynamic> namedArguments]); |
| 923 | 782 |
| 924 /** | |
| 925 * Invokes the named function and returns a mirror on the result. | |
| 926 * The arguments must be instances of [InstanceMirror], or of | |
| 927 * a type that is serializable across isolates (currently [num], | |
| 928 * [String], or [bool]). | |
| 929 * | |
| 930 * Let *c* be the class reflected by this mirror, | |
| 931 * let *a1, ..., an* be the elements of [positionalArguments] | |
| 932 * let *k1, ..., km* be the identifiers denoted by the elements of | |
| 933 * [namedArguments.keys] | |
| 934 * and let *v1, ..., vm* be the elements of [namedArguments.values]. | |
| 935 * For each *ai*, if *ai* is an instance of [InstanceMirror], let *pi* | |
| 936 * be the object reflected by *ai*; otherwise let *pi = ai, i in 1 ...n*. | |
| 937 * Likewise, for each *vj*, if *vj* is an instance of [InstanceMirror], let | |
| 938 * *qj* | |
| 939 * be the object reflected by *vj*; otherwise let *qj = vj, j in 1 ...m*. | |
| 940 * If any of the *pi, qj* is not an instance of [InstanceMirror] and | |
| 941 * is not serializable across isolates, an exception is thrown. | |
| 942 * If [constructorName] was created from the empty string | |
| 943 * Then this method will execute the instance creation expression | |
| 944 * *new c(a1, ..., an, k1: v1, ..., km: vm)* | |
| 945 * in a scope that has access to the private members | |
| 946 * of *c*. Otherwise, let | |
| 947 * *f* be the simple name of the constructor denoted by [constructorName] | |
| 948 * Then this method will execute the instance creation expression | |
| 949 * *new c.f(a1, ..., an, k1: v1, ..., km: vm)* | |
| 950 * in a scope that has access to the private members | |
| 951 * of *c*. | |
| 952 * In either case: | |
| 953 * The method returns a future *k*. | |
| 954 * If the invocation returns a result *r*, *k* will be completed | |
| 955 * with the result of calling [reflect](*r*). | |
| 956 * If the invocation throws an exception *e* (that it does not catch) | |
| 957 * then *k* is completed with a [MirrorError] wrapping *e*. | |
| 958 */ | |
| 959 Future<InstanceMirror> newInstanceAsync(Symbol constructorName, | |
| 960 List positionalArguments, | |
| 961 [Map<Symbol, dynamic> namedArguments])
; | |
| 962 | |
| 963 /** | 783 /** |
| 964 * Returns [:true:] if this mirror is equal to [other]. | 784 * Returns [:true:] if this mirror is equal to [other]. |
| 965 * Otherwise returns [:false:]. | 785 * Otherwise returns [:false:]. |
| 966 * | 786 * |
| 967 * The equality holds if and only if | 787 * The equality holds if and only if |
| 968 * (1) [other] is a mirror of the same kind | 788 * (1) [other] is a mirror of the same kind |
| 969 * and | 789 * and |
| 970 * (2) This mirror and [other] reflect the same class. | 790 * (2) This mirror and [other] reflect the same class. |
| 971 * | 791 * |
| 972 * Note that if the reflected class is an invocation of | 792 * Note that if the reflected class is an invocation of |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1422 * | 1242 * |
| 1423 * When used as metadata on an import of "dart:mirrors", this metadata does | 1243 * When used as metadata on an import of "dart:mirrors", this metadata does |
| 1424 * not apply to the library in which the annotation is used, but instead | 1244 * not apply to the library in which the annotation is used, but instead |
| 1425 * applies to the other libraries (all libraries if "*" is used). | 1245 * applies to the other libraries (all libraries if "*" is used). |
| 1426 */ | 1246 */ |
| 1427 final override; | 1247 final override; |
| 1428 | 1248 |
| 1429 const MirrorsUsed( | 1249 const MirrorsUsed( |
| 1430 {this.symbols, this.targets, this.metaTargets, this.override}); | 1250 {this.symbols, this.targets, this.metaTargets, this.override}); |
| 1431 } | 1251 } |
| OLD | NEW |