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

Side by Side Diff: pkg/dev_compiler/tool/input_sdk/lib/mirrors/mirrors.dart

Issue 2698353003: unfork DDC's copy of most SDK libraries (Closed)
Patch Set: revert core_patch Created 3 years, 9 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
OLDNEW
(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 invocation.
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 invocation* 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
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 * All libraries known to the mirror system, indexed by their URI.
73 *
74 * Returns an unmodifiable map of the libraries with [LibraryMirror.uri] as
75 * keys.
76 *
77 * For a runtime mirror system, only libraries which are currently loaded
78 * are included, and repeated calls of this method may return different maps
79 * as libraries are loaded.
80 */
81 Map<Uri, LibraryMirror> get libraries;
82
83 /**
84 * Returns the unique library named [libraryName] if it exists.
85 *
86 * If no unique library exists, an error is thrown.
87 */
88 LibraryMirror findLibrary(Symbol libraryName) {
89 return libraries.values.singleWhere(
90 (library) => library.simpleName == libraryName);
91 }
92
93 /**
94 * A mirror on the isolate associated with this [MirrorSystem].
95 *
96 * This may be null if this mirror system is not running.
97 */
98 IsolateMirror get isolate;
99
100 /**
101 * A mirror on the [:dynamic:] type.
102 */
103 TypeMirror get dynamicType;
104
105 /**
106 * A mirror on the [:void:] type.
107 */
108 TypeMirror get voidType;
109
110 /**
111 * Returns the name of [symbol].
112 *
113 * The following text is non-normative:
114 *
115 * Using this method may result in larger output. If possible, use
116 * [MirrorsUsed] to specify which symbols must be retained in clear text.
117 */
118 external static String getName(Symbol symbol);
119
120 /**
121 * Returns a symbol for [name].
122 *
123 * If [library] is not a [LibraryMirror] or if [name] is a private identifier
124 * and [library] is `null`, throws an [ArgumentError]. If [name] is a private
125 * identifier, the symbol returned is with respect to [library].
126 *
127 * The following text is non-normative:
128 *
129 * Using this method may result in larger output. If possible, use
130 * the const constructor of [Symbol] or symbol literals.
131 */
132 external static Symbol getSymbol(String name, [LibraryMirror library]);
133 }
134
135 /**
136 * Returns a [MirrorSystem] for the current isolate.
137 */
138 external MirrorSystem currentMirrorSystem();
139
140 /**
141 * Reflects an instance.
142 *
143 * Returns an [InstanceMirror] reflecting [reflectee]. If [reflectee] is a
144 * function or an instance of a class that has a [:call:] method, the returned
145 * instance mirror will be a [ClosureMirror].
146 *
147 * Note that since one cannot obtain an object from another isolate, this
148 * function can only be used to obtain mirrors on objects of the current
149 * isolate.
150 */
151 external InstanceMirror reflect(Object reflectee);
152
153 /**
154 * Reflects a class declaration.
155 *
156 * Let *C* be the original class declaration of the class represented by [key].
157 * This function returns a [ClassMirror] reflecting *C*.
158 *
159 * If [key] is not an instance of [Type], then this function throws an
160 * [ArgumentError]. If [key] is the Type for dynamic or a function typedef,
161 * throws an [ArgumentError].
162 *
163 * Note that since one cannot obtain a [Type] object from another isolate, this
164 * function can only be used to obtain class mirrors on classes of the current
165 * isolate.
166 */
167 external ClassMirror reflectClass(Type key);
168
169 /**
170 * Reflects the type represented by [key].
171 *
172 * If [key] is not an instance of [Type], then this function throws an
173 * [ArgumentError].
174 *
175 * Note that since one cannot obtain a [Type] object from another isolate, this
176 * function can only be used to obtain type mirrors on types of the current
177 * isolate.
178 */
179 external TypeMirror reflectType(Type key);
180
181 /**
182 * A [Mirror] reflects some Dart language entity.
183 *
184 * Every [Mirror] originates from some [MirrorSystem].
185 */
186 abstract class Mirror {}
187
188 /**
189 * An [IsolateMirror] reflects an isolate.
190 */
191 abstract class IsolateMirror implements Mirror {
192 /**
193 * A unique name used to refer to the isolate in debugging messages.
194 */
195 String get debugName;
196
197 /**
198 * Whether this mirror reflects the currently running isolate.
199 */
200 bool get isCurrent;
201
202 /**
203 * The root library for the reflected isolate.
204 */
205 LibraryMirror get rootLibrary;
206
207 /**
208 * Whether [other] is an [IsolateMirror] on the same isolate as this mirror.
209 *
210 * The equality holds if and only if
211 *
212 * 1. [other] is a mirror of the same kind, and
213 * 2. the isolate being reflected by this mirror is the same isolate being
214 * reflected by [other].
215 */
216 bool operator == (other);
217 }
218
219 /**
220 * A [DeclarationMirror] reflects some entity declared in a Dart program.
221 */
222 abstract class DeclarationMirror implements Mirror {
223 /**
224 * The simple name for this Dart language entity.
225 *
226 * The simple name is in most cases the identifier name of the entity,
227 * such as 'myMethod' for a method, [:void myMethod() {...}:] or 'mylibrary'
228 * for a [:library 'mylibrary';:] declaration.
229 */
230 Symbol get simpleName;
231
232 /**
233 * The fully-qualified name for this Dart language entity.
234 *
235 * This name is qualified by the name of the owner. For instance,
236 * the qualified name of a method 'method' in class 'Class' in
237 * library 'library' is 'library.Class.method'.
238 *
239 * Returns a [Symbol] constructed from a string representing the
240 * fully qualified name of the reflectee.
241 * Let *o* be the [owner] of this mirror, let *r* be the reflectee of
242 * this mirror, let *p* be the fully qualified
243 * name of the reflectee of *o*, and let *s* be the simple name of *r*
244 * computed by [simpleName].
245 * The fully qualified name of *r* is the
246 * concatenation of *p*, '.', and *s*.
247 *
248 * Because an isolate can contain more than one library with the same name (at
249 * different URIs), a fully-qualified name does not uniquely identify any
250 * language entity.
251 */
252 Symbol get qualifiedName;
253
254 /**
255 * A mirror on the owner of this Dart language entity.
256 *
257 * The owner is the declaration immediately surrounding the reflectee:
258 *
259 * * For a library, the owner is [:null:].
260 * * For a class declaration, typedef or top level function or variable, the
261 * owner is the enclosing library.
262 * * For a mixin application `S with M`, the owner is the owner of `M`.
263 * * For a constructor, the owner is the immediately enclosing class.
264 * * For a method, instance variable or a static variable, the owner is the
265 * immediately enclosing class, unless the class is a mixin application
266 * `S with M`, in which case the owner is `M`. Note that `M` may be an
267 * invocation of a generic.
268 * * For a parameter, local variable or local function the owner is the
269 * immediately enclosing function.
270 */
271 DeclarationMirror get owner;
272
273 /**
274 * Whether this declaration is library private.
275 *
276 * Always returns `false` for a library declaration,
277 * otherwise returns `true` if the declaration's name starts with an
278 * underscore character (`_`), and `false` if it doesn't.
279 */
280 bool get isPrivate;
281
282 /**
283 * Whether this declaration is top-level.
284 *
285 * A declaration is considered top-level if its [owner] is a [LibraryMirror].
286 */
287 bool get isTopLevel;
288
289 /**
290 * The source location of this Dart language entity, or [:null:] if the
291 * entity is synthetic.
292 *
293 * If the reflectee is a variable, the returned location gives the position
294 * of the variable name at its point of declaration.
295 *
296 * If the reflectee is a library, class, typedef, function or type variable
297 * with associated metadata, the returned location gives the position of the
298 * first metadata declaration associated with the reflectee.
299 *
300 * Otherwise:
301 *
302 * If the reflectee is a library, the returned location gives the position of
303 * the keyword 'library' at the reflectee's point of declaration, if the
304 * reflectee is a named library, or the first character of the first line in
305 * the compilation unit defining the reflectee if the reflectee is anonymous.
306 *
307 * If the reflectee is an abstract class, the returned location gives the
308 * position of the keyword 'abstract' at the reflectee's point of declaration.
309 * Otherwise, if the reflectee is a class, the returned location gives the
310 * position of the keyword 'class' at the reflectee's point of declaration.
311 *
312 * If the reflectee is a typedef the returned location gives the position of
313 * the of the keyword 'typedef' at the reflectee's point of declaration.
314 *
315 * If the reflectee is a function with a declared return type, the returned
316 * location gives the position of the function's return type at the
317 * reflectee's point of declaration. Otherwise. the returned location gives
318 * the position of the function's name at the reflectee's point of
319 * declaration.
320 *
321 * This operation is optional and may throw an [UnsupportedError].
322 */
323 SourceLocation get location;
324
325 /**
326 * A list of the metadata associated with this declaration.
327 *
328 * Let *D* be the declaration this mirror reflects.
329 * If *D* is decorated with annotations *A1, ..., An*
330 * where *n > 0*, then for each annotation *Ai* associated
331 * with *D, 1 <= i <= n*, let *ci* be the constant object
332 * specified by *Ai*. Then this method returns a list whose
333 * members are instance mirrors on *c1, ..., cn*.
334 * If no annotations are associated with *D*, then
335 * an empty list is returned.
336 *
337 * If evaluating any of *c1, ..., cn* would cause a
338 * compilation error
339 * the effect is the same as if a non-reflective compilation error
340 * had been encountered.
341 */
342 List<InstanceMirror> get metadata;
343 }
344
345 /**
346 * An [ObjectMirror] is a common superinterface of [InstanceMirror],
347 * [ClassMirror], and [LibraryMirror] that represents their shared
348 * functionality.
349 *
350 * For the purposes of the mirrors library, these types are all
351 * object-like, in that they support method invocation and field
352 * access. Real Dart objects are represented by the [InstanceMirror]
353 * type.
354 *
355 * See [InstanceMirror], [ClassMirror], and [LibraryMirror].
356 */
357 abstract class ObjectMirror implements Mirror {
358
359 /**
360 * Invokes the named function and returns a mirror on the result.
361 *
362 * Let *o* be the object reflected by this mirror, let *f* be the simple name
363 * of the member denoted by [memberName], let *a1, ..., an* be the elements
364 * of [positionalArguments], let *k1, ..., km* be the identifiers denoted by
365 * the elements of [namedArguments.keys], and let *v1, ..., vm* be the
366 * elements of [namedArguments.values]. Then this method will perform the
367 * method invocation *o.f(a1, ..., an, k1: v1, ..., km: vm)* in a scope that
368 * has access to the private members of *o* (if *o* is a class or library) or
369 * the private members of the class of *o* (otherwise).
370 *
371 * If the invocation returns a result *r*, this method returns the result of
372 * calling [reflect]\(*r*\).
373 *
374 * If the invocation causes a compilation error the effect is the same as if
375 * a non-reflective compilation error had been encountered.
376 *
377 * If the invocation throws an exception *e* (that it does not catch), this
378 * method throws *e*.
379 */
380 /*
381 * TODO(turnidge): Handle ambiguous names.
382 * TODO(turnidge): Handle optional & named arguments.
383 */
384 InstanceMirror invoke(Symbol memberName,
385 List positionalArguments,
386 [Map<Symbol,dynamic> namedArguments]);
387
388 /**
389 * Invokes a getter and returns a mirror on the result.
390 *
391 * The getter can be the implicit getter for a field or a user-defined getter
392 * method.
393 *
394 * Let *o* be the object reflected by this mirror,
395 * let *f* be the simple name of the getter denoted by [fieldName].
396 *
397 * Then this method will perform the getter invocation *o.f* in a scope that
398 * has access to the private members of *o* (if *o* is a class or library) or
399 * the private members of the class of *o* (otherwise).
400 *
401 * If this mirror is an [InstanceMirror], and [fieldName] denotes an instance
402 * method on its reflectee, the result of the invocation is an instance
403 * mirror on a closure corresponding to that method.
404 *
405 * If this mirror is a [LibraryMirror], and [fieldName] denotes a top-level
406 * method in the corresponding library, the result of the invocation is an
407 * instance mirror on a closure corresponding to that method.
408 *
409 * If this mirror is a [ClassMirror], and [fieldName] denotes a static method
410 * in the corresponding class, the result of the invocation is an instance
411 * mirror on a closure corresponding to that method.
412 *
413 * If the invocation returns a result *r*, this method returns the result of
414 * calling [reflect]\(*r*\).
415 *
416 * If the invocation causes a compilation error, the effect is the same as if
417 * a non-reflective compilation error had been encountered.
418 *
419 * If the invocation throws an exception *e* (that it does not catch), this
420 * method throws *e*.
421 */
422 // TODO(ahe): Remove stuff about scope and private members. [fieldName] is a
423 // capability giving access to private members.
424 InstanceMirror getField(Symbol fieldName);
425
426 /**
427 * Invokes a setter and returns a mirror on the result.
428 *
429 * The setter may be either the implicit setter for a non-final field or a
430 * user-defined setter method.
431 *
432 * Let *o* be the object reflected by this mirror,
433 * let *f* be the simple name of the getter denoted by [fieldName],
434 * and let *a* be the object bound to [value].
435 *
436 * Then this method will perform the setter invocation *o.f = a* in a scope
437 * that has access to the private members of *o* (if *o* is a class or
438 * library) or the private members of the class of *o* (otherwise).
439 *
440 * If the invocation returns a result *r*, this method returns the result of
441 * calling [reflect]\([value]\).
442 *
443 * If the invocation causes a compilation error, the effect is the same as if
444 * a non-reflective compilation error had been encountered.
445 *
446 * If the invocation throws an exception *e* (that it does not catch) this
447 * method throws *e*.
448 */
449 /* TODO(turnidge): Handle ambiguous names.*/
450 InstanceMirror setField(Symbol fieldName, Object value);
451 }
452
453 /**
454 * An [InstanceMirror] reflects an instance of a Dart language object.
455 */
456 abstract class InstanceMirror implements ObjectMirror {
457 /**
458 * A mirror on the type of the reflectee.
459 *
460 * Returns a mirror on the actual class of the reflectee.
461 * The class of the reflectee may differ from
462 * the object returned by invoking [runtimeType] on
463 * the reflectee.
464 */
465 ClassMirror get type;
466
467 /**
468 * Whether [reflectee] will return the instance reflected by this mirror.
469 *
470 * This will always be true in the local case (reflecting instances in the
471 * same isolate), but only true in the remote case if this mirror reflects a
472 * simple value.
473 *
474 * A value is simple if one of the following holds:
475 *
476 * * the value is [:null:]
477 * * the value is of type [num]
478 * * the value is of type [bool]
479 * * the value is of type [String]
480 */
481 bool get hasReflectee;
482
483 /**
484 * If the [InstanceMirror] reflects an instance it is meaningful to
485 * have a local reference to, we provide access to the actual
486 * instance here.
487 *
488 * If you access [reflectee] when [hasReflectee] is false, an
489 * exception is thrown.
490 */
491 get reflectee;
492
493 /**
494 * Whether this mirror is equal to [other].
495 *
496 * The equality holds if and only if
497 *
498 * 1. [other] is a mirror of the same kind, and
499 * 2. either
500 *
501 * a. [hasReflectee] is true and so is
502 * [:identical(reflectee, other.reflectee):], or
503 *
504 * b. the remote objects reflected by this mirror and by [other] are
505 * identical.
506 */
507 bool operator == (other);
508
509 /**
510 * Perform [invocation] on [reflectee].
511 * Equivalent to
512 *
513 * this.invoke(invocation.memberName,
514 * invocation.positionalArguments,
515 * invocation.namedArguments);
516 */
517 delegate(Invocation invocation);
518 }
519
520 /**
521 * A [ClosureMirror] reflects a closure.
522 *
523 * A [ClosureMirror] provides the ability to execute its reflectee and
524 * introspect its function.
525 */
526 abstract class ClosureMirror implements InstanceMirror {
527 /**
528 * A mirror on the function associated with this closure.
529 *
530 * The function associated with an implicit closure of a function is that
531 * function.
532 *
533 * The function associated with an instance of a class that has a [:call:]
534 * method is that [:call:] method.
535 *
536 * A Dart implementation might choose to create a class for each closure
537 * expression, in which case [:function:] would be the same as
538 * [:type.declarations[#call]:]. But the Dart language model does not require
539 * this. A more typical implementation involves a single closure class for
540 * each type signature, where the call method dispatches to a function held
541 * in the closure rather the call method
542 * directly implementing the closure body. So one cannot rely on closures from
543 * distinct closure expressions having distinct classes ([:type:]), but one
544 * can rely on them having distinct functions ([:function:]).
545 */
546 MethodMirror get function;
547
548 /**
549 * Executes the closure and returns a mirror on the result.
550 *
551 * Let *f* be the closure reflected by this mirror,
552 * let *a1, ..., an* be the elements of [positionalArguments],
553 * let *k1, ..., km* be the identifiers denoted by the elements of
554 * [namedArguments.keys],
555 * and let *v1, ..., vm* be the elements of [namedArguments.values].
556 *
557 * Then this method will perform the method invocation
558 * *f(a1, ..., an, k1: v1, ..., km: vm)*.
559 *
560 * If the invocation returns a result *r*, this method returns the result of
561 * calling [reflect]\(*r*\).
562 *
563 * If the invocation causes a compilation error, the effect is the same as if
564 * a non-reflective compilation error had been encountered.
565 *
566 * If the invocation throws an exception *e* (that it does not catch), this
567 * method throws *e*.
568 */
569 InstanceMirror apply(List positionalArguments,
570 [Map<Symbol, dynamic> namedArguments]);
571 }
572
573 /**
574 * A [LibraryMirror] reflects a Dart language library, providing
575 * access to the variables, functions, and classes of the
576 * library.
577 */
578 abstract class LibraryMirror implements DeclarationMirror, ObjectMirror {
579 /**
580 * The absolute uri of the library.
581 */
582 Uri get uri;
583
584 /**
585 * Returns an immutable map of the declarations actually given in the library.
586 *
587 * This map includes all regular methods, getters, setters, fields, classes
588 * and typedefs actually declared in the library. The map is keyed by the
589 * simple names of the declarations.
590 */
591 Map<Symbol, DeclarationMirror> get declarations;
592
593 /**
594 * Whether this mirror is equal to [other].
595 *
596 * The equality holds if and only if
597 *
598 * 1. [other] is a mirror of the same kind, and
599 * 2. The library being reflected by this mirror and the library being
600 * reflected by [other] are the same library in the same isolate.
601 */
602 bool operator ==(other);
603
604 /**
605 * Returns a list of the imports and exports in this library;
606 */
607 List<LibraryDependencyMirror> get libraryDependencies;
608 }
609
610 /// A mirror on an import or export declaration.
611 abstract class LibraryDependencyMirror implements Mirror {
612 /// Is `true` if this dependency is an import.
613 bool get isImport;
614
615 /// Is `true` if this dependency is an export.
616 bool get isExport;
617
618 /// Returns the library mirror of the library that imports or exports the
619 /// [targetLibrary].
620 LibraryMirror get sourceLibrary;
621
622 /// Returns the library mirror of the library that is imported or exported,
623 /// or null if the library is not loaded.
624 LibraryMirror get targetLibrary;
625
626 /// Returns the prefix if this is a prefixed import and `null` otherwise.
627 Symbol get prefix;
628
629 /// Returns the list of show/hide combinators on the import/export
630 /// declaration.
631 List<CombinatorMirror> get combinators;
632
633 /// Returns the source location for this import/export declaration.
634 SourceLocation get location;
635
636 List<InstanceMirror> get metadata;
637 }
638
639 /// A mirror on a show/hide combinator declared on a library dependency.
640 abstract class CombinatorMirror implements Mirror {
641 /// The list of identifiers on the combinator.
642 List<Symbol> get identifiers;
643
644 /// Is `true` if this is a 'show' combinator.
645 bool get isShow;
646
647 /// Is `true` if this is a 'hide' combinator.
648 bool get isHide;
649 }
650
651 /**
652 * A [TypeMirror] reflects a Dart language class, typedef,
653 * function type or type variable.
654 */
655 abstract class TypeMirror implements DeclarationMirror {
656 /**
657 * Returns true if this mirror reflects dynamic, a non-generic class or
658 * typedef, or an instantiated generic class or typedef in the current
659 * isolate. Otherwise, returns false.
660 */
661 bool get hasReflectedType;
662
663 /**
664 * If [:hasReflectedType:] returns true, returns the corresponding [Type].
665 * Otherwise, an [UnsupportedError] is thrown.
666 */
667 Type get reflectedType;
668
669 /**
670 * An immutable list with mirrors for all type variables for this type.
671 *
672 * If this type is a generic declaration or an invocation of a generic
673 * declaration, the returned list contains mirrors on the type variables
674 * declared in the original declaration.
675 * Otherwise, the returned list is empty.
676 *
677 * This list preserves the order of declaration of the type variables.
678 */
679 List<TypeVariableMirror> get typeVariables;
680
681 /**
682 * An immutable list with mirrors for all type arguments for
683 * this type.
684 *
685 * If the reflectee is an invocation of a generic class,
686 * the type arguments are the bindings of its type parameters.
687 * If the reflectee is the original declaration of a generic,
688 * it has no type arguments and this method returns an empty list.
689 * If the reflectee is not generic, then
690 * it has no type arguments and this method returns an empty list.
691 *
692 * This list preserves the order of declaration of the type variables.
693 */
694 List<TypeMirror> get typeArguments;
695
696 /**
697 * Is this the original declaration of this type?
698 *
699 * For most classes, they are their own original declaration. For
700 * generic classes, however, there is a distinction between the
701 * original class declaration, which has unbound type variables, and
702 * the instantiations of generic classes, which have bound type
703 * variables.
704 */
705 bool get isOriginalDeclaration;
706
707 /**
708 * A mirror on the original declaration of this type.
709 *
710 * For most classes, they are their own original declaration. For
711 * generic classes, however, there is a distinction between the
712 * original class declaration, which has unbound type variables, and
713 * the instantiations of generic classes, which have bound type
714 * variables.
715 */
716 TypeMirror get originalDeclaration;
717
718
719 /**
720 * Checks the subtype relationship, denoted by `<:` in the language
721 * specification.
722 *
723 * This is the type relationship used in `is` test checks.
724 */
725 bool isSubtypeOf(TypeMirror other);
726
727 /**
728 * Checks the assignability relationship, denoted by `<=>` in the language
729 * specification.
730 *
731 * This is the type relationship tested on assignment in checked mode.
732 */
733 bool isAssignableTo(TypeMirror other);
734 }
735
736 /**
737 * A [ClassMirror] reflects a Dart language class.
738 */
739 abstract class ClassMirror implements TypeMirror, ObjectMirror {
740 /**
741 * A mirror on the superclass on the reflectee.
742 *
743 * If this type is [:Object:], the superclass will be null.
744 */
745 ClassMirror get superclass;
746
747 /**
748 * A list of mirrors on the superinterfaces of the reflectee.
749 */
750 List<ClassMirror> get superinterfaces;
751
752 /**
753 * Is the reflectee abstract?
754 */
755 bool get isAbstract;
756
757 /**
758 * Returns an immutable map of the declarations actually given in the class
759 * declaration.
760 *
761 * This map includes all regular methods, getters, setters, fields,
762 * constructors and type variables actually declared in the class. Both
763 * static and instance members are included, but no inherited members are
764 * included. The map is keyed by the simple names of the declarations.
765 *
766 * This does not include inherited members.
767 */
768 Map<Symbol, DeclarationMirror> get declarations;
769
770 /**
771 * Returns a map of the methods, getters and setters of an instance of the
772 * class.
773 *
774 * The intent is to capture those members that constitute the API of an
775 * instance. Hence fields are not included, but the getters and setters
776 * implicitly introduced by fields are included. The map includes methods,
777 * getters and setters that are inherited as well as those introduced by the
778 * class itself.
779 *
780 * The map is keyed by the simple names of the members.
781 */
782 Map<Symbol, MethodMirror> get instanceMembers;
783
784 /**
785 * Returns a map of the static methods, getters and setters of the class.
786 *
787 * The intent is to capture those members that constitute the API of a class.
788 * Hence fields are not included, but the getters and setters implicitly
789 * introduced by fields are included.
790 *
791 * The map is keyed by the simple names of the members.
792 */
793 Map<Symbol, MethodMirror> get staticMembers;
794
795
796 /**
797 * The mixin of this class.
798 *
799 * If this class is the result of a mixin application of the form S with M,
800 * returns a class mirror on M. Otherwise returns a class mirror on
801 * [reflectee].
802 */
803 ClassMirror get mixin;
804
805 // TODO(ahe): What about:
806 // /// Finds the instance member named [name] declared or inherited in the
807 // /// reflected class.
808 // DeclarationMirror instanceLookup(Symbol name);
809
810 /**
811 * Invokes the named constructor and returns a mirror on the result.
812 *
813 * Let *c* be the class reflected by this mirror,
814 * let *a1, ..., an* be the elements of [positionalArguments],
815 * let *k1, ..., km* be the identifiers denoted by the elements of
816 * [namedArguments.keys],
817 * and let *v1, ..., vm* be the elements of [namedArguments.values].
818 *
819 * If [constructorName] was created from the empty string, then this method
820 * will execute the instance creation expression
821 * *new c(a1, ..., an, k1: v1, ..., km: vm)* in a scope that has access to
822 * the private members of *c*.
823 *
824 * Otherwise, let *f* be the simple name of the constructor denoted by
825 * [constructorName]. Then this method will execute the instance creation
826 * expression *new c.f(a1, ..., an, k1: v1, ..., km: vm)* in a scope that has
827 * access to the private members of *c*.
828 *
829 * In either case:
830 *
831 * * If the expression evaluates to a result *r*, this method returns the
832 * result of calling [reflect]\(*r*\).
833 * * If evaluating the expression causes a compilation error, the effect is
834 * the same as if a non-reflective compilation error had been encountered.
835 * * If evaluating the expression throws an exception *e* (that it does not
836 * catch), this method throws *e*.
837 */
838 InstanceMirror newInstance(Symbol constructorName,
839 List positionalArguments,
840 [Map<Symbol,dynamic> namedArguments]);
841
842 /**
843 * Whether this mirror is equal to [other].
844 *
845 * The equality holds if and only if
846 *
847 * 1. [other] is a mirror of the same kind, and
848 * 2. This mirror and [other] reflect the same class.
849 *
850 * Note that if the reflected class is an invocation of a generic class, 2.
851 * implies that the reflected class and [other] have equal type arguments.
852 */
853 bool operator == (other);
854
855 /**
856 * Returns whether the class denoted by the receiver is a subclass of the
857 * class denoted by the argument.
858 *
859 * Note that the subclass relationship is reflexive.
860 */
861 bool isSubclassOf(ClassMirror other);
862 }
863
864 /**
865 * A [FunctionTypeMirror] represents the type of a function in the
866 * Dart language.
867 */
868 abstract class FunctionTypeMirror implements ClassMirror {
869 /**
870 * Returns the return type of the reflectee.
871 */
872 TypeMirror get returnType;
873
874 /**
875 * Returns a list of the parameter types of the reflectee.
876 */
877 List<ParameterMirror> get parameters;
878
879 /**
880 * A mirror on the [:call:] method for the reflectee.
881 */
882 // This is only here because in the past the VM did not implement a call
883 // method on closures.
884 MethodMirror get callMethod;
885 }
886
887 /**
888 * A [TypeVariableMirror] represents a type parameter of a generic type.
889 */
890 abstract class TypeVariableMirror extends TypeMirror {
891 /**
892 * A mirror on the type that is the upper bound of this type variable.
893 */
894 TypeMirror get upperBound;
895
896 /**
897 * Is the reflectee static?
898 *
899 * For the purposes of the mirrors library, type variables are considered
900 * non-static.
901 */
902 bool get isStatic;
903
904 /**
905 * Whether [other] is a [TypeVariableMirror] on the same type variable as this
906 * mirror.
907 *
908 * The equality holds if and only if
909 *
910 * 1. [other] is a mirror of the same kind, and
911 * 2. [:simpleName == other.simpleName:] and [:owner == other.owner:].
912 */
913 bool operator == (other);
914 }
915
916 /**
917 * A [TypedefMirror] represents a typedef in a Dart language program.
918 */
919 abstract class TypedefMirror implements TypeMirror {
920 /**
921 * The defining type for this typedef.
922 *
923 * If the type referred to by the reflectee is a function type *F*, the
924 * result will be [:FunctionTypeMirror:] reflecting *F* which is abstract
925 * and has an abstract method [:call:] whose signature corresponds to *F*.
926 * For instance [:void f(int):] is the referent for [:typedef void f(int):].
927 */
928 FunctionTypeMirror get referent;
929 }
930
931 /**
932 * A [MethodMirror] reflects a Dart language function, method,
933 * constructor, getter, or setter.
934 */
935 abstract class MethodMirror implements DeclarationMirror {
936 /**
937 * A mirror on the return type for the reflectee.
938 */
939 TypeMirror get returnType;
940
941 /**
942 * The source code for the reflectee, if available. Otherwise null.
943 */
944 String get source;
945
946 /**
947 * A list of mirrors on the parameters for the reflectee.
948 */
949 List<ParameterMirror> get parameters;
950
951 /**
952 * A function is considered non-static iff it is permited to refer to 'this'.
953 *
954 * Note that generative constructors are considered non-static, whereas
955 * factory constructors are considered static.
956 */
957 bool get isStatic;
958
959 /**
960 * Is the reflectee abstract?
961 */
962 bool get isAbstract;
963
964 /**
965 * Returns true if the reflectee is synthetic, and returns false otherwise.
966 *
967 * A reflectee is synthetic if it is a getter or setter implicitly introduced
968 * for a field or Type, or if it is a constructor that was implicitly
969 * introduced as a default constructor or as part of a mixin application.
970 */
971 bool get isSynthetic;
972
973 /**
974 * Is the reflectee a regular function or method?
975 *
976 * A function or method is regular if it is not a getter, setter, or
977 * constructor. Note that operators, by this definition, are
978 * regular methods.
979 */
980 bool get isRegularMethod;
981
982 /**
983 * Is the reflectee an operator?
984 */
985 bool get isOperator;
986
987 /**
988 * Is the reflectee a getter?
989 */
990 bool get isGetter;
991
992 /**
993 * Is the reflectee a setter?
994 */
995 bool get isSetter;
996
997 /**
998 * Is the reflectee a constructor?
999 */
1000 bool get isConstructor;
1001
1002 /**
1003 * The constructor name for named constructors and factory methods.
1004 *
1005 * For unnamed constructors, this is the empty string. For
1006 * non-constructors, this is the empty string.
1007 *
1008 * For example, [:'bar':] is the constructor name for constructor
1009 * [:Foo.bar:] of type [:Foo:].
1010 */
1011 Symbol get constructorName;
1012
1013 /**
1014 * Is the reflectee a const constructor?
1015 */
1016 bool get isConstConstructor;
1017
1018 /**
1019 * Is the reflectee a generative constructor?
1020 */
1021 bool get isGenerativeConstructor;
1022
1023 /**
1024 * Is the reflectee a redirecting constructor?
1025 */
1026 bool get isRedirectingConstructor;
1027
1028 /**
1029 * Is the reflectee a factory constructor?
1030 */
1031 bool get isFactoryConstructor;
1032
1033 /**
1034 * Whether this mirror is equal to [other].
1035 *
1036 * The equality holds if and only if
1037 *
1038 * 1. [other] is a mirror of the same kind, and
1039 * 2. [:simpleName == other.simpleName:] and [:owner == other.owner:].
1040 */
1041 bool operator == (other);
1042 }
1043
1044 /**
1045 * A [VariableMirror] reflects a Dart language variable declaration.
1046 */
1047 abstract class VariableMirror implements DeclarationMirror {
1048 /**
1049 * Returns a mirror on the type of the reflectee.
1050 */
1051 TypeMirror get type;
1052
1053 /**
1054 * Returns [:true:] if the reflectee is a static variable.
1055 * Otherwise returns [:false:].
1056 *
1057 * For the purposes of the mirror library, top-level variables are
1058 * implicitly declared static.
1059 */
1060 bool get isStatic;
1061
1062 /**
1063 * Returns [:true:] if the reflectee is a final variable.
1064 * Otherwise returns [:false:].
1065 */
1066 bool get isFinal;
1067
1068 /**
1069 * Returns [:true:] if the reflectee is declared [:const:].
1070 * Otherwise returns [:false:].
1071 */
1072 bool get isConst;
1073
1074 /**
1075 * Whether this mirror is equal to [other].
1076 *
1077 * The equality holds if and only if
1078 *
1079 * 1. [other] is a mirror of the same kind, and
1080 * 2. [:simpleName == other.simpleName:] and [:owner == other.owner:].
1081 */
1082 bool operator == (other);
1083 }
1084
1085 /**
1086 * A [ParameterMirror] reflects a Dart formal parameter declaration.
1087 */
1088 abstract class ParameterMirror implements VariableMirror {
1089 /**
1090 * A mirror on the type of this parameter.
1091 */
1092 TypeMirror get type;
1093
1094 /**
1095 * Returns [:true:] if the reflectee is an optional parameter.
1096 * Otherwise returns [:false:].
1097 */
1098 bool get isOptional;
1099
1100 /**
1101 * Returns [:true:] if the reflectee is a named parameter.
1102 * Otherwise returns [:false:].
1103 */
1104 bool get isNamed;
1105
1106 /**
1107 * Returns [:true:] if the reflectee has explicitly declared a default value.
1108 * Otherwise returns [:false:].
1109 */
1110 bool get hasDefaultValue;
1111
1112 /**
1113 * Returns the default value of an optional parameter.
1114 *
1115 * Returns an [InstanceMirror] on the (compile-time constant)
1116 * default value for an optional parameter.
1117 * If no default value is declared, it defaults to `null`
1118 * and a mirror of `null` is returned.
1119 *
1120 * Returns `null` for a required parameter.
1121 */
1122 InstanceMirror get defaultValue;
1123 }
1124
1125 /**
1126 * A [SourceLocation] describes the span of an entity in Dart source code.
1127 */
1128 abstract class SourceLocation {
1129 /**
1130 * The 1-based line number for this source location.
1131 *
1132 * A value of 0 means that the line number is unknown.
1133 */
1134 int get line;
1135
1136 /**
1137 * The 1-based column number for this source location.
1138 *
1139 * A value of 0 means that the column number is unknown.
1140 */
1141 int get column;
1142
1143 /**
1144 * Returns the URI where the source originated.
1145 */
1146 Uri get sourceUri;
1147 }
1148
1149 /**
1150 * Class used for encoding comments as metadata annotations.
1151 */
1152 class Comment {
1153 /**
1154 * The comment text as written in the source text.
1155 */
1156 final String text;
1157
1158 /**
1159 * The comment text without the start, end, and padding text.
1160 *
1161 * For example, if [text] is [: /** Comment text. */ :] then the [trimmedText]
1162 * is [: Comment text. :].
1163 */
1164 final String trimmedText;
1165
1166 /**
1167 * Is [:true:] if this comment is a documentation comment.
1168 *
1169 * That is, that the comment is either enclosed in [: /** ... */ :] or starts
1170 * with [: /// :].
1171 */
1172 final bool isDocComment;
1173
1174 const Comment(this.text, this.trimmedText, this.isDocComment);
1175 }
1176
1177 /**
1178 * Annotation describing how "dart:mirrors" is used (EXPERIMENTAL).
1179 *
1180 * When used as metadata on an import of "dart:mirrors" in library *L*, this
1181 * class describes how "dart:mirrors" is used by library *L* unless overridden.
1182 * See [override].
1183 *
1184 * The following text is non-normative:
1185 *
1186 * In some scenarios, for example, when minifying Dart code, or when generating
1187 * JavaScript code from a Dart program, the size and performance of the output
1188 * can suffer from use of reflection. In those cases, telling the compiler
1189 * what is used, can have a significant impact.
1190 *
1191 * Example usage:
1192 *
1193 * @MirrorsUsed(symbols: 'foo')
1194 * import 'dart:mirrors';
1195 *
1196 * class Foo {
1197 * noSuchMethod(Invocation invocation) {
1198 * print(MirrorSystem.getName(invocation.memberName));
1199 * }
1200 * }
1201 *
1202 * main() {
1203 * new Foo().foo(); // Prints "foo".
1204 * new Foo().bar(); // Might print an arbitrary (mangled) name, "bar".
1205 * }
1206 *
1207 * For a detailed description of the parameters to the [MirrorsUsed] constructor
1208 * see the comments for [symbols], [targets], [metaTargets] and [override].
1209 *
1210 * An import of `dart:mirrors` may have multiple [MirrorsUsed] annotations. This
1211 * is particularly helpful to specify overrides for specific libraries. For
1212 * example:
1213 *
1214 * @MirrorsUsed(targets: 'foo.Bar', override: 'foo')
1215 * @MirrorsUsed(targets: 'Bar')
1216 * import 'dart:mirrors';
1217 *
1218 * will ensure that the target `Bar` from the current library and from library
1219 * `foo` is available for reflection. See also [override].
1220 */
1221 class MirrorsUsed {
1222 // Note: the fields of this class are untyped. This is because the most
1223 // convenient way to specify symbols today is using a single string. In
1224 // some cases, a const list of classes might be convenient. Some
1225 // might prefer to use a const list of symbols.
1226
1227 /**
1228 * The list of strings passed to new [Symbol], and symbols that might be
1229 * passed to [MirrorSystem.getName].
1230 *
1231 * Combined with the names of [targets], [metaTargets] and their members,
1232 * this forms the complete list of strings passed to new [Symbol], and
1233 * symbols that might be passed to [MirrorSystem.getName] by the library to
1234 * which this metadata applies.
1235 *
1236 * The following text is non-normative:
1237 *
1238 * Dart2js currently supports the following formats to specify symbols:
1239 *
1240 * * A constant [List] of [String] constants representing symbol names,
1241 * e.g., `const ['foo', 'bar']`.
1242 * * A single [String] constant whose value is a comma-separated list of
1243 * symbol names, e.g., `"foo, bar"`.
1244 *
1245 * Specifying the `symbols` field turns off the following warnings emitted by
1246 * dart2js:
1247 *
1248 * * Using "MirrorSystem.getName" may result in larger output.
1249 * * Using "new Symbol" may result in larger output.
1250 *
1251 * For example, if you're using [noSuchMethod] to interact with a database,
1252 * extract all the possible column names and include them in this list.
1253 * Similarly, if you're using [noSuchMethod] to interact with another
1254 * language (JavaScript, for example) extract all the identifiers from the
1255 * API you use and include them in this list.
1256 *
1257 * Note that specifying a symbol only ensures that the symbol will be
1258 * available under that name at runtime. It does not mark targets with
1259 * that name as available for reflection. See [targets] and [metaTargets]
1260 * for that purpose.
1261 */
1262 final symbols;
1263
1264 /**
1265 * A list of reflective targets.
1266 *
1267 * Combined with [metaTargets], this provides the complete list of reflective
1268 * targets used by the library to which this metadata applies.
1269 *
1270 * The following text is non-normative:
1271 *
1272 * For now, there is no formal description of what a reflective target is.
1273 * Informally, a target is a library, a class, a method or a field.
1274 *
1275 * Dart2js currently supports the following formats to specify targets:
1276 *
1277 * * A constant [List] containing [String] constants representing (qualified)
1278 * names of targets and Dart types.
1279 * * A single [String] constant whose value is a comma-separated list of
1280 * (qualified) names.
1281 * * A single Dart type.
1282 *
1283 * A (qualified) name is resolved to a target as follows:
1284 *
1285 * 1. If the qualified name matches a library name, the matching library is
1286 * the target.
1287 * 2. Else, find the longest prefix of the name such that the prefix ends
1288 * just before a `.` and is a library name.
1289 * 3. Use that library as current scope. If no matching prefix was found, use
1290 * the current library, i.e., the library where the [MirrorsUsed]
1291 * annotation was placed.
1292 * 4. Split the remaining suffix (the entire name if no library name was
1293 * found in step 3) into a list of [String] using `.` as a
1294 * separator.
1295 * 5. Select all targets in the current scope whose name matches a [String]
1296 * from the list.
1297 *
1298 * For example:
1299 *
1300 * library my.library.one;
1301 *
1302 * class A {
1303 * var aField;
1304 * }
1305 *
1306 * library main;
1307 *
1308 * @MirrorsUsed(targets: "my.library.one.A.aField")
1309 * import "dart:mirrors";
1310 *
1311 * The [MirrorsUsed] annotation specifies `A` and `aField` from library
1312 * `my.library.one` as targets. This will mark the class `A` as a reflective
1313 * target. The target specification for `aField` has no effect, as there is
1314 * no target in `my.library.one` with that name.
1315 *
1316 * Note that everything within a target also is available for reflection.
1317 * So, if a library is specified as target, all classes in that library
1318 * become targets for reflection. Likewise, if a class is a target, all
1319 * its methods and fields become targets for reflection. As a consequence,
1320 * `aField` in the above example is also a reflective target.
1321 *
1322 */
1323 final targets;
1324
1325 /**
1326 * A list of classes that when used as metadata indicates a reflective
1327 * target. See also [targets].
1328 *
1329 * The following text is non-normative:
1330 *
1331 * The format for specifying the list of classes is the same as used for
1332 * specifying [targets]. However, as a library cannot be used as a metadata
1333 * annotation in Dart, adding a library to the list of [metaTargets] has no
1334 * effect. In particular, adding a library to [metaTargets] does not make
1335 * the library's classes valid metadata annotations to enable reflection.
1336 *
1337 * If an instance of a class specified in [metaTargets] is used as
1338 * metadata annotation on a library, class, field or method, that library,
1339 * class, field or method is added to the set of targets for reflection.
1340 *
1341 * Example usage:
1342 *
1343 * library example;
1344 * @MirrorsUsed(metaTargets: "example.Reflectable")
1345 * import "dart:mirrors";
1346 *
1347 * class Reflectable {
1348 * const Reflectable();
1349 * }
1350 *
1351 * class Foo {
1352 * @Reflectable()
1353 * reflectableMethod() { ... }
1354 *
1355 * nonReflectableMethod() { ... }
1356 * }
1357 *
1358 * In the above example. `reflectableMethod` is marked as reflectable by
1359 * using the `Reflectable` class, which in turn is specified in the
1360 * [metaTargets] annotation.
1361 *
1362 * The method `nonReflectableMethod` lacks a metadata annotation and thus
1363 * will not be reflectable at runtime.
1364 */
1365 final metaTargets;
1366
1367 /**
1368 * A list of library names or "*".
1369 *
1370 * When used as metadata on an import of "dart:mirrors", this metadata does
1371 * not apply to the library in which the annotation is used, but instead
1372 * applies to the other libraries (all libraries if "*" is used).
1373 *
1374 * The following text is non-normative:
1375 *
1376 * Dart2js currently supports the following formats to specify libraries:
1377 *
1378 * * A constant [List] containing [String] constants representing names of
1379 * libraries.
1380 * * A single [String] constant whose value is a comma-separated list of
1381 * library names.
1382 *
1383 * Conceptually, a [MirrorsUsed] annotation with [override] has the same
1384 * effect as placing the annotation directly on the import of `dart:mirrors`
1385 * in each of the referenced libraries. Thus, if the library had no
1386 * [MirrorsUsed] annotation before, its unconditional import of
1387 * `dart:mirrors` is overridden by an annotated import.
1388 *
1389 * Note that, like multiple explicit [MirrorsUsed] annotations, using
1390 * override on a library with an existing [MirrorsUsed] annotation is
1391 * additive. That is, the overall set of reflective targets is the union
1392 * of the reflective targets that arise from the original and the
1393 * overriding [MirrorsUsed] annotations.
1394 *
1395 * The use of [override] is only meaningful for libraries that have an
1396 * import of `dart:mirrors` without annotation because otherwise it would
1397 * work exactly the same way without the [override] parameter.
1398 *
1399 * While the annotation will apply to the given target libraries, the
1400 * [symbols], [targets] and [metaTargets] are still evaluated in the
1401 * scope of the annotation. Thus, to select a target from library `foo`,
1402 * a qualified name has to be used or, if the target is visible in the
1403 * current scope, its type may be referenced.
1404 *
1405 * For example, the following code marks all targets in the library `foo`
1406 * as reflectable that have a metadata annotation using the `Reflectable`
1407 * class from the same library.
1408 *
1409 * @MirrorsUsed(metaTargets: "foo.Reflectable", override: "foo")
1410 *
1411 * However, the following code would require the use of the `Reflectable`
1412 * class from the current library, instead.
1413 *
1414 * @MirrorsUsed(metaTargets: "Reflectable", override: "foo")
1415 *
1416 */
1417 final override;
1418
1419 /**
1420 * See the documentation for [MirrorsUsed.symbols], [MirrorsUsed.targets],
1421 * [MirrorsUsed.metaTargets] and [MirrorsUsed.override] for documentation
1422 * of the parameters.
1423 */
1424 const MirrorsUsed(
1425 {this.symbols, this.targets, this.metaTargets, this.override});
1426 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/tool/input_sdk/lib/math/rectangle.dart ('k') | pkg/dev_compiler/tool/input_sdk/libraries.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698