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 // |
(...skipping 16 matching lines...) Expand all Loading... |
27 * of libraries which are not running -- perhaps at compile-time. In | 27 * of libraries which are not running -- perhaps at compile-time. In |
28 * this case, all available reflective functionality would be | 28 * this case, all available reflective functionality would be |
29 * supported, but runtime functionality (such as invoking a function | 29 * supported, but runtime functionality (such as invoking a function |
30 * or inspecting the contents of a variable) would fail dynamically. | 30 * or inspecting the contents of a variable) would fail dynamically. |
31 */ | 31 */ |
32 abstract class MirrorSystem { | 32 abstract class MirrorSystem { |
33 /** | 33 /** |
34 * An immutable map from from library names to mirrors for all | 34 * An immutable map from from library names to mirrors for all |
35 * libraries known to this mirror system. | 35 * libraries known to this mirror system. |
36 */ | 36 */ |
37 Map<String, LibraryMirror> get libraries; | 37 // TODO(ahe): [libraries] should be Map<Uri, LibraryMirror>. |
| 38 Map<Symbol, LibraryMirror> get libraries; |
38 | 39 |
39 /** | 40 /** |
40 * A mirror on the isolate associated with this [MirrorSystem]. | 41 * A mirror on the isolate associated with this [MirrorSystem]. |
41 * This may be null if this mirror system is not running. | 42 * This may be null if this mirror system is not running. |
42 */ | 43 */ |
43 IsolateMirror get isolate; | 44 IsolateMirror get isolate; |
44 | 45 |
45 /** | 46 /** |
46 * A mirror on the [:dynamic:] type. | 47 * A mirror on the [:dynamic:] type. |
47 */ | 48 */ |
48 TypeMirror get dynamicType; | 49 TypeMirror get dynamicType; |
49 | 50 |
50 /** | 51 /** |
51 * A mirror on the [:void:] type. | 52 * A mirror on the [:void:] type. |
52 */ | 53 */ |
53 TypeMirror get voidType; | 54 TypeMirror get voidType; |
| 55 |
| 56 external static String getName(Symbol symbol); |
54 } | 57 } |
55 | 58 |
56 /** | 59 /** |
57 * Returns a [MirrorSystem] for the current isolate. | 60 * Returns a [MirrorSystem] for the current isolate. |
58 */ | 61 */ |
59 external MirrorSystem currentMirrorSystem(); | 62 external MirrorSystem currentMirrorSystem(); |
60 | 63 |
61 /** | 64 /** |
62 * Creates a [MirrorSystem] for the isolate which is listening on | 65 * Creates a [MirrorSystem] for the isolate which is listening on |
63 * the [SendPort]. | 66 * the [SendPort]. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 * A [DeclarationMirror] reflects some entity declared in a Dart program. | 111 * A [DeclarationMirror] reflects some entity declared in a Dart program. |
109 */ | 112 */ |
110 abstract class DeclarationMirror implements Mirror { | 113 abstract class DeclarationMirror implements Mirror { |
111 /** | 114 /** |
112 * The simple name for this Dart language entity. | 115 * The simple name for this Dart language entity. |
113 * | 116 * |
114 * The simple name is in most cases the the identifier name of the | 117 * The simple name is in most cases the the identifier name of the |
115 * entity, such as 'method' for a method [:void method() {...}:] or | 118 * entity, such as 'method' for a method [:void method() {...}:] or |
116 * 'mylibrary' for a [:#library('mylibrary');:] declaration. | 119 * 'mylibrary' for a [:#library('mylibrary');:] declaration. |
117 */ | 120 */ |
118 String get simpleName; | 121 Symbol get simpleName; |
119 | 122 |
120 /** | 123 /** |
121 * The fully-qualified name for this Dart language entity. | 124 * The fully-qualified name for this Dart language entity. |
122 * | 125 * |
123 * This name is qualified by the name of the owner. For instance, | 126 * This name is qualified by the name of the owner. For instance, |
124 * the qualified name of a method 'method' in class 'Class' in | 127 * the qualified name of a method 'method' in class 'Class' in |
125 * library 'library' is 'library.Class.method'. | 128 * library 'library' is 'library.Class.method'. |
126 * | 129 * |
127 * TODO(turnidge): Specify whether this name is unique. Currently | 130 * TODO(turnidge): Specify whether this name is unique. Currently |
128 * this is a gray area due to lack of clarity over whether library | 131 * this is a gray area due to lack of clarity over whether library |
129 * names are unique. | 132 * names are unique. |
130 */ | 133 */ |
131 String get qualifiedName; | 134 Symbol get qualifiedName; |
132 | 135 |
133 /** | 136 /** |
134 * A mirror on the owner of this function. This is the declaration | 137 * A mirror on the owner of this function. This is the declaration |
135 * immediately surrounding the reflectee. | 138 * immediately surrounding the reflectee. |
136 * | 139 * |
137 * Note that for libraries, the owner will be [:null:]. | 140 * Note that for libraries, the owner will be [:null:]. |
138 */ | 141 */ |
139 DeclarationMirror get owner; | 142 DeclarationMirror get owner; |
140 | 143 |
141 /** | 144 /** |
(...skipping 25 matching lines...) Expand all Loading... |
167 * For the purposes of the mirrors library, these types are all | 170 * For the purposes of the mirrors library, these types are all |
168 * object-like, in that they support method invocation and field | 171 * object-like, in that they support method invocation and field |
169 * access. Real Dart objects are represented by the [InstanceMirror] | 172 * access. Real Dart objects are represented by the [InstanceMirror] |
170 * type. | 173 * type. |
171 * | 174 * |
172 * See [InstanceMirror], [ClassMirror], and [LibraryMirror]. | 175 * See [InstanceMirror], [ClassMirror], and [LibraryMirror]. |
173 */ | 176 */ |
174 abstract class ObjectMirror implements Mirror { | 177 abstract class ObjectMirror implements Mirror { |
175 /** | 178 /** |
176 * Invokes the named function and returns a mirror on the result. | 179 * Invokes the named function and returns a mirror on the result. |
177 * The arguments must be instances of [InstanceMirror], [num], | 180 * The arguments must be instances of [InstanceMirror], [num], |
178 * [String] or [bool]. | 181 * [String], or [bool]. |
179 */ | 182 */ |
180 /* TODO(turnidge): Properly document. | 183 /* TODO(turnidge): Properly document. |
181 * TODO(turnidge): Handle ambiguous names. | 184 * TODO(turnidge): Handle ambiguous names. |
182 * TODO(turnidge): Handle optional & named arguments. | 185 * TODO(turnidge): Handle optional & named arguments. |
183 */ | 186 */ |
184 Future<InstanceMirror> invokeAsync(String memberName, | 187 Future<InstanceMirror> invokeAsync(Symbol memberName, |
185 List<Object> positionalArguments, | 188 List<Object> positionalArguments, |
186 [Map<String,Object> namedArguments]); | 189 [Map<Symbol, Object> namedArguments]); |
187 | 190 |
188 /** | 191 /** |
189 * Invokes a getter and returns a mirror on the result. The getter | 192 * Invokes a getter and returns a mirror on the result. The getter |
190 * can be the implicit getter for a field or a user-defined getter | 193 * can be the implicit getter for a field or a user-defined getter |
191 * method. | 194 * method. |
192 */ | 195 */ |
193 /* TODO(turnidge): Handle ambiguous names.*/ | 196 /* TODO(turnidge): Handle ambiguous names.*/ |
194 Future<InstanceMirror> getFieldAsync(String fieldName); | 197 Future<InstanceMirror> getFieldAsync(Symbol fieldName); |
195 | 198 |
196 /** | 199 /** |
197 * Invokes a setter and returns a mirror on the result. The setter | 200 * Invokes a setter and returns a mirror on the result. The setter |
198 * may be either the implicit setter for a non-final field or a | 201 * may be either the implicit setter for a non-final field or a |
199 * user-defined setter method. | 202 * user-defined setter method. |
200 * The argument must be an instance of either [InstanceMirror], [num], | 203 * The argument must be an instance of either [InstanceMirror], [num], |
201 * [String] or [bool]. | 204 * [String], or [bool]. |
202 */ | 205 */ |
203 /* TODO(turnidge): Handle ambiguous names.*/ | 206 /* TODO(turnidge): Handle ambiguous names.*/ |
204 Future<InstanceMirror> setFieldAsync(String fieldName, Object value); | 207 Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object value); |
205 } | 208 } |
206 | 209 |
207 /** | 210 /** |
208 * An [InstanceMirror] reflects an instance of a Dart language object. | 211 * An [InstanceMirror] reflects an instance of a Dart language object. |
209 */ | 212 */ |
210 abstract class InstanceMirror implements ObjectMirror { | 213 abstract class InstanceMirror implements ObjectMirror { |
211 /** | 214 /** |
212 * A mirror on the type of the reflectee. | 215 * A mirror on the type of the reflectee. |
213 */ | 216 */ |
214 ClassMirror get type; | 217 ClassMirror get type; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 255 |
253 /** | 256 /** |
254 * The source code for this closure, if available. Otherwise null. | 257 * The source code for this closure, if available. Otherwise null. |
255 * | 258 * |
256 * TODO(turnidge): Would this just be available in function? | 259 * TODO(turnidge): Would this just be available in function? |
257 */ | 260 */ |
258 String get source; | 261 String get source; |
259 | 262 |
260 /** | 263 /** |
261 * Executes the closure. | 264 * Executes the closure. |
262 * The arguments must be instances of [InstanceMirror], [num], | 265 * The arguments must be instances of [InstanceMirror], [num], |
263 * [String] or [bool]. | 266 * [String], or [bool]. |
264 */ | 267 */ |
265 Future<InstanceMirror> applyAsync(List<Object> positionalArguments, | 268 Future<InstanceMirror> applyAsync(List<Object> positionalArguments, |
266 [Map<String,Object> namedArguments]); | 269 [Map<Symbol, Object> namedArguments]); |
267 | 270 |
268 /** | 271 /** |
269 * Looks up the value of a name in the scope of the closure. The | 272 * Looks up the value of a name in the scope of the closure. The |
270 * result is a mirror on that value. | 273 * result is a mirror on that value. |
271 */ | 274 */ |
272 Future<InstanceMirror> findInContext(String name); | 275 Future<InstanceMirror> findInContext(Symbol name); |
273 } | 276 } |
274 | 277 |
275 /** | 278 /** |
276 * A [LibraryMirror] reflects a Dart language library, providing | 279 * A [LibraryMirror] reflects a Dart language library, providing |
277 * access to the variables, functions, and classes of the | 280 * access to the variables, functions, and classes of the |
278 * library. | 281 * library. |
279 */ | 282 */ |
280 abstract class LibraryMirror implements DeclarationMirror, ObjectMirror { | 283 abstract class LibraryMirror implements DeclarationMirror, ObjectMirror { |
281 /** | 284 /** |
282 * The url of the library. | 285 * The url of the library. |
283 * | 286 * |
284 * TODO(turnidge): Document where this url comes from. Will this | 287 * TODO(turnidge): Document where this url comes from. Will this |
285 * value be sensible? | 288 * value be sensible? |
286 */ | 289 */ |
| 290 // TODO(ahe): Change type to [Uri], rename to "uri"? |
287 String get url; | 291 String get url; |
288 | 292 |
289 /** | 293 /** |
290 * An immutable map from from names to mirrors for all members in | 294 * An immutable map from from names to mirrors for all members in |
291 * this library. | 295 * this library. |
292 * | 296 * |
293 * The members of a library are its top-level classes, | 297 * The members of a library are its top-level classes, |
294 * functions, variables, getters, and setters. | 298 * functions, variables, getters, and setters. |
295 */ | 299 */ |
296 Map<String, Mirror> get members; | 300 Map<Symbol, Mirror> get members; |
297 | 301 |
298 /** | 302 /** |
299 * An immutable map from names to mirrors for all class | 303 * An immutable map from names to mirrors for all class |
300 * declarations in this library. | 304 * declarations in this library. |
301 */ | 305 */ |
302 Map<String, ClassMirror> get classes; | 306 Map<Symbol, ClassMirror> get classes; |
303 | 307 |
304 /** | 308 /** |
305 * An immutable map from names to mirrors for all function, getter, | 309 * An immutable map from names to mirrors for all function, getter, |
306 * and setter declarations in this library. | 310 * and setter declarations in this library. |
307 */ | 311 */ |
308 Map<String, MethodMirror> get functions; | 312 Map<Symbol, MethodMirror> get functions; |
309 | 313 |
310 /** | 314 /** |
311 * An immutable map from names to mirrors for all getter | 315 * An immutable map from names to mirrors for all getter |
312 * declarations in this library. | 316 * declarations in this library. |
313 */ | 317 */ |
314 Map<String, MethodMirror> get getters; | 318 Map<Symbol, MethodMirror> get getters; |
315 | 319 |
316 /** | 320 /** |
317 * An immutable map from names to mirrors for all setter | 321 * An immutable map from names to mirrors for all setter |
318 * declarations in this library. | 322 * declarations in this library. |
319 */ | 323 */ |
320 Map<String, MethodMirror> get setters; | 324 Map<Symbol, MethodMirror> get setters; |
321 | 325 |
322 /** | 326 /** |
323 * An immutable map from names to mirrors for all variable | 327 * An immutable map from names to mirrors for all variable |
324 * declarations in this library. | 328 * declarations in this library. |
325 */ | 329 */ |
326 Map<String, VariableMirror> get variables; | 330 Map<Symbol, VariableMirror> get variables; |
327 } | 331 } |
328 | 332 |
329 /** | 333 /** |
330 * A [TypeMirror] reflects a Dart language class, typedef | 334 * A [TypeMirror] reflects a Dart language class, typedef, |
331 * or type variable. | 335 * or type variable. |
332 */ | 336 */ |
333 abstract class TypeMirror implements DeclarationMirror { | 337 abstract class TypeMirror implements DeclarationMirror { |
334 } | 338 } |
335 | 339 |
336 /** | 340 /** |
337 * A [ClassMirror] reflects a Dart language class. | 341 * A [ClassMirror] reflects a Dart language class. |
338 */ | 342 */ |
339 abstract class ClassMirror implements TypeMirror, ObjectMirror { | 343 abstract class ClassMirror implements TypeMirror, ObjectMirror { |
340 /** | 344 /** |
(...skipping 12 matching lines...) Expand all Loading... |
353 /** | 357 /** |
354 * An immutable map from from names to mirrors for all members of | 358 * An immutable map from from names to mirrors for all members of |
355 * this type. | 359 * this type. |
356 * | 360 * |
357 * The members of a type are its methods, fields, getters, and | 361 * The members of a type are its methods, fields, getters, and |
358 * setters. Note that constructors and type variables are not | 362 * setters. Note that constructors and type variables are not |
359 * considered to be members of a type. | 363 * considered to be members of a type. |
360 * | 364 * |
361 * This does not include inherited members. | 365 * This does not include inherited members. |
362 */ | 366 */ |
363 Map<String, Mirror> get members; | 367 Map<Symbol, Mirror> get members; |
364 | 368 |
365 /** | 369 /** |
366 * An immutable map from names to mirrors for all method, | 370 * An immutable map from names to mirrors for all method, |
367 * declarations for this type. This does not include getters and | 371 * declarations for this type. This does not include getters and |
368 * setters. | 372 * setters. |
369 */ | 373 */ |
370 Map<String, MethodMirror> get methods; | 374 Map<Symbol, MethodMirror> get methods; |
371 | 375 |
372 /** | 376 /** |
373 * An immutable map from names to mirrors for all getter | 377 * An immutable map from names to mirrors for all getter |
374 * declarations for this type. | 378 * declarations for this type. |
375 */ | 379 */ |
376 Map<String, MethodMirror> get getters; | 380 Map<Symbol, MethodMirror> get getters; |
377 | 381 |
378 /** | 382 /** |
379 * An immutable map from names to mirrors for all setter | 383 * An immutable map from names to mirrors for all setter |
380 * declarations for this type. | 384 * declarations for this type. |
381 */ | 385 */ |
382 Map<String, MethodMirror> get setters; | 386 Map<Symbol, MethodMirror> get setters; |
383 | 387 |
384 /** | 388 /** |
385 * An immutable map from names to mirrors for all variable | 389 * An immutable map from names to mirrors for all variable |
386 * declarations for this type. | 390 * declarations for this type. |
387 */ | 391 */ |
388 Map<String, VariableMirror> get variables; | 392 Map<Symbol, VariableMirror> get variables; |
389 | 393 |
390 /** | 394 /** |
391 * An immutable map from names to mirrors for all constructor | 395 * An immutable map from names to mirrors for all constructor |
392 * declarations for this type. | 396 * declarations for this type. |
393 */ | 397 */ |
394 Map<String, MethodMirror> get constructors; | 398 Map<Symbol, MethodMirror> get constructors; |
395 | 399 |
396 /** | 400 /** |
397 * An immutable map from names to mirrors for all type variables for | 401 * An immutable map from names to mirrors for all type variables for |
398 * this type. | 402 * this type. |
399 * | 403 * |
400 * This map preserves the order of declaration of the type variables. | 404 * This map preserves the order of declaration of the type variables. |
401 */ | 405 */ |
402 Map<String, TypeVariableMirror> get typeVariables; | 406 Map<Symbol, TypeVariableMirror> get typeVariables; |
403 | 407 |
404 /** | 408 /** |
405 * An immutable map from names to mirrors for all type arguments for | 409 * An immutable map from names to mirrors for all type arguments for |
406 * this type. | 410 * this type. |
407 * | 411 * |
408 * This map preserves the order of declaration of the type variables. | 412 * This map preserves the order of declaration of the type variables. |
409 */ | 413 */ |
410 Map<String, TypeMirror> get typeArguments; | 414 Map<Symbol, TypeMirror> get typeArguments; |
411 | 415 |
412 /** | 416 /** |
413 * Is this the original declaration of this type? | 417 * Is this the original declaration of this type? |
414 * | 418 * |
415 * For most classes, they are their own original declaration. For | 419 * For most classes, they are their own original declaration. For |
416 * generic classes, however, there is a distinction between the | 420 * generic classes, however, there is a distinction between the |
417 * original class declaration, which has unbound type variables, and | 421 * original class declaration, which has unbound type variables, and |
418 * the instantiations of generic classes, which have bound type | 422 * the instantiations of generic classes, which have bound type |
419 * variables. | 423 * variables. |
420 */ | 424 */ |
421 bool get isOriginalDeclaration; | 425 bool get isOriginalDeclaration; |
422 | 426 |
423 /** | 427 /** |
424 * A mirror on the original declaration of this type. | 428 * A mirror on the original declaration of this type. |
425 * | 429 * |
426 * For most classes, they are their own original declaration. For | 430 * For most classes, they are their own original declaration. For |
427 * generic classes, however, there is a distinction between the | 431 * generic classes, however, there is a distinction between the |
428 * original class declaration, which has unbound type variables, and | 432 * original class declaration, which has unbound type variables, and |
429 * the instantiations of generic classes, which have bound type | 433 * the instantiations of generic classes, which have bound type |
430 * variables. | 434 * variables. |
431 */ | 435 */ |
432 ClassMirror get originalDeclaration; | 436 ClassMirror get originalDeclaration; |
433 | 437 |
434 /** | 438 /** |
435 * Invokes the named constructor and returns a mirror on the result. | 439 * Invokes the named constructor and returns a mirror on the result. |
436 * The arguments must be instances of [InstanceMirror], [num], | 440 * The arguments must be instances of [InstanceMirror], [num], |
| 441 * [String], or [bool]. |
437 */ | 442 */ |
438 /* TODO(turnidge): Properly document.*/ | 443 /* TODO(turnidge): Properly document.*/ |
439 Future<InstanceMirror> newInstanceAsync(String constructorName, | 444 Future<InstanceMirror> newInstanceAsync(Symbol constructorName, |
440 List<Object> positionalArguments, | 445 List<Object> positionalArguments, |
441 [Map<String,Object> namedArguments]); | 446 [Map<Symbol, Object> namedArguments]); |
442 | 447 |
443 /** | 448 /** |
444 * Does this mirror represent a class? | 449 * Does this mirror represent a class? |
445 * | 450 * |
446 * TODO(turnidge): This functions goes away after the | 451 * TODO(turnidge): This functions goes away after the |
447 * class/interface changes. | 452 * class/interface changes. |
448 */ | 453 */ |
449 bool get isClass; | 454 bool get isClass; |
450 | 455 |
451 /** | 456 /** |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 | 567 |
563 /** | 568 /** |
564 * The constructor name for named constructors and factory methods. | 569 * The constructor name for named constructors and factory methods. |
565 * | 570 * |
566 * For unnamed constructors, this is the empty string. For | 571 * For unnamed constructors, this is the empty string. For |
567 * non-constructors, this is the empty string. | 572 * non-constructors, this is the empty string. |
568 * | 573 * |
569 * For example, [:'bar':] is the constructor name for constructor | 574 * For example, [:'bar':] is the constructor name for constructor |
570 * [:Foo.bar:] of type [:Foo:]. | 575 * [:Foo.bar:] of type [:Foo:]. |
571 */ | 576 */ |
572 String get constructorName; | 577 Symbol get constructorName; |
573 | 578 |
574 /** | 579 /** |
575 * Is the reflectee a const constructor? | 580 * Is the reflectee a const constructor? |
576 */ | 581 */ |
577 bool get isConstConstructor; | 582 bool get isConstConstructor; |
578 | 583 |
579 /** | 584 /** |
580 * Is the reflectee a generative constructor? | 585 * Is the reflectee a generative constructor? |
581 */ | 586 */ |
582 bool get isGenerativeConstructor; | 587 bool get isGenerativeConstructor; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 */ | 639 */ |
635 bool get isNamed; | 640 bool get isNamed; |
636 | 641 |
637 /** | 642 /** |
638 * Does this parameter have a default value? | 643 * Does this parameter have a default value? |
639 */ | 644 */ |
640 bool get hasDefaultValue; | 645 bool get hasDefaultValue; |
641 | 646 |
642 /** | 647 /** |
643 * A mirror on the default value for this parameter, if it exists. | 648 * 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. | |
647 */ | 649 */ |
| 650 // TODO(ahe): This should return an InstanceMirror. |
648 String get defaultValue; | 651 String get defaultValue; |
649 } | 652 } |
650 | 653 |
651 /** | 654 /** |
652 * A [SourceLocation] describes the span of an entity in Dart source code. | 655 * A [SourceLocation] describes the span of an entity in Dart source code. |
653 */ | 656 */ |
654 abstract class SourceLocation { | 657 abstract class SourceLocation { |
655 } | 658 } |
656 | 659 |
657 /** | 660 /** |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 /** | 759 /** |
757 * Is [:true:] if this comment is a documentation comment. | 760 * Is [:true:] if this comment is a documentation comment. |
758 * | 761 * |
759 * That is, that the comment is either enclosed in [: /** ... */ :] or starts | 762 * That is, that the comment is either enclosed in [: /** ... */ :] or starts |
760 * with [: /// :]. | 763 * with [: /// :]. |
761 */ | 764 */ |
762 final bool isDocComment; | 765 final bool isDocComment; |
763 | 766 |
764 const Comment(this.text, this.trimmedText, this.isDocComment); | 767 const Comment(this.text, this.trimmedText, this.isDocComment); |
765 } | 768 } |
OLD | NEW |