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