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

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') | runtime/lib/mirrors_impl.dart » ('J')
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
cshapiro 2012/08/21 03:16:05 could call this (and above) mapping to get rid of
turnidge 2012/08/21 18:00:49 Since the type is listed below, I'm not sure if th
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 * Are the generic type variables for this type unbound?
414 */
415 final bool isUnboundType;
cshapiro 2012/08/21 03:16:05 isGenericDeclaration or isDefinition
turnidge 2012/08/21 18:00:49 Choosing isGenericDeclaration for now.
416
417 /**
418 * A mirror on this type but with unbound type variables.
419 *
420 * This allows us to go from a particular parametrization of a type
421 * to its generic declaration.
422 *
423 * TODO(turnidge): Is a non-generic class its own unboundType?
424 */
425 final ClassMirror unboundType;
cshapiro 2012/08/21 03:16:05 The verbiage in the comments seems better than the
turnidge 2012/08/21 18:00:49 I'm changing it to genericDeclaration for now.
426
427 /**
342 * Invokes the named constructor and returns a mirror on the result. 428 * Invokes the named constructor and returns a mirror on the result.
343 * 429 *
344 * TODO(turnidge): Properly document. 430 * TODO(turnidge): Properly document.
345 */ 431 */
346 Future<InstanceMirror> newInstance(String constructorName, 432 Future<InstanceMirror> newInstance(String constructorName,
347 List<Object> positionalArguments, 433 List<Object> positionalArguments,
348 [Map<String,Object> namedArguments]); 434 [Map<String,Object> namedArguments]);
435
436 /**
437 * Does this mirror represent a class?
438 *
439 * TODO(turnidge): This functions goes away after the
440 * class/interface changes.
441 */
442 final bool isClass;
443
444 /**
445 * A mirror on the default factory class or null if there is none.
446 *
447 * TODO(turnidge): This functions goes away after the
448 * class/interface changes.
449 */
450 final ClassMirror defaultFactory;
451 }
452
453 /**
454 * A [TypeVariableMirror] represents a type parameter of a generic
455 * type.
456 */
457 interface TypeVariableMirror extends TypeMirror {
458 /**
459 * The bound of the reflectee.
cshapiro 2012/08/21 03:16:05 I am not sure what this means from the comment. I
turnidge 2012/08/21 18:00:49 Changed to upperBound and improved comment.
460 */
461 final TypeMirror bound;
462 }
463
464 /**
465 * A [FunctionTypeMirror] represents the type of a function in the
466 * Dart language.
467 */
468 interface FunctionTypeMirror extends TypeMirror {
469 /**
470 * The return type of the reflectee.
471 */
472 final TypeMirror returnType;
473
474 /**
475 * A list of the parameter types of the reflectee.
476 */
477 final List<ParameterMirror> parameters;
478
479 /**
480 * A mirror on the [:call:] method for the reflectee.
481 *
482 * TODO(turnidge): What is this and what is it for?
483 */
484 final MethodMirror callMethod;
485 }
486
487 /**
488 * A [TypedefMirror] represents a typedef in a Dart language program.
489 */
490 interface TypedefMirror extends ClassMirror {
491 /**
492 * The defining type for this typedef.
493 *
494 * For instance [:void f(int):] is the value for [:typedef void f(int):].
495 */
496 final TypeMirror value;
349 } 497 }
350 498
351 /** 499 /**
352 * A [MethodMirror] reflects a Dart language function, method, 500 * A [MethodMirror] reflects a Dart language function, method,
353 * constructor, getter, or setter. 501 * constructor, getter, or setter.
354 */ 502 */
355 interface MethodMirror { 503 interface MethodMirror extends DeclarationMirror {
356 /** 504 /**
357 * The name of this function. 505 * A mirror on the return type for the reflectee.
358 */ 506 */
359 final String simpleName; 507 final TypeMirror returnType;
360 508
361 /** 509 /**
362 * A mirror on the owner of this function. This is the declaration 510 * 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 */ 511 */
374 final List<ParameterMirror> parameters; 512 final List<ParameterMirror> parameters;
375 513
376 // Ownership 514 /**
377 515 * 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 * 516 *
386 * For the purposes of the mirrors library, a top-level function is 517 * For the purposes of the mirrors library, a top-level function is
387 * considered static. 518 * considered static.
388 */ 519 */
389 final bool isStatic; 520 final bool isStatic;
390 521
391 // Method kind 522 /**
392 523 * 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 */ 524 */
403 final bool isAbstract; 525 final bool isAbstract;
404 526
405 /** 527 /**
406 * Does this mirror reflect a getter? 528 * Is the reflectee a regular function or method?
529 *
530 * A function or method is regular if it is not a getter, setter, or
531 * constructor. Note that operators, by this definition, are
532 * regular methods.
533 */
534 final bool isRegularMethod;
535
536 /**
537 * Is the reflectee an operator?
538 */
539 final bool isOperator;
540
541 /**
542 * Is the reflectee a getter?
407 */ 543 */
408 final bool isGetter; 544 final bool isGetter;
409 545
410 /** 546 /**
411 * Does this mirror reflect a setter? 547 * Is the reflectee a setter?
412 */ 548 */
413 final bool isSetter; 549 final bool isSetter;
414 550
415 /** 551 /**
416 * Does this mirror reflect a constructor? 552 * Is the reflectee a constructor?
417 */ 553 */
418 final bool isConstructor; 554 final bool isConstructor;
419 555
420 // Constructor kind 556 /**
421 557 * The constructor name for named constructors and factory methods.
422 /** 558 *
423 * Does this mirror reflect a const constructor? 559 * For unnamed constructors, this is the empty string. For
560 * non-constructors, this is the empty string.
561 *
562 * For example, [:'bar':] is the constructor name for constructor
563 * [:Foo.bar:] of type [:Foo:].
564 */
565 Final String constructorName;
566
567 /**
568 * Is the reflectee a const constructor?
424 */ 569 */
425 final bool isConstConstructor; 570 final bool isConstConstructor;
426 571
427 /** 572 /**
428 * Does this mirror reflect a generative constructor? 573 * Is the reflectee a generative constructor?
429 */ 574 */
430 final bool isGenerativeConstructor; 575 final bool isGenerativeConstructor;
431 576
432 /** 577 /**
433 * Does this mirror reflect a redirecting constructor? 578 * Is the reflectee a redirecting constructor?
434 */ 579 */
435 final bool isRedirectingConstructor; 580 final bool isRedirectingConstructor;
436 581
437 /** 582 /**
438 * Does this mirror reflect a factory constructor? 583 * Is the reflectee a factory constructor?
439 */ 584 */
440 final bool isFactoryConstructor; 585 final bool isFactoryConstructor;
441 } 586 }
442 587
443 /** 588 /**
444 * A [VariableMirror] reflects a Dart language variable declaration. 589 * A [VariableMirror] reflects a Dart language variable declaration.
445 */ 590 */
446 interface VariableMirror { 591 interface VariableMirror extends DeclarationMirror {
447 /** 592 /**
448 * The name of this variable 593 * A mirror on the type of the reflectee.
449 */ 594 */
450 final String simpleName; 595 final TypeMirror type;
451 596
452 /** 597 /**
453 * A mirror on the owner of this method. The owner is the 598 * 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 * 599 *
469 * For the purposes of the mirror library, top-level variables are 600 * For the purposes of the mirror library, top-level variables are
470 * implicitly declared static. 601 * implicitly declared static.
471 */ 602 */
472 final bool isStatic; 603 final bool isStatic;
473 604
474 /** 605 /**
475 * Does this mirror reflect a final variable? 606 * Is the reflectee a final variable?
476 */ 607 */
477 final bool isFinal; 608 final bool isFinal;
478 } 609 }
479 610
480 /** 611 /**
481 * A [ParameterMirror] reflects a Dart formal parameter declaration. 612 * A [ParameterMirror] reflects a Dart formal parameter declaration.
482 */ 613 */
483 interface ParameterMirror extends VariableMirror { 614 interface ParameterMirror extends VariableMirror {
484 /** 615 /**
485 * Returns the type of this parameter. 616 * A mirror on the type of this parameter.
486 */ 617 */
487 final TypeMirror type; 618 final TypeMirror type;
488 619
489 /** 620 /**
490 * Returns the default value for this parameter. 621 * Is this parameter optional?
491 */ 622 */
492 final String defaultValue; 623 final bool isOptional;
493 624
494 /** 625 /**
495 * Returns true if this parameter has a default value. 626 * Is this parameter named?
627 */
628 final bool isNamed;
629
630 /**
631 * Does this parameter have a default value?
496 */ 632 */
497 final bool hasDefaultValue; 633 final bool hasDefaultValue;
498 634
499 /** 635 /**
500 * Returns true if this parameter is optional. 636 * A mirror on the default value for this parameter, if it exists.
637 *
638 * TODO(turnidge): String may not be a good representation of this
639 * at runtime.
501 */ 640 */
502 final bool isOptional; 641 final String defaultValue;
642 }
643
644 /**
645 * A [SourceLocation] describes the span of an entity in Dart source code.
646 */
647 interface SourceLocation {
503 } 648 }
504 649
505 /** 650 /**
506 * When an error occurs during the mirrored execution of code, a 651 * When an error occurs during the mirrored execution of code, a
507 * [MirroredError] is thrown. 652 * [MirroredError] is thrown.
508 * 653 *
509 * In general, there are three main classes of failure that can happen 654 * In general, there are three main classes of failure that can happen
510 * during mirrored execution of code in some isolate: 655 * during mirrored execution of code in some isolate:
511 * 656 *
512 * - An exception is thrown but not caught. This is caught by the 657 * - 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 721
577 /** 722 /**
578 * A [MirrorException] is used to indicate errors within the mirrors 723 * A [MirrorException] is used to indicate errors within the mirrors
579 * framework. 724 * framework.
580 */ 725 */
581 class MirrorException implements Exception { 726 class MirrorException implements Exception {
582 const MirrorException(String this._message); 727 const MirrorException(String this._message);
583 String toString() => "MirrorException: '$_message'"; 728 String toString() => "MirrorException: '$_message'";
584 final String _message; 729 final String _message;
585 } 730 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698