Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1165)

Side by Side Diff: dart/sdk/lib/mirrors/mirrors.dart

Issue 23455028: Mirrors overhaul. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 //
11 // ...the getter is named 'myField' and the setter is named 11 // ...the getter is named 'myField' and the setter is named
12 // 'myField='. This allows us to assign unique names to getters and 12 // 'myField='. This allows us to assign unique names to getters and
13 // setters for the purposes of member lookup. 13 // setters for the purposes of member lookup.
14 14
15 // Open questions:
16 // Turn all getters into final fields?
Johnni Winther 2013/09/03 12:36:57 Why?
17 // Need a way to invoke super methods.
18
15 /** 19 /**
16 * Basic reflection in Dart, 20 * Basic reflection in Dart,
17 * with support for introspection and dynamic evaluation. 21 * with support for introspection and dynamic evaluation.
18 * 22 *
19 * *Introspection* is that subset of reflection by which a running 23 * *Introspection* is that subset of reflection by which a running
20 * program can examine its own structure. For example, a function 24 * program can examine its own structure. For example, a function
21 * that prints out the names of all the members of an arbitrary object. 25 * that prints out the names of all the members of an arbitrary object.
22 * 26 *
23 * *Dynamic evaluation* refers the ability to evaluate code that 27 * *Dynamic evaluation* refers the ability to evaluate code that
24 * has not been literally specified at compile time, such as calling a method 28 * has not been literally specified at compile time, such as calling a method
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 */ 69 */
66 abstract class MirrorSystem { 70 abstract class MirrorSystem {
67 /** 71 /**
68 * An immutable map from from library names to mirrors for all 72 * An immutable map from from library names to mirrors for all
69 * libraries known to this mirror system. 73 * libraries known to this mirror system.
70 */ 74 */
71 Map<Uri, LibraryMirror> get libraries; 75 Map<Uri, LibraryMirror> get libraries;
72 76
73 /** 77 /**
74 * Returns an iterable of all libraries in the mirror system whose library 78 * Returns an iterable of all libraries in the mirror system whose library
75 * name is [libraryName]. 79 * name is [libraryName].
Johnni Winther 2013/09/03 12:36:57 Comment needs update.
gbracha 2013/10/03 22:11:25 Yes, can we please fix these issues in the CL so t
ahe 2013/10/30 07:48:31 Done.
76 */ 80 */
77 Iterable<LibraryMirror> findLibrary(Symbol libraryName) { 81 LibraryMirror findLibrary(Symbol libraryName) {
78 return libraries.values.where( 82 return libraries.values.singleWhere(
Alan Knight 2013/09/03 20:08:31 Might this be more useful if it used firstWhere so
ahe 2013/09/03 20:14:30 What I don't like about firstWhere is that it does
Alan Knight 2013/09/03 20:30:56 Does the error distinguish between the case of no
79 (library) => library.simpleName == libraryName); 83 (library) => library.simpleName == libraryName);
80 } 84 }
81 85
82 /** 86 /**
83 * A mirror on the isolate associated with this [MirrorSystem]. 87 * A mirror on the isolate associated with this [MirrorSystem].
84 * This may be null if this mirror system is not running. 88 * This may be null if this mirror system is not running.
85 */ 89 */
86 IsolateMirror get isolate; 90 IsolateMirror get isolate;
87 91
88 /** 92 /**
(...skipping 16 matching lines...) Expand all
105 */ 109 */
106 external static String getName(Symbol symbol); 110 external static String getName(Symbol symbol);
107 } 111 }
108 112
109 /** 113 /**
110 * Returns a [MirrorSystem] for the current isolate. 114 * Returns a [MirrorSystem] for the current isolate.
111 */ 115 */
112 external MirrorSystem currentMirrorSystem(); 116 external MirrorSystem currentMirrorSystem();
113 117
114 /** 118 /**
115 * Creates a [MirrorSystem] for the isolate which is listening on
116 * the [SendPort].
117 */
118 external Future<MirrorSystem> mirrorSystemOf(SendPort port);
119
120 /**
121 * Returns an [InstanceMirror] reflecting [reflectee]. 119 * Returns an [InstanceMirror] reflecting [reflectee].
122 * If [reflectee] is function or an instance of a class 120 * If [reflectee] is function or an instance of a class
123 * that has a [:call:] method, the returned instance mirror 121 * that has a [:call:] method, the returned instance mirror
124 * will be a [ClosureMirror]. 122 * will be a [ClosureMirror].
125 * 123 *
126 * Note that since one cannot obtain an object from 124 * Note that since one cannot obtain an object from
127 * another isolate, this function can only be used to 125 * another isolate, this function can only be used to
128 * obtain mirrors on objects of the current isolate. 126 * obtain mirrors on objects of the current isolate.
129 */ 127 */
130 external InstanceMirror reflect(Object reflectee); 128 external InstanceMirror reflect(Object reflectee);
(...skipping 11 matching lines...) Expand all
142 * another isolate, this function can only be used to 140 * another isolate, this function can only be used to
143 * obtain class mirrors on classes of the current isolate. 141 * obtain class mirrors on classes of the current isolate.
144 */ 142 */
145 external ClassMirror reflectClass(Type key); 143 external ClassMirror reflectClass(Type key);
146 144
147 /** 145 /**
148 * A [Mirror] reflects some Dart language entity. 146 * A [Mirror] reflects some Dart language entity.
149 * 147 *
150 * Every [Mirror] originates from some [MirrorSystem]. 148 * Every [Mirror] originates from some [MirrorSystem].
151 */ 149 */
152 abstract class Mirror { 150 abstract class Mirror {}
153 /**
154 * The [MirrorSystem] that contains this mirror.
155 */
156 MirrorSystem get mirrors;
157 }
158 151
159 /** 152 /**
160 * An [IsolateMirror] reflects an isolate. 153 * An [IsolateMirror] reflects an isolate.
161 */ 154 */
162 abstract class IsolateMirror implements Mirror { 155 abstract class IsolateMirror implements Mirror {
163 /** 156 /**
164 * Returns a unique name used to refer to an isolate 157 * Returns a unique name used to refer to an isolate
165 * in debugging messages. 158 * in debugging messages.
166 */ 159 */
167 String get debugName; 160 String get debugName;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 /** 252 /**
260 * Is this declaration top-level? 253 * Is this declaration top-level?
261 * 254 *
262 * This is defined to be equivalent to: 255 * This is defined to be equivalent to:
263 * [:mirror.owner != null && mirror.owner is LibraryMirror:] 256 * [:mirror.owner != null && mirror.owner is LibraryMirror:]
264 */ 257 */
265 bool get isTopLevel; 258 bool get isTopLevel;
266 259
267 /** 260 /**
268 * The source location of this Dart language entity. 261 * The source location of this Dart language entity.
262 *
263 * This operation is optional and may return [:null:].
269 */ 264 */
270 SourceLocation get location; 265 SourceLocation get location;
271 266
272 /** 267 /**
273 * A list of the metadata associated with this declaration. 268 * A list of the metadata associated with this declaration.
274 * 269 *
275 * Let *D* be the declaration this mirror reflects. 270 * Let *D* be the declaration this mirror reflects.
276 * If *D* is decorated with annotations *A1, ..., An* 271 * If *D* is decorated with annotations *A1, ..., An*
277 * where *n > 0*, then for each annotation *Ai* associated 272 * where *n > 0*, then for each annotation *Ai* associated
278 * with *D, 1 <= i <= n*, let *ci* be the constant object 273 * with *D, 1 <= i <= n*, let *ci* be the constant object
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 * this method throws *e*. 315 * this method throws *e*.
321 */ 316 */
322 /* 317 /*
323 * TODO(turnidge): Handle ambiguous names. 318 * TODO(turnidge): Handle ambiguous names.
324 * TODO(turnidge): Handle optional & named arguments. 319 * TODO(turnidge): Handle optional & named arguments.
325 */ 320 */
326 InstanceMirror invoke(Symbol memberName, 321 InstanceMirror invoke(Symbol memberName,
327 List positionalArguments, 322 List positionalArguments,
328 [Map<Symbol,dynamic> namedArguments]); 323 [Map<Symbol,dynamic> namedArguments]);
329 324
325
Johnni Winther 2013/09/03 12:36:57 Extra line.
330 /** 326 /**
331 * Invokes a getter and returns a mirror on the result. The getter 327 * Invokes a getter and returns a mirror on the result. The getter
332 * can be the implicit getter for a field or a user-defined getter 328 * can be the implicit getter for a field or a user-defined getter
333 * method. 329 * method.
334 * 330 *
335 * Let *o* be the object reflected by this mirror, let 331 * Let *o* be the object reflected by this mirror, let
336 * *f* be the simple name of the getter denoted by [fieldName], 332 * *f* be the simple name of the getter denoted by [fieldName],
337 * Then this method will perform the getter invocation 333 * Then this method will perform the getter invocation
338 * *o.f* 334 * *o.f*
339 * in a scope that has access to the private members 335 * in a scope that has access to the private members
340 * of *o* (if *o* is a class or library) or the private members of the 336 * of *o* (if *o* is a class or library) or the private members of the
341 * class of *o* (otherwise). 337 * class of *o* (otherwise).
338 *
339 * If this mirror is an [InstanceMirror], and [fieldName] denotes an instance
340 * method on its reflectee, the result of the invocation is an instance
341 * mirror on a closure corresponding to that method.
342 *
343 * If this mirror is a [LibraryMirror], and [fieldName] denotes a top-level
344 * method in the corresponding library, the result of the invocation is an
345 * instance mirror on a closure corresponding to that method.
346 *
347 * If this mirror is a [ClassMirror], and [fieldName] denotes a static method
348 * in the corresponding class, the result of the invocation is an instance
349 * mirror on a closure corresponding to that method.
gbracha 2013/10/03 22:11:25 I'd tweak the wording a bit at some point, because
ahe 2013/10/30 07:48:31 A kind soul fixed that for me in another CL :-)
350 *
342 * If the invocation returns a result *r*, this method returns 351 * If the invocation returns a result *r*, this method returns
343 * the result of calling [reflect](*r*). 352 * the result of calling [reflect](*r*).
344 * If the invocation causes a compilation error 353 * If the invocation causes a compilation error
345 * this method throws a [MirroredCompilationError]. 354 * this method throws a [MirroredCompilationError].
346 * If the invocation throws an exception *e* (that it does not catch) 355 * If the invocation throws an exception *e* (that it does not catch)
347 * this method throws *e*. 356 * this method throws *e*.
348 */ 357 */
349 /* TODO(turnidge): Handle ambiguous names.*/ 358 // TODO(ahe): Remove stuff about scope and private members. [fieldName] is a
359 // capability giving access to private members.
350 InstanceMirror getField(Symbol fieldName); 360 InstanceMirror getField(Symbol fieldName);
351 361
352 /** 362 /**
353 * Invokes a setter and returns a mirror on the result. The setter 363 * Invokes a setter and returns a mirror on the result. The setter
354 * may be either the implicit setter for a non-final field or a 364 * may be either the implicit setter for a non-final field or a
355 * user-defined setter method. 365 * user-defined setter method.
356 * 366 *
357 * Let *o* be the object reflected by this mirror, let 367 * Let *o* be the object reflected by this mirror, let
358 * *f* be the simple name of the getter denoted by [fieldName], 368 * *f* be the simple name of the getter denoted by [fieldName],
359 * and let *a* be the object bound to [value]. 369 * and let *a* be the object bound to [value].
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 * can be the implicit getter for a field or a user-defined getter 424 * can be the implicit getter for a field or a user-defined getter
415 * method. 425 * method.
416 * 426 *
417 * Let *o* be the object reflected by this mirror, let 427 * Let *o* be the object reflected by this mirror, let
418 * *f* be the simple name of the getter denoted by [fieldName], 428 * *f* be the simple name of the getter denoted by [fieldName],
419 * Then this method will perform the getter invocation 429 * Then this method will perform the getter invocation
420 * *o.f* 430 * *o.f*
421 * in a scope that has access to the private members 431 * in a scope that has access to the private members
422 * of *o* (if *o* is a class or library) or the private members of the 432 * of *o* (if *o* is a class or library) or the private members of the
423 * class of *o*(otherwise). 433 * class of *o*(otherwise).
434 *
Johnni Winther 2013/09/03 12:36:57 Extra line.
435 *
436 * If this mirror is an [InstanceMirror], and [fieldName] denotes an instance
437 * method on its reflectee, the result of the invocation is an instance
438 * mirror on a closure corresponding to that method.
439 *
440 * If this mirror is a [LibraryMirror], and [fieldName] denotes a top-level
441 * method in the corresponding library, the result of the invocation is an
442 * instance mirror on a closure corresponding to that method.
443 *
444 * If this mirror is a [ClassMirror], and [fieldName] denotes a static method
445 * in the corresponding class, the result of the invocation is an instance
446 * mirror on a closure corresponding to that method.
447 *
424 * The method returns a future *k*. 448 * The method returns a future *k*.
425 * If the invocation returns a result *r*, *k* will be completed 449 * If the invocation returns a result *r*, *k* will be completed
426 * with the result of calling [reflect](*r*). 450 * with the result of calling [reflect](*r*).
427 * If the invocation throws an exception *e* (that it does not catch) 451 * If the invocation throws an exception *e* (that it does not catch)
428 * then *k* is completed with a [MirrorError] wrapping *e*. 452 * then *k* is completed with a [MirrorError] wrapping *e*.
429 */ 453 */
430 /* TODO(turnidge): Handle ambiguous names.*/ 454 /* TODO(turnidge): Handle ambiguous names.*/
431 Future<InstanceMirror> getFieldAsync(Symbol fieldName); 455 Future<InstanceMirror> getFieldAsync(Symbol fieldName);
432 456
433 /** 457 /**
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 538
515 /** 539 /**
516 * Perform [invocation] on [reflectee]. 540 * Perform [invocation] on [reflectee].
517 * Equivalent to 541 * Equivalent to
518 * 542 *
519 * this.invoke(invocation.memberName, 543 * this.invoke(invocation.memberName,
520 * invocation.positionalArguments, 544 * invocation.positionalArguments,
521 * invocation.namedArguments); 545 * invocation.namedArguments);
522 */ 546 */
523 delegate(Invocation invocation); 547 delegate(Invocation invocation);
548
549 /**
550 * Returns closure for invoking the regular method named [name].
551 *
552 * If [:type.instanceLookup(name:] is a regular method, the result of this
Johnni Winther 2013/09/03 12:36:57 '(name' -> '(name)'. 'is a regular method' -> 'ret
gbracha 2013/10/03 22:11:25 We have made some tweaks to this wording in other
ahe 2013/10/30 07:48:31 I assume the other CL will land this change.
553 * method is a closure equivalent to:
554 *
555 * (r1, .., rn, {p1: d1, ..., pk: dk}) {
556 * return this.invoke(name, [r1, .., rn], {#p1: p1, .., #pk: pk});
557 * }
558 *
559 * if m has required parameters r1, ..., rn, and named parameters p1, ..., pk
560 * with defaults d1, ..., dk.
561 *
562 * (r1, .., rn, [p1 = d1, …, pk = dk]) {
563 * return this.invoke(name, [r1, .., rn, p1, .., pk]);
564 * }
565 *
566 * if m has required parameters r1, ..., rn, and optional positional
567 * parameters p1, ..., pk with defaults d1, ..., dk.
568 */
569 Function operator [](Symbol name);
524 } 570 }
525 571
526 /** 572 /**
527 * A [ClosureMirror] reflects a closure. 573 * A [ClosureMirror] reflects a closure.
528 * 574 *
529 * A [ClosureMirror] provides access to its captured variables and 575 * A [ClosureMirror] provides access to its captured variables and
530 * provides the ability to execute its reflectee. 576 * provides the ability to execute its reflectee.
531 */ 577 */
532 abstract class ClosureMirror implements InstanceMirror { 578 abstract class ClosureMirror implements InstanceMirror {
533 /** 579 /**
534 * A mirror on the function associated with this closure. 580 * A mirror on the function associated with this closure.
581 *
582 * The function associated with an implicit closure of a function is that
583 * function.
Johnni Winther 2013/09/03 12:36:57 'of a function is that function' -> 'of a method i
584 *
585 * The function associated with an instance of a class that has a [:call:]
586 * method is that [:call:] method.
535 */ 587 */
536 MethodMirror get function; 588 MethodMirror get function;
537 589
538 /** 590 /**
539 * Executes the closure and returns a mirror on the result. 591 * Executes the closure and returns a mirror on the result.
540 * Let *f* be the closure reflected by this mirror, 592 * Let *f* be the closure reflected by this mirror,
541 * let *a1, ..., an* be the elements of [positionalArguments] 593 * let *a1, ..., an* be the elements of [positionalArguments]
542 * let *k1, ..., km* be the identifiers denoted by the elements of 594 * let *k1, ..., km* be the identifiers denoted by the elements of
543 * [namedArguments.keys] 595 * [namedArguments.keys]
544 * and let *v1, ..., vm* be the elements of [namedArguments.values]. 596 * and let *v1, ..., vm* be the elements of [namedArguments.values].
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 * If the expression *s* occurs within the source code of the reflectee, 645 * If the expression *s* occurs within the source code of the reflectee,
594 * and that any such occurrence refers to a declaration outside the reflectee, 646 * and that any such occurrence refers to a declaration outside the reflectee,
595 * then let *v* be the result of evaluating the expression *s* at such 647 * then let *v* be the result of evaluating the expression *s* at such
596 * an occurrence. 648 * an occurrence.
597 * If *s = this*, and the reflectee was defined within the instance scope of 649 * If *s = this*, and the reflectee was defined within the instance scope of
598 * an object *o*, then let *v* be *o*. 650 * an object *o*, then let *v* be *o*.
599 * 651 *
600 * The returned value is the result of invoking the method [reflect] on 652 * The returned value is the result of invoking the method [reflect] on
601 * *v*. 653 * *v*.
602 */ 654 */
655 // TODO(ahe): Drop from release 1.0?
Michael Lippautz (Google) 2013/09/03 17:24:50 Or "This operation is optional and may return [:nu
gbracha 2013/10/03 22:11:25 We have real demand for this. What are its prospec
rmacnak 2013/10/03 22:26:41 This should be doable in dart2js because it compil
603 Future<InstanceMirror> findInContext(Symbol name); 656 Future<InstanceMirror> findInContext(Symbol name);
604 } 657 }
605 658
606 /** 659 /**
607 * A [LibraryMirror] reflects a Dart language library, providing 660 * A [LibraryMirror] reflects a Dart language library, providing
608 * access to the variables, functions, and classes of the 661 * access to the variables, functions, and classes of the
609 * library. 662 * library.
610 */ 663 */
611 abstract class LibraryMirror implements DeclarationMirror, ObjectMirror { 664 abstract class LibraryMirror implements DeclarationMirror, ObjectMirror {
612 /** 665 /**
613 * The absolute uri of the library. 666 * The absolute uri of the library.
614 */ 667 */
615 Uri get uri; 668 Uri get uri;
616 669
617 /** 670 /**
618 * An immutable map from from names to mirrors for all members in 671 * An immutable map from from names to mirrors for all members declared in
619 * this library. 672 * this library.
620 * 673 *
621 * The members of a library are its top-level classes, 674 * The members of a library are its top-level classes, functions, variables,
gbracha 2013/10/03 22:11:25 also typedefs
622 * functions, variables, getters, and setters. 675 * getters, and setters.
623 */ 676 */
624 Map<Symbol, Mirror> get members; 677 Map<Symbol, DeclarationMirror> get declarations;
gbracha 2013/09/17 18:27:53 See comments on declarations in ClassMirror below
625 678
626 /** 679 /**
627 * An immutable map from names to mirrors for all class 680 * Returns closure for invoking the regular method named [name].
628 * declarations in this library. 681 *
682 * If [:declarations[name]:] is a regular method, the result of this method
683 * is a closure equivalent to:
684 *
685 * (r1, .., rn, {p1: d1, ..., pk: dk}) {
686 * return this.invoke(name, [r1, .., rn], {#p1: p1, .., #pk: pk});
687 * }
688 *
689 * if m has required parameters r1, ..., rn, and named parameters p1, ..., pk
690 * with defaults d1, ..., dk.
691 *
692 * (r1, .., rn, [p1 = d1, …, pk = dk]) {
693 * return this.invoke(name, [r1, .., rn, p1, .., pk]);
694 * }
695 *
696 * if m has required parameters r1, ..., rn, and optional positional
697 * parameters p1, ..., pk with defaults d1, ..., dk.
629 */ 698 */
630 Map<Symbol, ClassMirror> get classes; 699 Function operator [](Symbol name);
631
632 /**
633 * An immutable map from names to mirrors for all function, getter,
634 * and setter declarations in this library.
635 */
636 Map<Symbol, MethodMirror> get functions;
637
638 /**
639 * An immutable map from names to mirrors for all getter
640 * declarations in this library.
641 */
642 Map<Symbol, MethodMirror> get getters;
643
644 /**
645 * An immutable map from names to mirrors for all setter
646 * declarations in this library.
647 */
648 Map<Symbol, MethodMirror> get setters;
649
650 /**
651 * An immutable map from names to mirrors for all variable
652 * declarations in this library.
653 */
654 Map<Symbol, VariableMirror> get variables;
655 700
656 /** 701 /**
657 * Returns [:true:] if this mirror is equal to [other]. 702 * Returns [:true:] if this mirror is equal to [other].
658 * Otherwise returns [:false:]. 703 * Otherwise returns [:false:].
659 * 704 *
660 * The equality holds if and only if 705 * The equality holds if and only if
661 * (1) [other] is a mirror of the same kind 706 * (1) [other] is a mirror of the same kind
662 * and 707 * and
663 * (2) The library being reflected by this mirror 708 * (2) The library being reflected by this mirror
664 * and the library being reflected by [other] 709 * and the library being reflected by [other]
665 * are 710 * are
666 * the same library in the same isolate. 711 * the same library in the same isolate.
667 */ 712 */
668 bool operator == (other); 713 bool operator ==(other);
669 } 714 }
670 715
671 /** 716 /**
672 * A [TypeMirror] reflects a Dart language class, typedef, 717 * A [TypeMirror] reflects a Dart language class, typedef,
673 * or type variable. 718 * or type variable.
674 */ 719 */
675 abstract class TypeMirror implements DeclarationMirror { 720 abstract class TypeMirror implements DeclarationMirror {
676 } 721 }
677 722
678 /** 723 /**
(...skipping 19 matching lines...) Expand all
698 * null. 743 * null.
699 */ 744 */
700 ClassMirror get superclass; 745 ClassMirror get superclass;
701 746
702 /** 747 /**
703 * A list of mirrors on the superinterfaces of the reflectee. 748 * A list of mirrors on the superinterfaces of the reflectee.
704 */ 749 */
705 List<ClassMirror> get superinterfaces; 750 List<ClassMirror> get superinterfaces;
706 751
707 /** 752 /**
708 * An immutable map from from names to mirrors for all members of 753 * An immutable map from from names to mirrors for all declared members of
709 * this type. 754 * this type.
710 * 755 *
711 * The members of a type are its methods, fields, getters, and 756 * The members of a type are its methods, fields, getters, and
712 * setters. Note that constructors and type variables are not 757 * setters. Note that constructors and type variables are not
713 * considered to be members of a type. 758 * considered to be members of a type.
714 * 759 *
715 * This does not include inherited members. 760 * This does not include inherited members.
716 */ 761 */
717 Map<Symbol, Mirror> get members; 762 Map<Symbol, DeclarationMirror> get declarations;
gbracha 2013/09/17 18:27:53 I am slightly confused. I thought the plan was to
718 763
gbracha 2013/09/26 19:50:35 In our latest discussion, we assume that all decla
gbracha 2013/10/03 22:11:25 We now decided not to include type variables, beca
719 /** 764 /**
720 * An immutable map from names to mirrors for all method, 765 * Returns closure for invoking the regular method named [name].
721 * declarations for this type. This does not include getters and 766 *
722 * setters. 767 * If [:declarations[name]:] is a regular static method, the result of this
768 * method is a closure equivalent to:
769 *
770 * (r1, .., rn, {p1: d1, ..., pk: dk}) {
771 * return this.invoke(name, [r1, .., rn], {#p1: p1, .., #pk: pk});
772 * }
773 *
774 * if m has required parameters r1, ..., rn, and named parameters p1, ..., pk
775 * with defaults d1, ..., dk.
776 *
777 * (r1, .., rn, [p1 = d1, …, pk = dk]) {
778 * return this.invoke(name, [r1, .., rn, p1, .., pk]);
779 * }
780 *
781 * if m has required parameters r1, ..., rn, and optional positional
782 * parameters p1, ..., pk with defaults d1, ..., dk.
723 */ 783 */
724 Map<Symbol, MethodMirror> get methods; 784 Function operator [](Symbol name);
gbracha 2013/09/17 18:27:53 nits in wording: Returns *a* closure ... if m h
725 785
gbracha 2013/09/26 19:50:35 Also, why is this restricted to static methods? Wh
rmacnak 2013/09/26 22:47:52 From a subscript operator on InstanceMirror? Hois
726 /** 786 /// Finds the instance member named [name] declared or inherited in the
rmacnak 2013/09/03 18:42:37 Does this include getters and setters? If so, how
ahe 2013/09/03 18:47:20 Yes.
rmacnak 2013/09/03 19:44:26 I was thinking something like this, but the overri
ahe 2013/09/03 19:52:36 Yes. We have tried very hard to ensure a single na
727 * An immutable map from names to mirrors for all getter 787 /// reflected class.
728 * declarations for this type. 788 DeclarationMirror instanceLookup(Symbol name);
ahe 2013/09/26 18:03:36 We also need a way to get a list or map of all ins
rmacnak 2013/09/26 22:47:52 And perhaps add DeclarationMirror.isSynthetic
729 */
730 Map<Symbol, MethodMirror> get getters;
731
732 /**
733 * An immutable map from names to mirrors for all setter
734 * declarations for this type.
735 */
736 Map<Symbol, MethodMirror> get setters;
737
738 /**
739 * An immutable map from names to mirrors for all variable
740 * declarations for this type.
741 */
742 Map<Symbol, VariableMirror> get variables;
743
744 /**
745 * An immutable map from names to mirrors for all constructor
746 * declarations for this type.
747 */
748 Map<Symbol, MethodMirror> get constructors;
749 789
750 /** 790 /**
751 * An immutable map from names to mirrors for all type variables for 791 * An immutable map from names to mirrors for all type variables for
Michael Lippautz (Google) 2013/09/03 17:24:50 comment out of sync
752 * this type. 792 * this type.
753 * If this type is a generic declaration or an invocation of 793 * If this type is a generic declaration or an invocation of
754 * a generic declaration, the returned map has the names of the formal 794 * a generic declaration, the returned map has the names of the formal
755 * type parameters of the original declaration as its keys, and 795 * type parameters of the original declaration as its keys, and
756 * each such key maps to a TypeVariableMirror on the corresponding 796 * each such key maps to a TypeVariableMirror on the corresponding
757 * type variable. Otherwise, the returned map is empty. 797 * type variable. Otherwise, the returned map is empty.
758 * 798 *
759 * This map preserves the order of declaration of the type variables. 799 * This map preserves the order of declaration of the type variables.
760 */ 800 */
761 Map<Symbol, TypeVariableMirror> get typeVariables; 801 List<TypeVariableMirror> get typeVariables;
Alan Knight 2013/09/03 20:08:31 Would Iterable be better than List?
ahe 2013/09/03 20:14:30 I think length and operator[] are important proper
Alan Knight 2013/09/03 20:30:56 Important for what in this context? Are we expecti
762 802
763 /** 803 /**
764 * An immutable map from names to mirrors for all type arguments for 804 * An immutable map from names to mirrors for all type arguments for
Michael Lippautz (Google) 2013/09/03 17:24:50 comment out of sync
765 * this type. The keys of the map are the names of the 805 * this type. The keys of the map are the names of the
766 * corresponding type variables. 806 * corresponding type variables.
767 * 807 *
768 * If the the reflectee is an invocation of a generic class, 808 * If the the reflectee is an invocation of a generic class,
769 * the type arguments are the bindings of its type parameters. 809 * the type arguments are the bindings of its type parameters.
770 * If the reflectee is the original declaration of a generic, 810 * If the reflectee is the original declaration of a generic,
771 * it has no type arguments and this method returns an empty map. 811 * it has no type arguments and this method returns an empty map.
772 * If the reflectee is a not generic, then 812 * If the reflectee is a not generic, then
773 * it has no type arguments and this method returns an empty map. 813 * it has no type arguments and this method returns an empty map.
774 * This map preserves the order of declaration of the type variables. 814 * This map preserves the order of declaration of the type variables.
775 */ 815 */
776 Map<Symbol, TypeMirror> get typeArguments; 816 List<TypeMirror> get typeArguments;
777 817
778 /** 818 /**
779 * Is this the original declaration of this type? 819 * Is this the original declaration of this type?
780 * 820 *
781 * For most classes, they are their own original declaration. For 821 * For most classes, they are their own original declaration. For
782 * generic classes, however, there is a distinction between the 822 * generic classes, however, there is a distinction between the
783 * original class declaration, which has unbound type variables, and 823 * original class declaration, which has unbound type variables, and
784 * the instantiations of generic classes, which have bound type 824 * the instantiations of generic classes, which have bound type
785 * variables. 825 * variables.
786 */ 826 */
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 * Then this method will execute the instance creation expression 895 * Then this method will execute the instance creation expression
856 * *new c.f(a1, ..., an, k1: v1, ..., km: vm)* 896 * *new c.f(a1, ..., an, k1: v1, ..., km: vm)*
857 * in a scope that has access to the private members 897 * in a scope that has access to the private members
858 * of *c*. 898 * of *c*.
859 * In either case: 899 * In either case:
860 * The method returns a future *k*. 900 * The method returns a future *k*.
861 * If the invocation returns a result *r*, *k* will be completed 901 * If the invocation returns a result *r*, *k* will be completed
862 * with the result of calling [reflect](*r*). 902 * with the result of calling [reflect](*r*).
863 * If the invocation throws an exception *e* (that it does not catch) 903 * If the invocation throws an exception *e* (that it does not catch)
864 * then *k* is completed with a [MirrorError] wrapping *e*. 904 * then *k* is completed with a [MirrorError] wrapping *e*.
865 */ 905 */
866 Future<InstanceMirror> newInstanceAsync(Symbol constructorName, 906 Future<InstanceMirror> newInstanceAsync(Symbol constructorName,
867 List positionalArguments, 907 List positionalArguments,
868 [Map<Symbol, dynamic> namedArguments]) ; 908 [Map<Symbol, dynamic> namedArguments]) ;
869 909
870 /** 910 /**
871 * Returns [:true:] if this mirror is equal to [other]. 911 * Returns [:true:] if this mirror is equal to [other].
872 * Otherwise returns [:false:]. 912 * Otherwise returns [:false:].
873 * 913 *
874 * The equality holds if and only if 914 * The equality holds if and only if
875 * (1) [other] is a mirror of the same kind 915 * (1) [other] is a mirror of the same kind
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 InstanceMirror get defaultValue; 1156 InstanceMirror get defaultValue;
1117 } 1157 }
1118 1158
1119 /** 1159 /**
1120 * A [SourceLocation] describes the span of an entity in Dart source code. 1160 * A [SourceLocation] describes the span of an entity in Dart source code.
1121 */ 1161 */
1122 abstract class SourceLocation { 1162 abstract class SourceLocation {
1123 } 1163 }
1124 1164
1125 /** 1165 /**
1126 * When an error occurs during the mirrored execution of code, a
1127 * [MirroredError] is thrown.
1128 *
1129 * In general, there are three main classes of failure that can happen
1130 * during mirrored execution of code in some isolate:
1131 *
1132 * - An exception is thrown but not caught. This is caught by the
1133 * mirrors framework and a [MirroredUncaughtExceptionError] is
1134 * created and thrown.
1135 *
1136 * - A compile-time error occurs, such as a syntax error. This is
1137 * suppressed by the mirrors framework and a
1138 * [MirroredCompilationError] is created and thrown.
1139 *
1140 * - A truly fatal error occurs, causing the isolate to be exited. If
1141 * the reflector and reflectee share the same isolate, then they
1142 * will both suffer. If the reflector and reflectee are in distinct
1143 * isolates, then we hope to provide some information about the
1144 * isolate death, but this has yet to be implemented.
1145 *
1146 * TODO(turnidge): Specify the behavior for remote fatal errors.
1147 */
1148 abstract class MirroredError implements Exception {
1149 }
1150
1151 /**
1152 * When an uncaught exception occurs during the mirrored execution
1153 * of code, a [MirroredUncaughtExceptionError] is thrown.
1154 *
1155 * This exception contains a mirror on the original exception object.
1156 * It also contains an object which can be used to recover the
1157 * stacktrace.
1158 */
1159 class MirroredUncaughtExceptionError extends MirroredError {
rmacnak 2013/09/03 18:42:37 We will need this for cross-isolate reflection, bu
1160 MirroredUncaughtExceptionError(this.exception_mirror,
1161 this.exception_string,
1162 this.stacktrace) {}
1163
1164 /** A mirror on the exception object. */
1165 final InstanceMirror exception_mirror;
1166
1167 /** The result of toString() for the exception object. */
1168 final String exception_string;
1169
1170 /** A stacktrace object for the uncaught exception. */
1171 final Object stacktrace;
1172
1173 String toString() {
1174 return
1175 "Uncaught exception during mirrored execution: <${exception_string}>";
1176 }
1177 }
1178
1179 /**
1180 * When a compile-time error occurs during the mirrored execution
1181 * of code, a [MirroredCompilationError] is thrown.
1182 *
1183 * This exception includes the compile-time error message that would
1184 * have been displayed to the user, if the function had not been
1185 * invoked via mirror.
1186 */
1187 class MirroredCompilationError extends MirroredError {
Michael Lippautz (Google) 2013/09/03 17:24:50 Note: I suspect that removing this classes will br
rmacnak 2013/09/03 18:42:37 We should keep this. Catching compilation errors i
ahe 2013/09/03 18:47:20 Yes, I think I would start by moving these classes
1188 MirroredCompilationError(this.message) {}
1189
1190 final String message;
1191
1192 String toString() {
1193 return "Compile-time error during mirrored execution: <$message>";
1194 }
1195 }
1196
1197 /**
1198 * A [MirrorException] is used to indicate errors within the mirrors
1199 * framework.
1200 */
1201 class MirrorException implements Exception {
1202 const MirrorException(String this._message);
1203 String toString() => "MirrorException: '$_message'";
1204 final String _message;
1205 }
1206
1207 /**
1208 * Class used for encoding comments as metadata annotations. 1166 * Class used for encoding comments as metadata annotations.
1209 */ 1167 */
1210 class Comment { 1168 class Comment {
1211 /** 1169 /**
1212 * The comment text as written in the source text. 1170 * The comment text as written in the source text.
1213 */ 1171 */
1214 final String text; 1172 final String text;
1215 1173
1216 /** 1174 /**
1217 * The comment text without the start, end, and padding text. 1175 * The comment text without the start, end, and padding text.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 * 1281 *
1324 * When used as metadata on an import of "dart:mirrors", this metadata does 1282 * When used as metadata on an import of "dart:mirrors", this metadata does
1325 * not apply to the library in which the annotation is used, but instead 1283 * not apply to the library in which the annotation is used, but instead
1326 * applies to the other libraries (all libraries if "*" is used). 1284 * applies to the other libraries (all libraries if "*" is used).
1327 */ 1285 */
1328 final override; 1286 final override;
1329 1287
1330 const MirrorsUsed( 1288 const MirrorsUsed(
1331 {this.symbols, this.targets, this.metaTargets, this.override}); 1289 {this.symbols, this.targets, this.metaTargets, this.override});
1332 } 1290 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698