OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 // For the purposes of the mirrors library, we adopt a naming | |
6 // convention with respect to getters and setters. Specifically, for | |
7 // some variable or field... | |
8 // | |
9 // var myField; | |
10 // | |
11 // ...the getter is named 'myField' and the setter is named | |
12 // 'myField='. This allows us to assign unique names to getters and | |
13 // setters for the purposes of member lookup. | |
14 | |
15 /** | |
16 * Basic reflection in Dart, | |
17 * with support for introspection and dynamic evaluation. | |
18 * | |
19 * *Introspection* is that subset of reflection by which a running | |
20 * program can examine its own structure. For example, a function | |
21 * that prints out the names of all the members of an arbitrary object. | |
22 * | |
23 * *Dynamic evaluation* refers the ability to evaluate code that | |
24 * has not been literally specified at compile time, such as calling a method | |
25 * whose name is provided as an argument (because it is looked up | |
26 * in a database, or provided interactively by the user). | |
27 * | |
28 * ## How to interpret this library's documentation | |
29 * | |
30 * As a rule, the names of Dart declarations are represented using | |
31 * instances of class [Symbol]. Whenever the doc speaks of an object *s* | |
32 * of class [Symbol] denoting a name, it means the string that | |
33 * was used to construct *s*. | |
34 * | |
35 * The documentation frequently abuses notation with | |
36 * Dart pseudo-code such as [:o.x(a):], where | |
37 * o and a are defined to be objects; what is actually meant in these | |
38 * cases is [:o'.x(a'):] where *o'* and *a'* are Dart variables | |
39 * bound to *o* and *a* respectively. Furthermore, *o'* and *a'* | |
40 * are assumed to be fresh variables (meaning that they are | |
41 * distinct from any other variables in the program). | |
42 * | |
43 * Sometimes the documentation refers to *serializable* objects. | |
44 * An object is serializable across isolates if and only if it is an instance of | |
45 * num, bool, String, a list of objects that are serializable | |
46 * across isolates, or a map with keys and values that are all serializable acro ss | |
Jennifer Messerly
2015/06/15 16:42:01
long line, I'm guessing was from original code tho
vsm
2015/06/15 20:59:46
Yeah, this is the upstream - same version as the r
| |
47 * isolates. | |
48 * | |
49 * ## Status: Unstable | |
50 * | |
51 * The dart:mirrors library is unstable and its API might change slightly as a | |
52 * result of user feedback. This library is platform dependent and therefore it | |
53 * has implementations for both dart2js and the Dart VM. Both are under | |
54 * development and may not support all operations yet. | |
55 */ | |
56 library dart.mirrors; | |
57 | |
58 /** | |
59 * A [MirrorSystem] is the main interface used to reflect on a set of | |
60 * associated libraries. | |
61 * | |
62 * At runtime each running isolate has a distinct [MirrorSystem]. | |
63 * | |
64 * It is also possible to have a [MirrorSystem] which represents a set | |
65 * of libraries which are not running -- perhaps at compile-time. In | |
66 * this case, all available reflective functionality would be | |
67 * supported, but runtime functionality (such as invoking a function | |
68 * or inspecting the contents of a variable) would fail dynamically. | |
69 */ | |
70 abstract class MirrorSystem { | |
71 /** | |
72 * Returns an immutable map from URIs to mirrors for all | |
73 * libraries known to this mirror system. | |
74 */ | |
75 Map<Uri, LibraryMirror> get libraries; | |
76 | |
77 /** | |
78 * Returns the unique library named [libraryName] if it exists. | |
79 * | |
80 * If no unique library exists, an error is thrown. | |
81 */ | |
82 LibraryMirror findLibrary(Symbol libraryName) { | |
83 return libraries.values.singleWhere( | |
84 (library) => library.simpleName == libraryName); | |
85 } | |
86 | |
87 /** | |
88 * A mirror on the isolate associated with this [MirrorSystem]. | |
89 * This may be null if this mirror system is not running. | |
90 */ | |
91 IsolateMirror get isolate; | |
92 | |
93 /** | |
94 * A mirror on the [:dynamic:] type. | |
95 */ | |
96 TypeMirror get dynamicType; | |
97 | |
98 /** | |
99 * A mirror on the [:void:] type. | |
100 */ | |
101 TypeMirror get voidType; | |
102 | |
103 /** | |
104 * Returns the name of [symbol]. | |
105 * | |
106 * The following text is non-normative: | |
107 * | |
108 * Using this method may result in larger output. If possible, use | |
109 * [MirrorsUsed] to specify which symbols must be retained in clear text. | |
110 */ | |
111 external static String getName(Symbol symbol); | |
112 | |
113 /** | |
114 * Returns a symbol for [name]. If [library] is not a [LibraryMirror] or if | |
115 * [name] is a private identifier and [library] is [:null:], throws an | |
116 * [ArgumentError]. If [name] is a private identifier, the symbol returned is | |
117 * with respect to [library]. | |
118 * | |
119 * The following text is non-normative: | |
120 * | |
121 * Using this method may result in larger output. If possible, use | |
122 * the const constructor of Symbol or symbol literals. | |
123 */ | |
124 external static Symbol getSymbol(String name, [LibraryMirror library]); | |
125 } | |
126 | |
127 /** | |
128 * Returns a [MirrorSystem] for the current isolate. | |
129 */ | |
130 external MirrorSystem currentMirrorSystem(); | |
131 | |
132 /** | |
133 * Reflects an instance. | |
134 * Returns an [InstanceMirror] reflecting [reflectee]. | |
135 * If [reflectee] is a function or an instance of a class | |
136 * that has a [:call:] method, the returned instance mirror | |
137 * will be a [ClosureMirror]. | |
138 * | |
139 * Note that since one cannot obtain an object from | |
140 * another isolate, this function can only be used to | |
141 * obtain mirrors on objects of the current isolate. | |
142 */ | |
143 external InstanceMirror reflect(Object reflectee); | |
144 | |
145 /** | |
146 * Reflects a class declaration. | |
147 * Let *C* be the original class declaration of the class | |
148 * represented by [key]. | |
149 * This function returns a [ClassMirror] reflecting *C*. | |
150 * | |
151 * If [key] is not an instance of [Type] then this function | |
152 * throws an [ArgumentError]. If [key] is the Type for dynamic | |
153 * or a function typedef, throws an [ArgumentError]. | |
154 * | |
155 * Note that since one cannot obtain a [Type] object from | |
156 * another isolate, this function can only be used to | |
157 * obtain class mirrors on classes of the current isolate. | |
158 */ | |
159 external ClassMirror reflectClass(Type key); | |
160 | |
161 /** | |
162 * This function returns a [TypeMirror] reflecting the type | |
163 * represented by [key]. | |
164 * | |
165 * If [key] is not an instance of [Type] then this function | |
166 * throws an [ArgumentError]. | |
167 * | |
168 * Note that since one cannot obtain a [Type] object from | |
169 * another isolate, this function can only be used to | |
170 * obtain type mirrors on types of the current isolate. | |
171 */ | |
172 external TypeMirror reflectType(Type key); | |
173 | |
174 /** | |
175 * A [Mirror] reflects some Dart language entity. | |
176 * | |
177 * Every [Mirror] originates from some [MirrorSystem]. | |
178 */ | |
179 abstract class Mirror {} | |
180 | |
181 /** | |
182 * An [IsolateMirror] reflects an isolate. | |
183 */ | |
184 abstract class IsolateMirror implements Mirror { | |
185 /** | |
186 * Returns a unique name used to refer to an isolate | |
187 * in debugging messages. | |
188 */ | |
189 String get debugName; | |
190 | |
191 /** | |
192 * Returns [:true:] if and only if this mirror reflects | |
193 * the currently running isolate. Otherwise returns | |
194 * [:false:]. | |
195 */ | |
196 bool get isCurrent; | |
197 | |
198 /** | |
199 * Returns a [LibraryMirror] on the root library for this | |
200 * isolate. | |
201 */ | |
202 LibraryMirror get rootLibrary; | |
203 | |
204 /** | |
205 * Returns [:true:] if this mirror is equal to [other]. | |
206 * Otherwise returns [:false:]. | |
207 * The equality holds if and only if | |
208 * (1) [other] is a mirror of the same kind | |
209 * and | |
210 * (2) the isolate being reflected by this mirror is the same | |
211 * isolate being reflected by [other]. | |
212 */ | |
213 bool operator == (other); | |
214 } | |
215 | |
216 /** | |
217 * A [DeclarationMirror] reflects some entity declared in a Dart program. | |
218 */ | |
219 abstract class DeclarationMirror implements Mirror { | |
220 /** | |
221 * The simple name for this Dart language entity. | |
222 * | |
223 * The simple name is in most cases the the identifier name of the | |
224 * entity, such as 'method' for a method [:void method() {...}:] or | |
225 * 'mylibrary' for a [:library 'mylibrary';:] declaration. | |
226 */ | |
227 Symbol get simpleName; | |
228 | |
229 /** | |
230 * The fully-qualified name for this Dart language entity. | |
231 * | |
232 * This name is qualified by the name of the owner. For instance, | |
233 * the qualified name of a method 'method' in class 'Class' in | |
234 * library 'library' is 'library.Class.method'. | |
235 * | |
236 * Returns a [Symbol] constructed from a string representing the | |
237 * fully qualified name of the reflectee. | |
238 * Let *o* be the [owner] of this mirror, let *r* be the reflectee of | |
239 * this mirror, let *p* be the fully qualified | |
240 * name of the reflectee of *o*, and let *s* be the simple name of *r* | |
241 * computed by [simpleName]. | |
242 * The fully qualified name of *r* is the | |
243 * concatenation of *p*, '.', and *s*. | |
244 * | |
245 * Because an isolate can contain more than one library with the same name (at | |
246 * different URIs), a fully-qualified name does not uniquely identify any | |
247 * language entity. | |
248 */ | |
249 Symbol get qualifiedName; | |
250 | |
251 /** | |
252 * A mirror on the owner of this Dart language entity. This is the declaration | |
253 * immediately surrounding the reflectee. | |
254 * | |
255 * For a library, the owner is [:null:]. | |
256 * For a class declaration, typedef or top level function | |
257 * or variable, the owner is the enclosing library. | |
258 * For a mixin application *S with M*, the owner is the owner | |
259 * of *M*. | |
260 * For a constructor, the owner is the immediately enclosing class. | |
261 * For a method, instance variable or | |
262 * a static variable, the owner is the immediately enclosing class, | |
263 * unless the class is a mixin application *S with M*, in which case | |
264 * the owner is *M*. Note that *M* may be an invocation of a generic. | |
265 * For a parameter, local variable or local function the owner is the | |
266 * immediately enclosing function. | |
267 */ | |
268 DeclarationMirror get owner; | |
269 | |
270 /** | |
271 * Returns [:true:] if this declaration is considered private | |
272 * according to the Dart language specification. | |
273 * Always returns [: false :] if this declaration | |
274 * is a library. | |
275 * Otherwise return [:false:]. | |
276 * | |
277 */ | |
278 bool get isPrivate; | |
279 | |
280 /** | |
281 * Is this declaration top-level? | |
282 * | |
283 * This is defined to be equivalent to: | |
284 * [:mirror.owner != null && mirror.owner is LibraryMirror:] | |
285 */ | |
286 bool get isTopLevel; | |
287 | |
288 /** | |
289 * The source location of this Dart language entity. | |
290 * | |
291 * This operation is optional and may return [:null:]. | |
292 */ | |
293 SourceLocation get location; | |
294 | |
295 /** | |
296 * A list of the metadata associated with this declaration. | |
297 * | |
298 * Let *D* be the declaration this mirror reflects. | |
299 * If *D* is decorated with annotations *A1, ..., An* | |
300 * where *n > 0*, then for each annotation *Ai* associated | |
301 * with *D, 1 <= i <= n*, let *ci* be the constant object | |
302 * specified by *Ai*. Then this method returns a list whose | |
303 * members are instance mirrors on *c1, ..., cn*. | |
304 * If no annotations are associated with *D*, then | |
305 * an empty list is returned. | |
306 * | |
307 * If evaluating any of *c1, ..., cn* would cause a | |
308 * compilation error | |
309 * the effect is the same as if a non-reflective compilation error | |
310 * had been encountered. | |
311 */ | |
312 List<InstanceMirror> get metadata; | |
313 } | |
314 | |
315 /** | |
316 * An [ObjectMirror] is a common superinterface of [InstanceMirror], | |
317 * [ClassMirror], and [LibraryMirror] that represents their shared | |
318 * functionality. | |
319 * | |
320 * For the purposes of the mirrors library, these types are all | |
321 * object-like, in that they support method invocation and field | |
322 * access. Real Dart objects are represented by the [InstanceMirror] | |
323 * type. | |
324 * | |
325 * See [InstanceMirror], [ClassMirror], and [LibraryMirror]. | |
326 */ | |
327 abstract class ObjectMirror implements Mirror { | |
328 | |
329 /** | |
330 * Invokes the named function and returns a mirror on the result. | |
331 * | |
332 * Let *o* be the object reflected by this mirror, let | |
333 * *f* be the simple name of the member denoted by [memberName], | |
334 * let *a1, ..., an* be the elements of [positionalArguments] | |
335 * let *k1, ..., km* be the identifiers denoted by the elements of | |
336 * [namedArguments.keys] | |
337 * and let *v1, ..., vm* be the elements of [namedArguments.values]. | |
338 * Then this method will perform the method invocation | |
339 * *o.f(a1, ..., an, k1: v1, ..., km: vm)* | |
340 * in a scope that has access to the private members | |
341 * of *o* (if *o* is a class or library) or the private members of the | |
342 * class of *o* (otherwise). | |
343 * If the invocation returns a result *r*, this method returns | |
344 * the result of calling [reflect](*r*). | |
345 * If the invocation causes a compilation error | |
346 * the effect is the same as if a non-reflective compilation error | |
347 * had been encountered. | |
348 * If the invocation throws an exception *e* (that it does not catch) | |
349 * this method throws *e*. | |
350 */ | |
351 /* | |
352 * TODO(turnidge): Handle ambiguous names. | |
353 * TODO(turnidge): Handle optional & named arguments. | |
354 */ | |
355 InstanceMirror invoke(Symbol memberName, | |
356 List positionalArguments, | |
357 [Map<Symbol,dynamic> namedArguments]); | |
358 | |
359 /** | |
360 * Invokes a getter and returns a mirror on the result. The getter | |
361 * can be the implicit getter for a field or a user-defined getter | |
362 * method. | |
363 * | |
364 * Let *o* be the object reflected by this mirror, let | |
365 * *f* be the simple name of the getter denoted by [fieldName], | |
366 * Then this method will perform the getter invocation | |
367 * *o.f* | |
368 * in a scope that has access to the private members | |
369 * of *o* (if *o* is a class or library) or the private members of the | |
370 * class of *o* (otherwise). | |
371 * | |
372 * If this mirror is an [InstanceMirror], and [fieldName] denotes an instance | |
373 * method on its reflectee, the result of the invocation is an instance | |
374 * mirror on a closure corresponding to that method. | |
375 * | |
376 * If this mirror is a [LibraryMirror], and [fieldName] denotes a top-level | |
377 * method in the corresponding library, the result of the invocation is an | |
378 * instance mirror on a closure corresponding to that method. | |
379 * | |
380 * If this mirror is a [ClassMirror], and [fieldName] denotes a static method | |
381 * in the corresponding class, the result of the invocation is an instance | |
382 * mirror on a closure corresponding to that method. | |
383 * | |
384 * If the invocation returns a result *r*, this method returns | |
385 * the result of calling [reflect](*r*). | |
386 * If the invocation causes a compilation error | |
387 * the effect is the same as if a non-reflective compilation error | |
388 * had been encountered. | |
389 * If the invocation throws an exception *e* (that it does not catch) | |
390 * this method throws *e*. | |
391 */ | |
392 // TODO(ahe): Remove stuff about scope and private members. [fieldName] is a | |
393 // capability giving access to private members. | |
394 InstanceMirror getField(Symbol fieldName); | |
395 | |
396 /** | |
397 * Invokes a setter and returns a mirror on the result. The setter | |
398 * may be either the implicit setter for a non-final field or a | |
399 * user-defined setter method. | |
400 * | |
401 * Let *o* be the object reflected by this mirror, let | |
402 * *f* be the simple name of the getter denoted by [fieldName], | |
403 * and let *a* be the object bound to [value]. | |
404 * Then this method will perform the setter invocation | |
405 * *o.f = a* | |
406 * in a scope that has access to the private members | |
407 * of *o* (if *o* is a class or library) or the private members of the | |
408 * class of *o* (otherwise). | |
409 * If the invocation returns a result *r*, this method returns | |
410 * the result of calling [reflect]([value]). | |
411 * If the invocation causes a compilation error | |
412 * the effect is the same as if a non-reflective compilation error | |
413 * had been encountered. | |
414 * If the invocation throws an exception *e* (that it does not catch) | |
415 * this method throws *e*. | |
416 */ | |
417 /* TODO(turnidge): Handle ambiguous names.*/ | |
418 InstanceMirror setField(Symbol fieldName, Object value); | |
419 } | |
420 | |
421 /** | |
422 * An [InstanceMirror] reflects an instance of a Dart language object. | |
423 */ | |
424 abstract class InstanceMirror implements ObjectMirror { | |
425 /** | |
426 * A mirror on the type of the reflectee. | |
427 * | |
428 * Returns a mirror on the actual class of the reflectee. | |
429 * The class of the reflectee may differ from | |
430 * the object returned by invoking [runtimeType] on | |
431 * the reflectee. | |
432 */ | |
433 ClassMirror get type; | |
434 | |
435 /** | |
436 * Does [reflectee] contain the instance reflected by this mirror? | |
437 * This will always be true in the local case (reflecting instances | |
438 * in the same isolate), but only true in the remote case if this | |
439 * mirror reflects a simple value. | |
440 * | |
441 * A value is simple if one of the following holds: | |
442 * - the value is [:null:] | |
443 * - the value is of type [num] | |
444 * - the value is of type [bool] | |
445 * - the value is of type [String] | |
446 */ | |
447 bool get hasReflectee; | |
448 | |
449 /** | |
450 * If the [InstanceMirror] reflects an instance it is meaningful to | |
451 * have a local reference to, we provide access to the actual | |
452 * instance here. | |
453 * | |
454 * If you access [reflectee] when [hasReflectee] is false, an | |
455 * exception is thrown. | |
456 */ | |
457 get reflectee; | |
458 | |
459 /** | |
460 * Returns true if this mirror is equal to [other]. | |
461 * The equality holds if and only if | |
462 * (1) [other] is a mirror of the same kind | |
463 * and | |
464 * (2) either | |
465 * (a) [hasReflectee] is true and so is | |
466 * [:identical(reflectee, other.reflectee):] | |
467 * or | |
468 * (b) the remote objects reflected by this mirror and | |
469 * by [other] are identical. | |
470 */ | |
471 bool operator == (other); | |
472 | |
473 /** | |
474 * Perform [invocation] on [reflectee]. | |
475 * Equivalent to | |
476 * | |
477 * this.invoke(invocation.memberName, | |
478 * invocation.positionalArguments, | |
479 * invocation.namedArguments); | |
480 */ | |
481 delegate(Invocation invocation); | |
482 } | |
483 | |
484 /** | |
485 * A [ClosureMirror] reflects a closure. | |
486 * | |
487 * A [ClosureMirror] provides access to its captured variables and | |
488 * provides the ability to execute its reflectee. | |
489 */ | |
490 abstract class ClosureMirror implements InstanceMirror { | |
491 /** | |
492 * A mirror on the function associated with this closure. | |
493 * | |
494 * The function associated with an implicit closure of a function is that | |
495 * function. | |
496 * | |
497 * The function associated with an instance of a class that has a [:call:] | |
498 * method is that [:call:] method. | |
499 * | |
500 * A Dart implementation might choose to create a class for each closure | |
501 * expression, in which case [:function:] would be the same as | |
502 * [:type.declarations[#call]:]. But the Dart language model does not require | |
503 * this. A more typical implementation involves a single closure class for | |
504 * each type signature, where the call method dispatches to a function held | |
505 * in the closure rather the call method | |
506 * directly implementing the closure body. So one cannot rely on closures from | |
507 * distinct closure expressions having distinct classes ([:type:]), but one | |
508 * can rely on them having distinct functions ([:function:]). | |
509 */ | |
510 MethodMirror get function; | |
511 | |
512 /** | |
513 * Executes the closure and returns a mirror on the result. | |
514 * Let *f* be the closure reflected by this mirror, | |
515 * let *a1, ..., an* be the elements of [positionalArguments] | |
516 * let *k1, ..., km* be the identifiers denoted by the elements of | |
517 * [namedArguments.keys] | |
518 * and let *v1, ..., vm* be the elements of [namedArguments.values]. | |
519 * Then this method will perform the method invocation | |
520 * *f(a1, ..., an, k1: v1, ..., km: vm)* | |
521 * If the invocation returns a result *r*, this method returns | |
522 * the result of calling [reflect](*r*). | |
523 * If the invocation causes a compilation error | |
524 * the effect is the same as if a non-reflective compilation error | |
525 * had been encountered. | |
526 * If the invocation throws an exception *e* (that it does not catch) | |
527 * this method throws *e*. | |
528 */ | |
529 InstanceMirror apply(List positionalArguments, | |
530 [Map<Symbol, dynamic> namedArguments]); | |
531 } | |
532 | |
533 /** | |
534 * A [LibraryMirror] reflects a Dart language library, providing | |
535 * access to the variables, functions, and classes of the | |
536 * library. | |
537 */ | |
538 abstract class LibraryMirror implements DeclarationMirror, ObjectMirror { | |
539 /** | |
540 * The absolute uri of the library. | |
541 */ | |
542 Uri get uri; | |
543 | |
544 /** | |
545 * Returns an immutable map of the declarations actually given in the library. | |
546 * | |
547 * This map includes all regular methods, getters, setters, fields, classes | |
548 * and typedefs actually declared in the library. The map is keyed by the | |
549 * simple names of the declarations. | |
550 */ | |
551 Map<Symbol, DeclarationMirror> get declarations; | |
552 | |
553 /** | |
554 * Returns [:true:] if this mirror is equal to [other]. | |
555 * Otherwise returns [:false:]. | |
556 * | |
557 * The equality holds if and only if | |
558 * (1) [other] is a mirror of the same kind | |
559 * and | |
560 * (2) The library being reflected by this mirror | |
561 * and the library being reflected by [other] | |
562 * are | |
563 * the same library in the same isolate. | |
564 */ | |
565 bool operator ==(other); | |
566 | |
567 /** | |
568 * Returns a list of the imports and exports in this library; | |
569 */ | |
570 List<LibraryDependencyMirror> get libraryDependencies; | |
571 } | |
572 | |
573 /// A mirror on an import or export declaration. | |
574 abstract class LibraryDependencyMirror implements Mirror { | |
575 /// Is `true` if this dependency is an import. | |
576 bool get isImport; | |
577 | |
578 /// Is `true` if this dependency is an export. | |
579 bool get isExport; | |
580 | |
581 /// Returns the library mirror of the library that imports or exports the | |
582 /// [targetLibrary]. | |
583 LibraryMirror get sourceLibrary; | |
584 | |
585 /// Returns the library mirror of the library that is imported or exported. | |
586 LibraryMirror get targetLibrary; | |
587 | |
588 /// Returns the prefix if this is a prefixed import and `null` otherwise. | |
589 Symbol get prefix; | |
590 | |
591 /// Returns the list of show/hide combinators on the import/export | |
592 /// declaration. | |
593 List<CombinatorMirror> get combinators; | |
594 | |
595 /// Returns the source location for this import/export declaration. | |
596 SourceLocation get location; | |
597 | |
598 List<InstanceMirror> get metadata; | |
599 } | |
600 | |
601 /// A mirror on a show/hide combinator declared on a library dependency. | |
602 abstract class CombinatorMirror implements Mirror { | |
603 /// The list of identifiers on the combinator. | |
604 List<Symbol> get identifiers; | |
605 | |
606 /// Is `true` if this is a 'show' combinator. | |
607 bool get isShow; | |
608 | |
609 /// Is `true` if this is a 'hide' combinator. | |
610 bool get isHide; | |
611 } | |
612 | |
613 /** | |
614 * A [TypeMirror] reflects a Dart language class, typedef, | |
615 * function type or type variable. | |
616 */ | |
617 abstract class TypeMirror implements DeclarationMirror { | |
618 /** | |
619 * Returns true if this mirror reflects dynamic, a non-generic class or | |
620 * typedef, or an instantiated generic class or typedef in the current | |
621 * isolate. Otherwise, returns false. | |
622 */ | |
623 bool get hasReflectedType; | |
624 | |
625 /** | |
626 * If [:hasReflectedType:] returns true, returns the corresponding [Type]. | |
627 * Otherwise, an [UnsupportedError] is thrown. | |
628 */ | |
629 Type get reflectedType; | |
630 | |
631 /** | |
632 * An immutable list with mirrors for all type variables for this type. | |
633 * | |
634 * If this type is a generic declaration or an invocation of a generic | |
635 * declaration, the returned list contains mirrors on the type variables | |
636 * declared in the original declaration. | |
637 * Otherwise, the returned list is empty. | |
638 * | |
639 * This list preserves the order of declaration of the type variables. | |
640 */ | |
641 List<TypeVariableMirror> get typeVariables; | |
642 | |
643 /** | |
644 * An immutable list with mirrors for all type arguments for | |
645 * this type. | |
646 * | |
647 * If the reflectee is an invocation of a generic class, | |
648 * the type arguments are the bindings of its type parameters. | |
649 * If the reflectee is the original declaration of a generic, | |
650 * it has no type arguments and this method returns an empty list. | |
651 * If the reflectee is not generic, then | |
652 * it has no type arguments and this method returns an empty list. | |
653 * | |
654 * This list preserves the order of declaration of the type variables. | |
655 */ | |
656 List<TypeMirror> get typeArguments; | |
657 | |
658 /** | |
659 * Is this the original declaration of this type? | |
660 * | |
661 * For most classes, they are their own original declaration. For | |
662 * generic classes, however, there is a distinction between the | |
663 * original class declaration, which has unbound type variables, and | |
664 * the instantiations of generic classes, which have bound type | |
665 * variables. | |
666 */ | |
667 bool get isOriginalDeclaration; | |
668 | |
669 /** | |
670 * A mirror on the original declaration of this type. | |
671 * | |
672 * For most classes, they are their own original declaration. For | |
673 * generic classes, however, there is a distinction between the | |
674 * original class declaration, which has unbound type variables, and | |
675 * the instantiations of generic classes, which have bound type | |
676 * variables. | |
677 */ | |
678 TypeMirror get originalDeclaration; | |
679 | |
680 | |
681 /** | |
682 * Checks the subtype relationship, denoted by [:<::] in the language | |
683 * specification. This is the type relationship used in [:is:] test checks. | |
684 */ | |
685 bool isSubtypeOf(TypeMirror other); | |
686 | |
687 /** | |
688 * Checks the assignability relationship, denoted by [:<=>:] in the language | |
689 * specification. This is the type relationship tested on assignment in | |
690 * checked mode. | |
691 */ | |
692 bool isAssignableTo(TypeMirror other); | |
693 } | |
694 | |
695 /** | |
696 * A [ClassMirror] reflects a Dart language class. | |
697 */ | |
698 abstract class ClassMirror implements TypeMirror, ObjectMirror { | |
699 /** | |
700 * A mirror on the superclass on the reflectee. | |
701 * | |
702 * If this type is [:Object:], the superclass will be null. | |
703 */ | |
704 ClassMirror get superclass; | |
705 | |
706 /** | |
707 * A list of mirrors on the superinterfaces of the reflectee. | |
708 */ | |
709 List<ClassMirror> get superinterfaces; | |
710 | |
711 /** | |
712 * Is the reflectee abstract? | |
713 */ | |
714 bool get isAbstract; | |
715 | |
716 /** | |
717 * Returns an immutable map of the declarations actually given in the class | |
718 * declaration. | |
719 * | |
720 * This map includes all regular methods, getters, setters, fields, | |
721 * constructors and type variables actually declared in the class. Both | |
722 * static and instance members are included, but no inherited members are | |
723 * included. The map is keyed by the simple names of the declarations. | |
724 * | |
725 * This does not include inherited members. | |
726 */ | |
727 Map<Symbol, DeclarationMirror> get declarations; | |
728 | |
729 /** | |
730 * Returns a map of the methods, getters and setters of an instance of the | |
731 * class. | |
732 * | |
733 * The intent is to capture those members that constitute the API of an | |
734 * instance. Hence fields are not included, but the getters and setters | |
735 * implicitly introduced by fields are included. The map includes methods, | |
736 * getters and setters that are inherited as well as those introduced by the | |
737 * class itself. | |
738 * | |
739 * The map is keyed by the simple names of the members. | |
740 */ | |
741 Map<Symbol, MethodMirror> get instanceMembers; | |
742 | |
743 /** | |
744 * Returns a map of the static methods, getters and setters of the class. | |
745 * | |
746 * The intent is to capture those members that constitute the API of a class. | |
747 * Hence fields are not included, but the getters and setters implicitly | |
748 * introduced by fields are included. | |
749 * | |
750 * The map is keyed by the simple names of the members. | |
751 */ | |
752 Map<Symbol, MethodMirror> get staticMembers; | |
753 | |
754 | |
755 /** | |
756 * The mixin of this class. | |
757 * If this class is the result of a mixin application of the | |
758 * form S with M, returns a class mirror on M. | |
759 * Otherwise returns a class mirror on [reflectee]. | |
760 */ | |
761 ClassMirror get mixin; | |
762 | |
763 // TODO(ahe): What about: | |
764 // /// Finds the instance member named [name] declared or inherited in the | |
765 // /// reflected class. | |
766 // DeclarationMirror instanceLookup(Symbol name); | |
767 | |
768 /** | |
769 * Invokes the named constructor and returns a mirror on the result. | |
770 * | |
771 * Let *c* be the class reflected by this mirror | |
772 * let *a1, ..., an* be the elements of [positionalArguments] | |
773 * let *k1, ..., km* be the identifiers denoted by the elements of | |
774 * [namedArguments.keys] | |
775 * and let *v1, ..., vm* be the elements of [namedArguments.values]. | |
776 * If [constructorName] was created from the empty string | |
777 * Then this method will execute the instance creation expression | |
778 * *new c(a1, ..., an, k1: v1, ..., km: vm)* | |
779 * in a scope that has access to the private members | |
780 * of *c*. Otherwise, let | |
781 * *f* be the simple name of the constructor denoted by [constructorName] | |
782 * Then this method will execute the instance creation expression | |
783 * *new c.f(a1, ..., an, k1: v1, ..., km: vm)* | |
784 * in a scope that has access to the private members | |
785 * of *c*. | |
786 * In either case: | |
787 * If the expression evaluates to a result *r*, this method returns | |
788 * the result of calling [reflect](*r*). | |
789 * If evaluating the expression causes a compilation error | |
790 * the effect is the same as if a non-reflective compilation error | |
791 * had been encountered. | |
792 * If evaluating the expression throws an exception *e* | |
793 * (that it does not catch) | |
794 * this method throws *e*. | |
795 */ | |
796 InstanceMirror newInstance(Symbol constructorName, | |
797 List positionalArguments, | |
798 [Map<Symbol,dynamic> namedArguments]); | |
799 | |
800 /** | |
801 * Returns [:true:] if this mirror is equal to [other]. | |
802 * Otherwise returns [:false:]. | |
803 * | |
804 * The equality holds if and only if | |
805 * (1) [other] is a mirror of the same kind | |
806 * and | |
807 * (2) This mirror and [other] reflect the same class. | |
808 * | |
809 * Note that if the reflected class is an invocation of | |
810 * a generic class,(2) implies that the reflected class | |
811 * and [other] have equal type arguments. | |
812 */ | |
813 bool operator == (other); | |
814 | |
815 /** | |
816 * Returns whether the class denoted by the receiver is a subclass of the | |
817 * class denoted by the argument. | |
818 * | |
819 * Note that the subclass relationship is reflexive. | |
820 */ | |
821 bool isSubclassOf(ClassMirror other); | |
822 } | |
823 | |
824 /** | |
825 * A [FunctionTypeMirror] represents the type of a function in the | |
826 * Dart language. | |
827 */ | |
828 abstract class FunctionTypeMirror implements ClassMirror { | |
829 /** | |
830 * Returns the return type of the reflectee. | |
831 */ | |
832 TypeMirror get returnType; | |
833 | |
834 /** | |
835 * Returns a list of the parameter types of the reflectee. | |
836 */ | |
837 List<ParameterMirror> get parameters; | |
838 | |
839 /** | |
840 * A mirror on the [:call:] method for the reflectee. | |
841 */ | |
842 // This is only here because in the past the VM did not implement a call | |
843 // method on closures. | |
844 MethodMirror get callMethod; | |
845 } | |
846 | |
847 /** | |
848 * A [TypeVariableMirror] represents a type parameter of a generic | |
849 * type. | |
850 */ | |
851 abstract class TypeVariableMirror extends TypeMirror { | |
852 /** | |
853 * A mirror on the type that is the upper bound of this type variable. | |
854 */ | |
855 TypeMirror get upperBound; | |
856 | |
857 /** | |
858 * Is the reflectee static? | |
859 * | |
860 * For the purposes of the mirrors library, type variables are considered | |
861 * non-static. | |
862 */ | |
863 bool get isStatic; | |
864 | |
865 /** | |
866 * Returns [:true:] if this mirror is equal to [other]. | |
867 * Otherwise returns [:false:]. | |
868 * | |
869 * The equality holds if and only if | |
870 * (1) [other] is a mirror of the same kind | |
871 * and | |
872 * (2) [:simpleName == other.simpleName:] and | |
873 * [:owner == other.owner:]. | |
874 */ | |
875 bool operator == (other); | |
876 } | |
877 | |
878 /** | |
879 * A [TypedefMirror] represents a typedef in a Dart language program. | |
880 */ | |
881 abstract class TypedefMirror implements TypeMirror { | |
882 /** | |
883 * The defining type for this typedef. | |
884 * If the the type referred to by the reflectee is a function type | |
885 * *F*, the result will be [:FunctionTypeMirror:] reflecting *F* | |
886 * which is abstract and has an abstract method [:call:] whose | |
887 * signature corresponds to *F*. | |
888 * | |
889 * For instance [:void f(int):] is the referent for [:typedef void f(int):]. | |
890 */ | |
891 FunctionTypeMirror get referent; | |
892 } | |
893 | |
894 /** | |
895 * A [MethodMirror] reflects a Dart language function, method, | |
896 * constructor, getter, or setter. | |
897 */ | |
898 abstract class MethodMirror implements DeclarationMirror { | |
899 /** | |
900 * A mirror on the return type for the reflectee. | |
901 */ | |
902 TypeMirror get returnType; | |
903 | |
904 /** | |
905 * The source code for the reflectee, if available. Otherwise null. | |
906 */ | |
907 String get source; | |
908 | |
909 /** | |
910 * A list of mirrors on the parameters for the reflectee. | |
911 */ | |
912 List<ParameterMirror> get parameters; | |
913 | |
914 /** | |
915 * A function is considered non-static iff it is permited to refer to 'this'. | |
916 * | |
917 * Note that generative constructors are considered non-static, whereas | |
918 * factory constructors are considered static. | |
919 */ | |
920 bool get isStatic; | |
921 | |
922 /** | |
923 * Is the reflectee abstract? | |
924 */ | |
925 bool get isAbstract; | |
926 | |
927 /** | |
928 * Returns true if the reflectee is synthetic, and returns false otherwise. | |
929 * | |
930 * A reflectee is synthetic if it is a getter or setter implicitly introduced | |
931 * for a field or Type, or if it is a constructor that was implicitly | |
932 * introduced as a default constructor or as part of a mixin application. | |
933 */ | |
934 bool get isSynthetic; | |
935 | |
936 /** | |
937 * Is the reflectee a regular function or method? | |
938 * | |
939 * A function or method is regular if it is not a getter, setter, or | |
940 * constructor. Note that operators, by this definition, are | |
941 * regular methods. | |
942 */ | |
943 bool get isRegularMethod; | |
944 | |
945 /** | |
946 * Is the reflectee an operator? | |
947 */ | |
948 bool get isOperator; | |
949 | |
950 /** | |
951 * Is the reflectee a getter? | |
952 */ | |
953 bool get isGetter; | |
954 | |
955 /** | |
956 * Is the reflectee a setter? | |
957 */ | |
958 bool get isSetter; | |
959 | |
960 /** | |
961 * Is the reflectee a constructor? | |
962 */ | |
963 bool get isConstructor; | |
964 | |
965 /** | |
966 * The constructor name for named constructors and factory methods. | |
967 * | |
968 * For unnamed constructors, this is the empty string. For | |
969 * non-constructors, this is the empty string. | |
970 * | |
971 * For example, [:'bar':] is the constructor name for constructor | |
972 * [:Foo.bar:] of type [:Foo:]. | |
973 */ | |
974 Symbol get constructorName; | |
975 | |
976 /** | |
977 * Is the reflectee a const constructor? | |
978 */ | |
979 bool get isConstConstructor; | |
980 | |
981 /** | |
982 * Is the reflectee a generative constructor? | |
983 */ | |
984 bool get isGenerativeConstructor; | |
985 | |
986 /** | |
987 * Is the reflectee a redirecting constructor? | |
988 */ | |
989 bool get isRedirectingConstructor; | |
990 | |
991 /** | |
992 * Is the reflectee a factory constructor? | |
993 */ | |
994 bool get isFactoryConstructor; | |
995 | |
996 /** | |
997 * Returns true if this mirror is equal to [other]. | |
998 * | |
999 * The equality holds if and only if | |
1000 * (1) [other] is a mirror of the same kind | |
1001 * and | |
1002 * (2) [:simpleName == other.simpleName:] and | |
1003 * [:owner == other.owner:]. | |
1004 */ | |
1005 bool operator == (other); | |
1006 } | |
1007 | |
1008 /** | |
1009 * A [VariableMirror] reflects a Dart language variable declaration. | |
1010 */ | |
1011 abstract class VariableMirror implements DeclarationMirror { | |
1012 /** | |
1013 * Returns a mirror on the type of the reflectee. | |
1014 */ | |
1015 TypeMirror get type; | |
1016 | |
1017 /** | |
1018 * Returns [:true:] if the reflectee is a static variable. | |
1019 * Otherwise returns [:false:]. | |
1020 * | |
1021 * For the purposes of the mirror library, top-level variables are | |
1022 * implicitly declared static. | |
1023 */ | |
1024 bool get isStatic; | |
1025 | |
1026 /** | |
1027 * Returns [:true:] if the reflectee is a final variable. | |
1028 * Otherwise returns [:false:]. | |
1029 */ | |
1030 bool get isFinal; | |
1031 | |
1032 /** | |
1033 * Returns [:true:] if the reflectee is declared [:const:]. | |
1034 * Otherwise returns [:false:]. | |
1035 */ | |
1036 bool get isConst; | |
1037 | |
1038 /** | |
1039 * Returns true if this mirror is equal to [other]. | |
1040 * | |
1041 * The equality holds if and only if | |
1042 * (1) [other] is a mirror of the same kind | |
1043 * and | |
1044 * (2) [:simpleName == other.simpleName:] and | |
1045 * [:owner == other.owner:]. | |
1046 */ | |
1047 bool operator == (other); | |
1048 } | |
1049 | |
1050 /** | |
1051 * A [ParameterMirror] reflects a Dart formal parameter declaration. | |
1052 */ | |
1053 abstract class ParameterMirror implements VariableMirror { | |
1054 /** | |
1055 * A mirror on the type of this parameter. | |
1056 */ | |
1057 TypeMirror get type; | |
1058 | |
1059 /** | |
1060 * Returns [:true:] if the reflectee is an optional parameter. | |
1061 * Otherwise returns [:false:]. | |
1062 */ | |
1063 bool get isOptional; | |
1064 | |
1065 /** | |
1066 * Returns [:true:] if the reflectee is a named parameter. | |
1067 * Otherwise returns [:false:]. | |
1068 */ | |
1069 bool get isNamed; | |
1070 | |
1071 /** | |
1072 * Returns [:true:] if the reflectee has explicitly declared a default value. | |
1073 * Otherwise returns [:false:]. | |
1074 */ | |
1075 bool get hasDefaultValue; | |
1076 | |
1077 /** | |
1078 * If this is a required parameter, returns [:null:]. Otherwise returns a | |
1079 * mirror on the default value for this parameter. If no default is declared | |
1080 * for an optional parameter, the default is [:null:] and a mirror on [:null:] | |
1081 * is returned. | |
1082 */ | |
1083 InstanceMirror get defaultValue; | |
1084 } | |
1085 | |
1086 /** | |
1087 * A [SourceLocation] describes the span of an entity in Dart source code. | |
1088 */ | |
1089 abstract class SourceLocation { | |
1090 /** | |
1091 * The 1-based line number for this source location. | |
1092 * | |
1093 * A value of 0 means that the line number is unknown. | |
1094 */ | |
1095 int get line; | |
1096 | |
1097 /** | |
1098 * The 1-based column number for this source location. | |
1099 * | |
1100 * A value of 0 means that the column number is unknown. | |
1101 */ | |
1102 int get column; | |
1103 | |
1104 /** | |
1105 * Returns the URI where the source originated. | |
1106 */ | |
1107 Uri get sourceUri; | |
1108 } | |
1109 | |
1110 /** | |
1111 * Class used for encoding comments as metadata annotations. | |
1112 */ | |
1113 class Comment { | |
1114 /** | |
1115 * The comment text as written in the source text. | |
1116 */ | |
1117 final String text; | |
1118 | |
1119 /** | |
1120 * The comment text without the start, end, and padding text. | |
1121 * | |
1122 * For example, if [text] is [: /** Comment text. */ :] then the [trimmedText] | |
1123 * is [: Comment text. :]. | |
1124 */ | |
1125 final String trimmedText; | |
1126 | |
1127 /** | |
1128 * Is [:true:] if this comment is a documentation comment. | |
1129 * | |
1130 * That is, that the comment is either enclosed in [: /** ... */ :] or starts | |
1131 * with [: /// :]. | |
1132 */ | |
1133 final bool isDocComment; | |
1134 | |
1135 const Comment(this.text, this.trimmedText, this.isDocComment); | |
1136 } | |
1137 | |
1138 /** | |
1139 * Annotation describing how "dart:mirrors" is used (EXPERIMENTAL). | |
1140 * | |
1141 * When used as metadata on an import of "dart:mirrors" in library *L*, this | |
1142 * class describes how "dart:mirrors" is used by library *L* unless overridden. | |
1143 * See [override]. | |
1144 * | |
1145 * The following text is non-normative: | |
1146 * | |
1147 * In some scenarios, for example, when minifying Dart code, or when generating | |
1148 * JavaScript code from a Dart program, the size and performance of the output | |
1149 * can suffer from use of reflection. In those cases, telling the compiler | |
1150 * what is used, can have a significant impact. | |
1151 * | |
1152 * Example usage: | |
1153 * | |
1154 * @MirrorsUsed(symbols: 'foo', override: '*') | |
1155 * import 'dart:mirrors'; | |
1156 * | |
1157 * class Foo { | |
1158 * noSuchMethod(Invocation invocation) { | |
1159 * print(MirrorSystem.getName(invocation.memberName)); | |
1160 * } | |
1161 * } | |
1162 * | |
1163 * main() { | |
1164 * new Foo().foo(); // Prints "foo". | |
1165 * new Foo().bar(); // Might print an arbitrary (mangled) name, "bar". | |
1166 * } | |
1167 */ | |
1168 // TODO(ahe): Remove ", override: '*'" when it isn't necessary anymore. | |
1169 class MirrorsUsed { | |
1170 // Note: the fields of this class are untyped. This is because the most | |
1171 // convenient way to specify to specify symbols today is using a single | |
1172 // string. In some cases, a const list of classes might be convenient. Some | |
1173 // might prefer to use a const list of symbols. | |
1174 | |
1175 /** | |
1176 * The list of strings passed to new [Symbol], and symbols that might be | |
1177 * passed to [MirrorSystem.getName]. | |
1178 * | |
1179 * Combined with the names of [targets], [metaTargets] and their members, | |
1180 * this forms the complete list of strings passed to new [Symbol], and | |
1181 * symbols that might be passed to [MirrorSystem.getName] by the library to | |
1182 * which this metadata applies. | |
1183 * | |
1184 * The following text is non-normative: | |
1185 * | |
1186 * Specifying this option turns off the following warnings emitted by | |
1187 * dart2js: | |
1188 * | |
1189 * * Using "MirrorSystem.getName" may result in larger output. | |
1190 * * Using "new #{name}" may result in larger output. | |
1191 * | |
1192 * Use symbols = "*" to turn off the warnings mentioned above. | |
1193 * | |
1194 * For example, if using [noSuchMethod] to interact with a database, extract | |
1195 * all the possible column names and include them in this list. Similarly, | |
1196 * if using [noSuchMethod] to interact with another language (JavaScript, for | |
1197 * example) extract all the identifiers from API used and include them in | |
1198 * this list. | |
1199 */ | |
1200 final symbols; | |
1201 | |
1202 /** | |
1203 * A list of reflective targets. | |
1204 * | |
1205 * Combined with [metaTargets], this provides the complete list of reflective | |
1206 * targets used by the library to which this metadata applies. | |
1207 * | |
1208 * The following text is non-normative: | |
1209 * | |
1210 * For now, there is no formal description of what a reflective target is. | |
1211 * Informally, it is a list of things that are expected to have fully | |
1212 * functional mirrors. | |
1213 */ | |
1214 final targets; | |
1215 | |
1216 /** | |
1217 * A list of classes that when used as metadata indicates a reflective | |
1218 * target. | |
1219 * | |
1220 * See [targets]. | |
1221 */ | |
1222 final metaTargets; | |
1223 | |
1224 /** | |
1225 * A list of library names or "*". | |
1226 * | |
1227 * When used as metadata on an import of "dart:mirrors", this metadata does | |
1228 * not apply to the library in which the annotation is used, but instead | |
1229 * applies to the other libraries (all libraries if "*" is used). | |
1230 */ | |
1231 final override; | |
1232 | |
1233 const MirrorsUsed( | |
1234 {this.symbols, this.targets, this.metaTargets, this.override}); | |
1235 } | |
OLD | NEW |