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

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

Issue 11434030: Revert "Switch libraries to using new tags." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/math/random.dart ('k') | sdk/lib/mirrors/mirrors.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Commented out until supported by VM.
6 // part of dart_mirrors;
7
8 // For the purposes of the mirrors library, we adopt a naming
9 // convention with respect to getters and setters. Specifically, for
10 // some variable or field...
11 //
12 // var myField;
13 //
14 // ...the getter is named 'myField' and the setter is named
15 // 'myField='. This allows us to assign unique names to getters and
16 // setters for the purposes of member lookup.
17
18 /**
19 * A [MirrorSystem] is the main interface used to reflect on a set of
20 * associated libraries.
21 *
22 * At runtime each running isolate has a distinct [MirrorSystem].
23 *
24 * It is also possible to have a [MirrorSystem] which represents a set
25 * of libraries which are not running -- perhaps at compile-time. In
26 * this case, all available reflective functionality would be
27 * supported, but runtime functionality (such as invoking a function
28 * or inspecting the contents of a variable) would fail dynamically.
29 */
30 abstract class MirrorSystem {
31 /**
32 * An immutable map from from library names to mirrors for all
33 * libraries known to this mirror system.
34 */
35 Map<String, LibraryMirror> get libraries;
36
37 /**
38 * A mirror on the isolate associated with this [MirrorSystem].
39 * This may be null if this mirror system is not running.
40 */
41 IsolateMirror get isolate;
42
43 /**
44 * A mirror on the [:dynamic:] type.
45 */
46 TypeMirror get dynamicType;
47
48 /**
49 * A mirror on the [:void:] type.
50 */
51 TypeMirror get voidType;
52 }
53
54 /**
55 * Returns a [MirrorSystem] for the current isolate.
56 */
57 MirrorSystem currentMirrorSystem() {
58 return _Mirrors.currentMirrorSystem();
59 }
60
61 /**
62 * Creates a [MirrorSystem] for the isolate which is listening on
63 * the [SendPort].
64 */
65 Future<MirrorSystem> mirrorSystemOf(SendPort port) {
66 return _Mirrors.mirrorSystemOf(port);
67 }
68
69 /**
70 * Returns an [InstanceMirror] for some Dart language object.
71 *
72 * This only works if this mirror system is associated with the
73 * current running isolate.
74 */
75 InstanceMirror reflect(Object reflectee) {
76 return _Mirrors.reflect(reflectee);
77 }
78
79 /**
80 * A [Mirror] reflects some Dart language entity.
81 *
82 * Every [Mirror] originates from some [MirrorSystem].
83 */
84 abstract class Mirror {
85 /**
86 * The [MirrorSystem] that contains this mirror.
87 */
88 MirrorSystem get mirrors;
89 }
90
91 /**
92 * An [IsolateMirror] reflects an isolate.
93 */
94 abstract class IsolateMirror implements Mirror {
95 /**
96 * A unique name used to refer to an isolate in debugging messages.
97 */
98 String get debugName;
99
100 /**
101 * Does this mirror reflect the currently running isolate?
102 */
103 bool get isCurrent;
104
105 /**
106 * A mirror on the root library for this isolate.
107 */
108 LibraryMirror get rootLibrary;
109 }
110
111 /**
112 * A [DeclarationMirror] reflects some entity declared in a Dart program.
113 */
114 abstract class DeclarationMirror implements Mirror {
115 /**
116 * The simple name for this Dart language entity.
117 *
118 * The simple name is in most cases the the identifier name of the
119 * entity, such as 'method' for a method [:void method() {...}:] or
120 * 'mylibrary' for a [:#library('mylibrary');:] declaration.
121 */
122 String get simpleName;
123
124 /**
125 * The fully-qualified name for this Dart language entity.
126 *
127 * This name is qualified by the name of the owner. For instance,
128 * the qualified name of a method 'method' in class 'Class' in
129 * library 'library' is 'library.Class.method'.
130 *
131 * TODO(turnidge): Specify whether this name is unique. Currently
132 * this is a gray area due to lack of clarity over whether library
133 * names are unique.
134 */
135 String get qualifiedName;
136
137 /**
138 * A mirror on the owner of this function. This is the declaration
139 * immediately surrounding the reflectee.
140 *
141 * Note that for libraries, the owner will be [:null:].
142 */
143 DeclarationMirror get owner;
144
145 /**
146 * Is this declaration private?
147 *
148 * Note that for libraries, this will be [:false:].
149 */
150 bool get isPrivate;
151
152 /**
153 * Is this declaration top-level?
154 *
155 * This is defined to be equivalent to:
156 * [:mirror.owner != null && mirror.owner is LibraryMirror:]
157 */
158 bool get isTopLevel;
159
160 /**
161 * The source location of this Dart language entity.
162 */
163 SourceLocation get location;
164 }
165
166 /**
167 * An [ObjectMirror] is a common superinterface of [InstanceMirror],
168 * [ClassMirror], and [LibraryMirror] that represents their shared
169 * functionality.
170 *
171 * For the purposes of the mirrors library, these types are all
172 * object-like, in that they support method invocation and field
173 * access. Real Dart objects are represented by the [InstanceMirror]
174 * type.
175 *
176 * See [InstanceMirror], [ClassMirror], and [LibraryMirror].
177 */
178 abstract class ObjectMirror implements Mirror {
179 /**
180 * Invokes the named function and returns a mirror on the result.
181 *
182 * TODO(turnidge): Properly document.
183 * TODO(turnidge): Handle ambiguous names.
184 * TODO(turnidge): Handle optional & named arguments.
185 */
186 Future<InstanceMirror> invoke(String memberName,
187 List<Object> positionalArguments,
188 [Map<String,Object> namedArguments]);
189
190 /**
191 * Invokes a getter and returns a mirror on the result. The getter
192 * can be the implicit getter for a field or a user-defined getter
193 * method.
194 *
195 * TODO(turnidge): Handle ambiguous names.
196 */
197 Future<InstanceMirror> getField(String fieldName);
198
199 /**
200 * Invokes a setter and returns a mirror on the result. The setter
201 * may be either the implicit setter for a non-final field or a
202 * user-defined setter method.
203 *
204 * TODO(turnidge): Handle ambiguous names.
205 */
206 Future<InstanceMirror> setField(String fieldName, Object value);
207 }
208
209 /**
210 * An [InstanceMirror] reflects an instance of a Dart language object.
211 */
212 abstract class InstanceMirror implements ObjectMirror {
213 /**
214 * A mirror on the type of the reflectee.
215 */
216 ClassMirror get type;
217
218 /**
219 * Does [reflectee] contain the instance reflected by this mirror?
220 * This will always be true in the local case (reflecting instances
221 * in the same isolate), but only true in the remote case if this
222 * mirror reflects a simple value.
223 *
224 * A value is simple if one of the following holds:
225 * - the value is null
226 * - the value is of type [num]
227 * - the value is of type [bool]
228 * - the value is of type [String]
229 */
230 bool get hasReflectee;
231
232 /**
233 * If the [InstanceMirror] reflects an instance it is meaningful to
234 * have a local reference to, we provide access to the actual
235 * instance here.
236 *
237 * If you access [reflectee] when [hasReflectee] is false, an
238 * exception is thrown.
239 */
240 get reflectee;
241 }
242
243 /**
244 * A [ClosureMirror] reflects a closure.
245 *
246 * A [ClosureMirror] provides access to its captured variables and
247 * provides the ability to execute its reflectee.
248 */
249 abstract class ClosureMirror implements InstanceMirror {
250 /**
251 * A mirror on the function associated with this closure.
252 */
253 MethodMirror get function;
254
255 /**
256 * The source code for this closure, if available. Otherwise null.
257 *
258 * TODO(turnidge): Would this just be available in function?
259 */
260 String get source;
261
262 /**
263 * Executes the closure. The arguments given in the descriptor need to
264 * be InstanceMirrors or simple values.
265 *
266 * A value is simple if one of the following holds:
267 * - the value is null
268 * - the value is of type [num]
269 * - the value is of type [bool]
270 * - the value is of type [String]
271 */
272 Future<InstanceMirror> apply(List<Object> positionalArguments,
273 [Map<String,Object> namedArguments]);
274
275 /**
276 * Looks up the value of a name in the scope of the closure. The
277 * result is a mirror on that value.
278 */
279 Future<InstanceMirror> findInContext(String name);
280 }
281
282 /**
283 * A [LibraryMirror] reflects a Dart language library, providing
284 * access to the variables, functions, and classes of the
285 * library.
286 */
287 abstract class LibraryMirror implements DeclarationMirror, ObjectMirror {
288 /**
289 * The url of the library.
290 *
291 * TODO(turnidge): Document where this url comes from. Will this
292 * value be sensible?
293 */
294 String get url;
295
296 /**
297 * An immutable map from from names to mirrors for all members in
298 * this library.
299 *
300 * The members of a library are its top-level classes,
301 * functions, variables, getters, and setters.
302 */
303 Map<String, Mirror> get members;
304
305 /**
306 * An immutable map from names to mirrors for all class
307 * declarations in this library.
308 */
309 Map<String, ClassMirror> get classes;
310
311 /**
312 * An immutable map from names to mirrors for all function, getter,
313 * and setter declarations in this library.
314 */
315 Map<String, MethodMirror> get functions;
316
317 /**
318 * An immutable map from names to mirrors for all getter
319 * declarations in this library.
320 */
321 Map<String, MethodMirror> get getters;
322
323 /**
324 * An immutable map from names to mirrors for all setter
325 * declarations in this library.
326 */
327 Map<String, MethodMirror> get setters;
328
329 /**
330 * An immutable map from names to mirrors for all variable
331 * declarations in this library.
332 */
333 Map<String, VariableMirror> get variables;
334 }
335
336 /**
337 * A [TypeMirror] reflects a Dart language class, typedef
338 * or type variable.
339 */
340 abstract class TypeMirror implements DeclarationMirror {
341 }
342
343 /**
344 * A [ClassMirror] reflects a Dart language class.
345 */
346 abstract class ClassMirror implements TypeMirror, ObjectMirror {
347 /**
348 * A mirror on the superclass on the reflectee.
349 *
350 * If this type is [:Object:] or a typedef, the superClass will be
351 * null.
352 */
353 ClassMirror get superclass;
354
355 /**
356 * A list of mirrors on the superinterfaces of the reflectee.
357 */
358 List<ClassMirror> get superinterfaces;
359
360 /**
361 * An immutable map from from names to mirrors for all members of
362 * this type.
363 *
364 * The members of a type are its methods, fields, getters, and
365 * setters. Note that constructors and type variables are not
366 * considered to be members of a type.
367 *
368 * This does not include inherited members.
369 */
370 Map<String, Mirror> get members;
371
372 /**
373 * An immutable map from names to mirrors for all method,
374 * declarations for this type. This does not include getters and
375 * setters.
376 */
377 Map<String, MethodMirror> get methods;
378
379 /**
380 * An immutable map from names to mirrors for all getter
381 * declarations for this type.
382 */
383 Map<String, MethodMirror> get getters;
384
385 /**
386 * An immutable map from names to mirrors for all setter
387 * declarations for this type.
388 */
389 Map<String, MethodMirror> get setters;
390
391 /**
392 * An immutable map from names to mirrors for all variable
393 * declarations for this type.
394 */
395 Map<String, VariableMirror> get variables;
396
397 /**
398 * An immutable map from names to mirrors for all constructor
399 * declarations for this type.
400 */
401 Map<String, MethodMirror> get constructors;
402
403 /**
404 * An immutable map from names to mirrors for all type variables for
405 * this type.
406 *
407 * This map preserves the order of declaration of the type variables.
408 */
409 Map<String, TypeVariableMirror> get typeVariables;
410
411 /**
412 * An immutable map from names to mirrors for all type arguments for
413 * this type.
414 *
415 * This map preserves the order of declaration of the type variables.
416 */
417 Map<String, TypeMirror> get typeArguments;
418
419 /**
420 * Is this the original declaration of this type?
421 *
422 * For most classes, they are their own original declaration. For
423 * generic classes, however, there is a distinction between the
424 * original class declaration, which has unbound type variables, and
425 * the instantiations of generic classes, which have bound type
426 * variables.
427 */
428 bool get isOriginalDeclaration;
429
430 /**
431 * A mirror on the original declaration of this type.
432 *
433 * For most classes, they are their own original declaration. For
434 * generic classes, however, there is a distinction between the
435 * original class declaration, which has unbound type variables, and
436 * the instantiations of generic classes, which have bound type
437 * variables.
438 */
439 ClassMirror get originalDeclaration;
440
441 /**
442 * Invokes the named constructor and returns a mirror on the result.
443 *
444 * TODO(turnidge): Properly document.
445 */
446 Future<InstanceMirror> newInstance(String constructorName,
447 List<Object> positionalArguments,
448 [Map<String,Object> namedArguments]);
449
450 /**
451 * Does this mirror represent a class?
452 *
453 * TODO(turnidge): This functions goes away after the
454 * class/interface changes.
455 */
456 bool get isClass;
457
458 /**
459 * A mirror on the default factory class or null if there is none.
460 *
461 * TODO(turnidge): This functions goes away after the
462 * class/interface changes.
463 */
464 ClassMirror get defaultFactory;
465 }
466
467 /**
468 * A [FunctionTypeMirror] represents the type of a function in the
469 * Dart language.
470 */
471 abstract class FunctionTypeMirror implements ClassMirror {
472 /**
473 * The return type of the reflectee.
474 */
475 TypeMirror get returnType;
476
477 /**
478 * A list of the parameter types of the reflectee.
479 */
480 List<ParameterMirror> get parameters;
481
482 /**
483 * A mirror on the [:call:] method for the reflectee.
484 *
485 * TODO(turnidge): What is this and what is it for?
486 */
487 MethodMirror get callMethod;
488 }
489
490 /**
491 * A [TypeVariableMirror] represents a type parameter of a generic
492 * type.
493 */
494 abstract class TypeVariableMirror extends TypeMirror {
495 /**
496 * A mirror on the type that is the upper bound of this type variable.
497 */
498 TypeMirror get upperBound;
499 }
500
501 /**
502 * A [TypedefMirror] represents a typedef in a Dart language program.
503 */
504 abstract class TypedefMirror implements ClassMirror {
505 /**
506 * The defining type for this typedef.
507 *
508 * For instance [:void f(int):] is the value for [:typedef void f(int):].
509 */
510 TypeMirror get value;
511 }
512
513 /**
514 * A [MethodMirror] reflects a Dart language function, method,
515 * constructor, getter, or setter.
516 */
517 abstract class MethodMirror implements DeclarationMirror {
518 /**
519 * A mirror on the return type for the reflectee.
520 */
521 TypeMirror get returnType;
522
523 /**
524 * A list of mirrors on the parameters for the reflectee.
525 */
526 List<ParameterMirror> get parameters;
527
528 /**
529 * Is the reflectee static?
530 *
531 * For the purposes of the mirrors library, a top-level function is
532 * considered static.
533 */
534 bool get isStatic;
535
536 /**
537 * Is the reflectee abstract?
538 */
539 bool get isAbstract;
540
541 /**
542 * Is the reflectee a regular function or method?
543 *
544 * A function or method is regular if it is not a getter, setter, or
545 * constructor. Note that operators, by this definition, are
546 * regular methods.
547 */
548 bool get isRegularMethod;
549
550 /**
551 * Is the reflectee an operator?
552 */
553 bool get isOperator;
554
555 /**
556 * Is the reflectee a getter?
557 */
558 bool get isGetter;
559
560 /**
561 * Is the reflectee a setter?
562 */
563 bool get isSetter;
564
565 /**
566 * Is the reflectee a constructor?
567 */
568 bool get isConstructor;
569
570 /**
571 * The constructor name for named constructors and factory methods.
572 *
573 * For unnamed constructors, this is the empty string. For
574 * non-constructors, this is the empty string.
575 *
576 * For example, [:'bar':] is the constructor name for constructor
577 * [:Foo.bar:] of type [:Foo:].
578 */
579 String get constructorName;
580
581 /**
582 * Is the reflectee a const constructor?
583 */
584 bool get isConstConstructor;
585
586 /**
587 * Is the reflectee a generative constructor?
588 */
589 bool get isGenerativeConstructor;
590
591 /**
592 * Is the reflectee a redirecting constructor?
593 */
594 bool get isRedirectingConstructor;
595
596 /**
597 * Is the reflectee a factory constructor?
598 */
599 bool get isFactoryConstructor;
600 }
601
602 /**
603 * A [VariableMirror] reflects a Dart language variable declaration.
604 */
605 abstract class VariableMirror implements DeclarationMirror {
606 /**
607 * A mirror on the type of the reflectee.
608 */
609 TypeMirror get type;
610
611 /**
612 * Is the reflectee a static variable?
613 *
614 * For the purposes of the mirror library, top-level variables are
615 * implicitly declared static.
616 */
617 bool get isStatic;
618
619 /**
620 * Is the reflectee a final variable?
621 */
622 bool get isFinal;
623 }
624
625 /**
626 * A [ParameterMirror] reflects a Dart formal parameter declaration.
627 */
628 abstract class ParameterMirror implements VariableMirror {
629 /**
630 * A mirror on the type of this parameter.
631 */
632 TypeMirror get type;
633
634 /**
635 * Is this parameter optional?
636 */
637 bool get isOptional;
638
639 /**
640 * Is this parameter named?
641 */
642 bool get isNamed;
643
644 /**
645 * Does this parameter have a default value?
646 */
647 bool get hasDefaultValue;
648
649 /**
650 * A mirror on the default value for this parameter, if it exists.
651 *
652 * TODO(turnidge): String may not be a good representation of this
653 * at runtime.
654 */
655 String get defaultValue;
656 }
657
658 /**
659 * A [SourceLocation] describes the span of an entity in Dart source code.
660 */
661 abstract class SourceLocation {
662 }
663
664 /**
665 * When an error occurs during the mirrored execution of code, a
666 * [MirroredError] is thrown.
667 *
668 * In general, there are three main classes of failure that can happen
669 * during mirrored execution of code in some isolate:
670 *
671 * - An exception is thrown but not caught. This is caught by the
672 * mirrors framework and a [MirroredUncaughtExceptionError] is
673 * created and thrown.
674 *
675 * - A compile-time error occurs, such as a syntax error. This is
676 * suppressed by the mirrors framework and a
677 * [MirroredCompilationError] is created and thrown.
678 *
679 * - A truly fatal error occurs, causing the isolate to be exited. If
680 * the reflector and reflectee share the same isolate, then they
681 * will both suffer. If the reflector and reflectee are in distinct
682 * isolates, then we hope to provide some information about the
683 * isolate death, but this has yet to be implemented.
684 *
685 * TODO(turnidge): Specify the behavior for remote fatal errors.
686 */
687 abstract class MirroredError implements Exception {
688 }
689
690 /**
691 * When an uncaught exception occurs during the mirrored execution
692 * of code, a [MirroredUncaughtExceptionError] is thrown.
693 *
694 * This exception contains a mirror on the original exception object.
695 * It also contains an object which can be used to recover the
696 * stacktrace.
697 */
698 class MirroredUncaughtExceptionError extends MirroredError {
699 MirroredUncaughtExceptionError(this.exception_mirror,
700 this.exception_string,
701 this.stacktrace) {}
702
703 /** A mirror on the exception object. */
704 final InstanceMirror exception_mirror;
705
706 /** The result of toString() for the exception object. */
707 final String exception_string;
708
709 /** A stacktrace object for the uncaught exception. */
710 final Object stacktrace;
711
712 String toString() {
713 return
714 "Uncaught exception during mirrored execution: <${exception_string}>";
715 }
716 }
717
718 /**
719 * When a compile-time error occurs during the mirrored execution
720 * of code, a [MirroredCompilationError] is thrown.
721 *
722 * This exception includes the compile-time error message that would
723 * have been displayed to the user, if the function had not been
724 * invoked via mirror.
725 */
726 class MirroredCompilationError extends MirroredError {
727 MirroredCompilationError(this.message) {}
728
729 final String message;
730
731 String toString() {
732 return "Compile-time error during mirrored execution: <$message>";
733 }
734 }
735
736 /**
737 * A [MirrorException] is used to indicate errors within the mirrors
738 * framework.
739 */
740 class MirrorException implements Exception {
741 const MirrorException(String this._message);
742 String toString() => "MirrorException: '$_message'";
743 final String _message;
744 }
OLDNEW
« no previous file with comments | « sdk/lib/math/random.dart ('k') | sdk/lib/mirrors/mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698