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

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

Issue 10825431: More mirrors changes to bring vm mirrors more in line with the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // The dart:mirrors library provides reflective access for Dart program. 5 // The dart:mirrors library provides reflective access for Dart program.
6 // 6 //
7 // For the purposes of the mirrors library, we adopt a naming 7 // For the purposes of the mirrors library, we adopt a naming
8 // convention with respect to getters and setters. Specifically, for 8 // convention with respect to getters and setters. Specifically, for
9 // some variable or field... 9 // some variable or field...
10 // 10 //
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 */ 103 */
104 final bool isCurrent; 104 final bool isCurrent;
105 105
106 /** 106 /**
107 * A mirror on the root library for this isolate. 107 * A mirror on the root library for this isolate.
108 */ 108 */
109 final LibraryMirror rootLibrary; 109 final LibraryMirror rootLibrary;
110 } 110 }
111 111
112 /** 112 /**
113 * A [DeclarationMirror] reflects some entity declared in a Dart program.
114 */
115 interface DeclarationMirror extends Mirror {
116 /**
117 * The simple name for this Dart language entity.
118 *
119 * The simple name is in most cases the the identifier name of the
120 * entity, such as 'method' for a method [:void method() {...}:] or
121 * 'mylibrary' for a [:#library('mylibrary');:] declaration.
122 */
123 final String simpleName;
124
125 /**
126 * The fully-qualified name for this Dart language entity.
127 *
128 * This name is qualified by the name of the owner. For instance,
129 * the qualified name of a method 'method' in class 'Class' in
130 * library 'library' is 'library.Class.method'.
131 *
132 * TODO(turnidge): Specify whether this name is unique. Currently
133 * this is a gray area due to lack of clarity over whether library
134 * names are unique.
135 */
136 final String qualifiedName;
137
138 /**
139 * A mirror on the owner of this function. This is the declaration
140 * immediately surrounding the reflectee.
141 *
142 * Note that for libraries, the owner will be [:null:].
143 */
144 final DeclarationMirror owner;
145
146 /**
147 * Is this declaration private?
148 *
149 * Note that for libraries, this will be [:false:].
150 */
151 final bool isPrivate;
152
153 /**
154 * Is this declaration top-level?
155 *
156 * This is defined to be equivalent to:
157 * [:mirror.owner !== null && mirror.owner is LibraryMirror:]
158 */
159 final bool isTopLevel;
160
161 /**
162 * The source location of this Dart language entity.
163 */
164 final SourceLocation location;
165 }
166
167 /**
113 * An [ObjectMirror] is a common superinterface of [InstanceMirror], 168 * An [ObjectMirror] is a common superinterface of [InstanceMirror],
114 * [ClassMirror], and [LibraryMirror] that represents their shared 169 * [ClassMirror], and [LibraryMirror] that represents their shared
115 * functionality. 170 * functionality.
116 * 171 *
117 * For the purposes of the mirrors library, these types are all 172 * For the purposes of the mirrors library, these types are all
118 * object-like, in that they support method invocation and field 173 * object-like, in that they support method invocation and field
119 * access. Real Dart objects are represented by the [InstanceMirror] 174 * access. Real Dart objects are represented by the [InstanceMirror]
120 * type. 175 * type.
121 * 176 *
122 * See [InstanceMirror], [ClassMirror], and [LibraryMirror]. 177 * See [InstanceMirror], [ClassMirror], and [LibraryMirror].
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 * result is a mirror on that value. 278 * result is a mirror on that value.
224 */ 279 */
225 Future<InstanceMirror> findInContext(String name); 280 Future<InstanceMirror> findInContext(String name);
226 } 281 }
227 282
228 /** 283 /**
229 * A [LibraryMirror] reflects a Dart language library, providing 284 * A [LibraryMirror] reflects a Dart language library, providing
230 * access to the variables, functions, classes, and interfaces of the 285 * access to the variables, functions, classes, and interfaces of the
231 * library. 286 * library.
232 */ 287 */
233 interface LibraryMirror extends ObjectMirror { 288 interface LibraryMirror extends DeclarationMirror, ObjectMirror {
234 /**
235 * The name of this library, as provided in the [#library] declaration.
236 */
237 final String simpleName;
238
239 /** 289 /**
240 * The url of the library. 290 * The url of the library.
241 * 291 *
242 * TODO(turnidge): Document where this url comes from. Will this 292 * TODO(turnidge): Document where this url comes from. Will this
243 * value be sensible? 293 * value be sensible?
244 */ 294 */
245 final String url; 295 final String url;
246 296
247 /** 297 /**
248 * An immutable map from from names to mirrors for all members in 298 * An immutable map from from names to mirrors for all members in
249 * this library. 299 * this library.
250 * 300 *
251 * The members of a library are its top-level classes, interfaces, 301 * The members of a library are its top-level classes, interfaces,
252 * functions, variables, getters, and setters. 302 * functions, variables, getters, and setters.
253 */ 303 */
254 final Map<String, Mirror> members; 304 final Map<String, Mirror> members;
255 305
256 /** 306 /**
257 * An immutable map from names to mirrors for all class and 307 * An immutable map from names to mirrors for all class and
258 * interface declarations in this library. 308 * interface declarations in this library.
259 */ 309 */
260 final Map<String, ClassMirror> classes; 310 final Map<String, ClassMirror> classes;
261 311
262 /** 312 /**
263 * An immutable map from names to mirrors for all function 313 * An immutable map from names to mirrors for all function, getter,
314 * and setter declarations in this library.
315 */
316 final Map<String, MethodMirror> functions;
317
318 /**
319 * An immutable map from names to mirrors for all getter
264 * declarations in this library. 320 * declarations in this library.
265 */ 321 */
266 final Map<String, MethodMirror> functions; 322 final Map<String, MethodMirror> getters;
323
324 /**
325 * An immutable map from names to mirrors for all setter
326 * declarations in this library.
327 */
328 final Map<String, MethodMirror> setters;
267 329
268 /** 330 /**
269 * An immutable map from names to mirrors for all variable 331 * An immutable map from names to mirrors for all variable
270 * declarations in this library. 332 * declarations in this library.
271 */ 333 */
272 final Map<String, VariableMirror> variables; 334 final Map<String, VariableMirror> variables;
273 } 335 }
274 336
275 /** 337 /**
276 * A [TypeMirror] reflects a Dart language class, interface, typedef 338 * A [TypeMirror] reflects a Dart language class, interface, typedef
277 * or type variable. 339 * or type variable.
278 */ 340 */
279 interface TypeMirror extends Mirror { 341 interface TypeMirror extends DeclarationMirror {
280 /**
281 * The library in which this interface is declared.
282 */
283 final LibraryMirror library;
284 } 342 }
285 343
286 /** 344 /**
287 * A [ClassMirror] reflects a Dart language class or interface. 345 * A [ClassMirror] reflects a Dart language class or interface.
288 */ 346 */
289 interface ClassMirror extends TypeMirror, ObjectMirror { 347 interface ClassMirror extends TypeMirror, ObjectMirror {
290 /** 348 /**
291 * The name of this interface. 349 * A mirror on the superclass on the reflectee.
292 */
293 final String simpleName;
294
295 /**
296 * Does this mirror represent a class?
297 */
298 final bool isClass;
299
300 /**
301 * Returns a mirror on the superclass on the reflectee.
302 * 350 *
303 * For interfaces, the superclass is Object. 351 * If this type is [:Object:] or a typedef, the superClass will be
352 * null. For interfaces, the superclass is Object.
304 */ 353 */
305 final ClassMirror superclass; 354 final ClassMirror superclass;
306 355
307 /** 356 /**
308 * Returns a list of mirrors on the superinterfaces for the reflectee. 357 * A list of mirrors on the superinterfaces of the reflectee.
309 */ 358 */
310 final List<ClassMirror> superinterfaces; 359 final List<ClassMirror> superinterfaces;
311 360
312 /** 361 /**
313 * Returns a mirror on the default factory class or null if there is
314 * none.
315 */
316 final ClassMirror defaultFactory;
317
318 /**
319 * An immutable map from from names to mirrors for all members of 362 * An immutable map from from names to mirrors for all members of
320 * this type. 363 * this type.
321 * 364 *
322 * The members of an interface are its constructors, methods, 365 * The members of an interface are its constructors, methods,
323 * fields, getters, and setters. 366 * fields, getters, and setters.
324 * 367 *
325 * This does not include inherited members. 368 * This does not include inherited members.
326 */ 369 */
327 final Map<String, Mirror> members; 370 final Map<String, Mirror> members;
328 371
329 /** 372 /**
330 * An immutable map from names to mirrors for all method, 373 * An immutable map from names to mirrors for all method,
331 * constructor, getter, and setter declarations in this library. 374 * constructor, getter, and setter declarations for this type.
332 */ 375 */
333 final Map<String, MethodMirror> methods; 376 final Map<String, MethodMirror> methods;
334 377
335 /** 378 /**
379 * An immutable map from names to mirrors for all constructor
380 * declarations for this type.
381 */
382 final Map<String, MethodMirror> constructors;
383
384 /**
385 * An immutable map from names to mirrors for all getter
386 * declarations for this type.
387 */
388 final Map<String, MethodMirror> getters;
389
390 /**
391 * An immutable map from names to mirrors for all setter
392 * declarations for this type.
393 */
394 final Map<String, MethodMirror> setters;
395
396 /**
336 * An immutable map from names to mirrors for all variable 397 * An immutable map from names to mirrors for all variable
337 * declarations in this library. 398 * declarations for this type.
338 */ 399 */
339 final Map<String, VariableMirror> variables; 400 final Map<String, VariableMirror> variables;
340 401
341 /** 402 /**
403 * A list of type variables for this type.
404 */
405 final List<TypeVariableMirror> typeVariables;
406
407 /**
408 * A list of the type arguments for this type.
409 */
410 final List<TypeMirror> typeArguments;
411
412 /**
413 * Is this the original declaration of this type?
414 *
415 * For most classes, they are their own original declaration. For
416 * generic classes, however, there is a distinction between the
417 * original class declaration, which has unbound type variables, and
418 * the instantiations of generic classes, which have bound type
419 * variables.
420 */
421 final bool isOriginalDeclaration;
422
423 /**
424 * A mirror on the original declaration of this type.
425 *
426 * For most classes, they are their own original declaration. For
427 * generic classes, however, there is a distinction between the
428 * original class declaration, which has unbound type variables, and
429 * the instantiations of generic classes, which have bound type
430 * variables.
431 */
432 final ClassMirror originalDeclaration;
433
434 /**
342 * Invokes the named constructor and returns a mirror on the result. 435 * Invokes the named constructor and returns a mirror on the result.
343 * 436 *
344 * TODO(turnidge): Properly document. 437 * TODO(turnidge): Properly document.
345 */ 438 */
346 Future<InstanceMirror> newInstance(String constructorName, 439 Future<InstanceMirror> newInstance(String constructorName,
347 List<Object> positionalArguments, 440 List<Object> positionalArguments,
348 [Map<String,Object> namedArguments]); 441 [Map<String,Object> namedArguments]);
442
443 /**
444 * Does this mirror represent a class?
445 *
446 * TODO(turnidge): This functions goes away after the
447 * class/interface changes.
448 */
449 final bool isClass;
450
451 /**
452 * A mirror on the default factory class or null if there is none.
453 *
454 * TODO(turnidge): This functions goes away after the
455 * class/interface changes.
456 */
457 final ClassMirror defaultFactory;
458 }
459
460 /**
461 * A [TypeVariableMirror] represents a type parameter of a generic
462 * type.
463 */
464 interface TypeVariableMirror extends TypeMirror {
465 /**
466 * A mirror on the type that is the upper bound for this type variable.
467 */
468 final TypeMirror upperBound;
469 }
470
471 /**
472 * A [FunctionTypeMirror] represents the type of a function in the
473 * Dart language.
474 */
475 interface FunctionTypeMirror extends TypeMirror {
476 /**
477 * The return type of the reflectee.
478 */
479 final TypeMirror returnType;
480
481 /**
482 * A list of the parameter types of the reflectee.
483 */
484 final List<ParameterMirror> parameters;
485
486 /**
487 * A mirror on the [:call:] method for the reflectee.
488 *
489 * TODO(turnidge): What is this and what is it for?
490 */
491 final MethodMirror callMethod;
492 }
493
494 /**
495 * A [TypedefMirror] represents a typedef in a Dart language program.
496 */
497 interface TypedefMirror extends ClassMirror {
498 /**
499 * The defining type for this typedef.
500 *
501 * For instance [:void f(int):] is the value for [:typedef void f(int):].
502 */
503 final TypeMirror value;
349 } 504 }
350 505
351 /** 506 /**
352 * A [MethodMirror] reflects a Dart language function, method, 507 * A [MethodMirror] reflects a Dart language function, method,
353 * constructor, getter, or setter. 508 * constructor, getter, or setter.
354 */ 509 */
355 interface MethodMirror { 510 interface MethodMirror extends DeclarationMirror {
356 /** 511 /**
357 * The name of this function. 512 * A mirror on the return type for the reflectee.
358 */ 513 */
359 final String simpleName; 514 final TypeMirror returnType;
360 515
361 /** 516 /**
362 * A mirror on the owner of this function. This is the declaration 517 * A list of mirrors on the parameters for the reflectee.
363 * immediately surrounding the reflectee.
364 *
365 * For top-level functions, this will be a [LibraryMirror] and for
366 * methods, constructors, getters, and setters, this will be an
367 * [ClassMirror].
368 */
369 final Mirror owner;
370
371 /**
372 * Returns the list of parameters for this method.
373 */ 518 */
374 final List<ParameterMirror> parameters; 519 final List<ParameterMirror> parameters;
375 520
376 // Ownership 521 /**
377 522 * Is the reflectee static?
378 /**
379 * Does this mirror reflect a top-level function?
380 */
381 final bool isTopLevel;
382
383 /**
384 * Does this mirror reflect a static method?
385 * 523 *
386 * For the purposes of the mirrors library, a top-level function is 524 * For the purposes of the mirrors library, a top-level function is
387 * considered static. 525 * considered static.
388 */ 526 */
389 final bool isStatic; 527 final bool isStatic;
390 528
391 // Method kind 529 /**
392 530 * Is the reflectee abstract?
393 /**
394 * Does this mirror reflect a regular function or method?
395 *
396 * A method is regular if it is not a getter, setter, or constructor.
397 */
398 final bool isMethod;
399
400 /**
401 * Does this mirror reflect an abstract method?
402 */ 531 */
403 final bool isAbstract; 532 final bool isAbstract;
404 533
405 /** 534 /**
406 * Does this mirror reflect a getter? 535 * Is the reflectee a regular function or method?
536 *
537 * A function or method is regular if it is not a getter, setter, or
538 * constructor. Note that operators, by this definition, are
539 * regular methods.
540 */
541 final bool isRegularMethod;
542
543 /**
544 * Is the reflectee an operator?
545 */
546 final bool isOperator;
547
548 /**
549 * Is the reflectee a getter?
407 */ 550 */
408 final bool isGetter; 551 final bool isGetter;
409 552
410 /** 553 /**
411 * Does this mirror reflect a setter? 554 * Is the reflectee a setter?
412 */ 555 */
413 final bool isSetter; 556 final bool isSetter;
414 557
415 /** 558 /**
416 * Does this mirror reflect a constructor? 559 * Is the reflectee a constructor?
417 */ 560 */
418 final bool isConstructor; 561 final bool isConstructor;
419 562
420 // Constructor kind 563 /**
421 564 * The constructor name for named constructors and factory methods.
422 /** 565 *
423 * Does this mirror reflect a const constructor? 566 * For unnamed constructors, this is the empty string. For
567 * non-constructors, this is the empty string.
568 *
569 * For example, [:'bar':] is the constructor name for constructor
570 * [:Foo.bar:] of type [:Foo:].
571 */
572 final String constructorName;
573
574 /**
575 * Is the reflectee a const constructor?
424 */ 576 */
425 final bool isConstConstructor; 577 final bool isConstConstructor;
426 578
427 /** 579 /**
428 * Does this mirror reflect a generative constructor? 580 * Is the reflectee a generative constructor?
429 */ 581 */
430 final bool isGenerativeConstructor; 582 final bool isGenerativeConstructor;
431 583
432 /** 584 /**
433 * Does this mirror reflect a redirecting constructor? 585 * Is the reflectee a redirecting constructor?
434 */ 586 */
435 final bool isRedirectingConstructor; 587 final bool isRedirectingConstructor;
436 588
437 /** 589 /**
438 * Does this mirror reflect a factory constructor? 590 * Is the reflectee a factory constructor?
439 */ 591 */
440 final bool isFactoryConstructor; 592 final bool isFactoryConstructor;
441 } 593 }
442 594
443 /** 595 /**
444 * A [VariableMirror] reflects a Dart language variable declaration. 596 * A [VariableMirror] reflects a Dart language variable declaration.
445 */ 597 */
446 interface VariableMirror { 598 interface VariableMirror extends DeclarationMirror {
447 /** 599 /**
448 * The name of this variable 600 * A mirror on the type of the reflectee.
449 */ 601 */
450 final String simpleName; 602 final TypeMirror type;
451 603
452 /** 604 /**
453 * A mirror on the owner of this method. The owner is the 605 * Is the reflectee a static variable?
454 * declaration immediately surrounding the reflectee.
455 *
456 * For top-level variables, this will be a [LibraryMirror] and for
457 * class and interface variables, this will be a [ClassMirror].
458 */
459 final Mirror owner;
460
461 /**
462 * Does this mirror reflect a top-level variable?
463 */
464 final bool isTopLevel;
465
466 /**
467 * Does this mirror reflect a static variable?
468 * 606 *
469 * For the purposes of the mirror library, top-level variables are 607 * For the purposes of the mirror library, top-level variables are
470 * implicitly declared static. 608 * implicitly declared static.
471 */ 609 */
472 final bool isStatic; 610 final bool isStatic;
473 611
474 /** 612 /**
475 * Does this mirror reflect a final variable? 613 * Is the reflectee a final variable?
476 */ 614 */
477 final bool isFinal; 615 final bool isFinal;
478 } 616 }
479 617
480 /** 618 /**
481 * A [ParameterMirror] reflects a Dart formal parameter declaration. 619 * A [ParameterMirror] reflects a Dart formal parameter declaration.
482 */ 620 */
483 interface ParameterMirror extends VariableMirror { 621 interface ParameterMirror extends VariableMirror {
484 /** 622 /**
485 * Returns the type of this parameter. 623 * A mirror on the type of this parameter.
486 */ 624 */
487 final TypeMirror type; 625 final TypeMirror type;
488 626
489 /** 627 /**
490 * Returns the default value for this parameter. 628 * Is this parameter optional?
491 */ 629 */
492 final String defaultValue; 630 final bool isOptional;
493 631
494 /** 632 /**
495 * Returns true if this parameter has a default value. 633 * Is this parameter named?
634 */
635 final bool isNamed;
636
637 /**
638 * Does this parameter have a default value?
496 */ 639 */
497 final bool hasDefaultValue; 640 final bool hasDefaultValue;
498 641
499 /** 642 /**
500 * Returns true if this parameter is optional. 643 * A mirror on the default value for this parameter, if it exists.
644 *
645 * TODO(turnidge): String may not be a good representation of this
646 * at runtime.
501 */ 647 */
502 final bool isOptional; 648 final String defaultValue;
649 }
650
651 /**
652 * A [SourceLocation] describes the span of an entity in Dart source code.
653 */
654 interface SourceLocation {
503 } 655 }
504 656
505 /** 657 /**
506 * When an error occurs during the mirrored execution of code, a 658 * When an error occurs during the mirrored execution of code, a
507 * [MirroredError] is thrown. 659 * [MirroredError] is thrown.
508 * 660 *
509 * In general, there are three main classes of failure that can happen 661 * In general, there are three main classes of failure that can happen
510 * during mirrored execution of code in some isolate: 662 * during mirrored execution of code in some isolate:
511 * 663 *
512 * - An exception is thrown but not caught. This is caught by the 664 * - An exception is thrown but not caught. This is caught by the
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 728
577 /** 729 /**
578 * A [MirrorException] is used to indicate errors within the mirrors 730 * A [MirrorException] is used to indicate errors within the mirrors
579 * framework. 731 * framework.
580 */ 732 */
581 class MirrorException implements Exception { 733 class MirrorException implements Exception {
582 const MirrorException(String this._message); 734 const MirrorException(String this._message);
583 String toString() => "MirrorException: '$_message'"; 735 String toString() => "MirrorException: '$_message'";
584 final String _message; 736 final String _message;
585 } 737 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698