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