OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 * At runtime each running isolate has a distinct [MirrorSystem]. | 64 * At runtime each running isolate has a distinct [MirrorSystem]. |
65 * | 65 * |
66 * It is also possible to have a [MirrorSystem] which represents a set | 66 * It is also possible to have a [MirrorSystem] which represents a set |
67 * of libraries which are not running -- perhaps at compile-time. In | 67 * of libraries which are not running -- perhaps at compile-time. In |
68 * this case, all available reflective functionality would be | 68 * this case, all available reflective functionality would be |
69 * supported, but runtime functionality (such as invoking a function | 69 * supported, but runtime functionality (such as invoking a function |
70 * or inspecting the contents of a variable) would fail dynamically. | 70 * or inspecting the contents of a variable) would fail dynamically. |
71 */ | 71 */ |
72 abstract class MirrorSystem { | 72 abstract class MirrorSystem { |
73 /** | 73 /** |
74 * Returns an immutable map from URIs to mirrors for all libraries known | 74 * All libraries known to the mirror system, indexed by their URI. |
75 * to this mirror system. For a runtime mirror system, only libraries which | 75 * |
76 * are currently loaded are included, and repeated calls of this method may | 76 * Returns an unmodifiable map of the libraries with [LibraryMirror.uri] as |
77 * return different maps as libraries are loaded. | 77 * keys. |
| 78 * |
| 79 * For a runtime mirror system, only libraries which are currently loaded |
| 80 * are included, and repeated calls of this method may return different maps |
| 81 * as libraries are loaded. |
78 */ | 82 */ |
79 Map<Uri, LibraryMirror> get libraries; | 83 Map<Uri, LibraryMirror> get libraries; |
80 | 84 |
81 /** | 85 /** |
82 * Returns the unique library named [libraryName] if it exists. | 86 * Returns the unique library named [libraryName] if it exists. |
83 * | 87 * |
84 * If no unique library exists, an error is thrown. | 88 * If no unique library exists, an error is thrown. |
85 */ | 89 */ |
86 LibraryMirror findLibrary(Symbol libraryName) { | 90 LibraryMirror findLibrary(Symbol libraryName) { |
87 return libraries.values.singleWhere( | 91 return libraries.values.singleWhere( |
88 (library) => library.simpleName == libraryName); | 92 (library) => library.simpleName == libraryName); |
89 } | 93 } |
90 | 94 |
91 /** | 95 /** |
92 * A mirror on the isolate associated with this [MirrorSystem]. | 96 * A mirror on the isolate associated with this [MirrorSystem]. |
| 97 * |
93 * This may be null if this mirror system is not running. | 98 * This may be null if this mirror system is not running. |
94 */ | 99 */ |
95 IsolateMirror get isolate; | 100 IsolateMirror get isolate; |
96 | 101 |
97 /** | 102 /** |
98 * A mirror on the [:dynamic:] type. | 103 * A mirror on the [:dynamic:] type. |
99 */ | 104 */ |
100 TypeMirror get dynamicType; | 105 TypeMirror get dynamicType; |
101 | 106 |
102 /** | 107 /** |
103 * A mirror on the [:void:] type. | 108 * A mirror on the [:void:] type. |
104 */ | 109 */ |
105 TypeMirror get voidType; | 110 TypeMirror get voidType; |
106 | 111 |
107 /** | 112 /** |
108 * Returns the name of [symbol]. | 113 * Returns the name of [symbol]. |
109 * | 114 * |
110 * The following text is non-normative: | 115 * The following text is non-normative: |
111 * | 116 * |
112 * Using this method may result in larger output. If possible, use | 117 * Using this method may result in larger output. If possible, use |
113 * [MirrorsUsed] to specify which symbols must be retained in clear text. | 118 * [MirrorsUsed] to specify which symbols must be retained in clear text. |
114 */ | 119 */ |
115 external static String getName(Symbol symbol); | 120 external static String getName(Symbol symbol); |
116 | 121 |
117 /** | 122 /** |
118 * Returns a symbol for [name]. If [library] is not a [LibraryMirror] or if | 123 * Returns a symbol for [name]. |
119 * [name] is a private identifier and [library] is [:null:], throws an | 124 * |
120 * [ArgumentError]. If [name] is a private identifier, the symbol returned is | 125 * If [library] is not a [LibraryMirror] or if [name] is a private identifier |
121 * with respect to [library]. | 126 * and [library] is `null`, throws an [ArgumentError]. If [name] is a private |
| 127 * identifier, the symbol returned is with respect to [library]. |
122 * | 128 * |
123 * The following text is non-normative: | 129 * The following text is non-normative: |
124 * | 130 * |
125 * Using this method may result in larger output. If possible, use | 131 * Using this method may result in larger output. If possible, use |
126 * the const constructor of Symbol or symbol literals. | 132 * the const constructor of [Symbol] or symbol literals. |
127 */ | 133 */ |
128 external static Symbol getSymbol(String name, [LibraryMirror library]); | 134 external static Symbol getSymbol(String name, [LibraryMirror library]); |
129 } | 135 } |
130 | 136 |
131 /** | 137 /** |
132 * Returns a [MirrorSystem] for the current isolate. | 138 * Returns a [MirrorSystem] for the current isolate. |
133 */ | 139 */ |
134 external MirrorSystem currentMirrorSystem(); | 140 external MirrorSystem currentMirrorSystem(); |
135 | 141 |
136 /** | 142 /** |
137 * Reflects an instance. | 143 * Reflects an instance. |
138 * Returns an [InstanceMirror] reflecting [reflectee]. | |
139 * If [reflectee] is a function or an instance of a class | |
140 * that has a [:call:] method, the returned instance mirror | |
141 * will be a [ClosureMirror]. | |
142 * | 144 * |
143 * Note that since one cannot obtain an object from | 145 * Returns an [InstanceMirror] reflecting [reflectee]. If [reflectee] is a |
144 * another isolate, this function can only be used to | 146 * function or an instance of a class that has a [:call:] method, the returned |
145 * obtain mirrors on objects of the current isolate. | 147 * instance mirror will be a [ClosureMirror]. |
| 148 * |
| 149 * Note that since one cannot obtain an object from another isolate, this |
| 150 * function can only be used to obtain mirrors on objects of the current |
| 151 * isolate. |
146 */ | 152 */ |
147 external InstanceMirror reflect(Object reflectee); | 153 external InstanceMirror reflect(Object reflectee); |
148 | 154 |
149 /** | 155 /** |
150 * Reflects a class declaration. | 156 * Reflects a class declaration. |
151 * Let *C* be the original class declaration of the class | 157 * |
152 * represented by [key]. | 158 * Let *C* be the original class declaration of the class represented by [key]. |
153 * This function returns a [ClassMirror] reflecting *C*. | 159 * This function returns a [ClassMirror] reflecting *C*. |
154 * | 160 * |
155 * If [key] is not an instance of [Type] then this function | 161 * If [key] is not an instance of [Type], then this function throws an |
156 * throws an [ArgumentError]. If [key] is the Type for dynamic | 162 * [ArgumentError]. If [key] is the Type for dynamic or a function typedef, |
157 * or a function typedef, throws an [ArgumentError]. | 163 * throws an [ArgumentError]. |
158 * | 164 * |
159 * Note that since one cannot obtain a [Type] object from | 165 * Note that since one cannot obtain a [Type] object from another isolate, this |
160 * another isolate, this function can only be used to | 166 * function can only be used to obtain class mirrors on classes of the current |
161 * obtain class mirrors on classes of the current isolate. | 167 * isolate. |
162 */ | 168 */ |
163 external ClassMirror reflectClass(Type key); | 169 external ClassMirror reflectClass(Type key); |
164 | 170 |
165 /** | 171 /** |
166 * This function returns a [TypeMirror] reflecting the type | 172 * Reflects the type represented by [key]. |
167 * represented by [key]. | |
168 * | 173 * |
169 * If [key] is not an instance of [Type] then this function | 174 * If [key] is not an instance of [Type], then this function throws an |
170 * throws an [ArgumentError]. | 175 * [ArgumentError]. |
171 * | 176 * |
172 * Note that since one cannot obtain a [Type] object from | 177 * Note that since one cannot obtain a [Type] object from another isolate, this |
173 * another isolate, this function can only be used to | 178 * function can only be used to obtain type mirrors on types of the current |
174 * obtain type mirrors on types of the current isolate. | 179 * isolate. |
175 */ | 180 */ |
176 external TypeMirror reflectType(Type key); | 181 external TypeMirror reflectType(Type key); |
177 | 182 |
178 /** | 183 /** |
179 * A [Mirror] reflects some Dart language entity. | 184 * A [Mirror] reflects some Dart language entity. |
180 * | 185 * |
181 * Every [Mirror] originates from some [MirrorSystem]. | 186 * Every [Mirror] originates from some [MirrorSystem]. |
182 */ | 187 */ |
183 abstract class Mirror {} | 188 abstract class Mirror {} |
184 | 189 |
185 /** | 190 /** |
186 * An [IsolateMirror] reflects an isolate. | 191 * An [IsolateMirror] reflects an isolate. |
187 */ | 192 */ |
188 abstract class IsolateMirror implements Mirror { | 193 abstract class IsolateMirror implements Mirror { |
189 /** | 194 /** |
190 * Returns a unique name used to refer to an isolate | 195 * A unique name used to refer to the isolate in debugging messages. |
191 * in debugging messages. | |
192 */ | 196 */ |
193 String get debugName; | 197 String get debugName; |
194 | 198 |
195 /** | 199 /** |
196 * Returns [:true:] if and only if this mirror reflects | 200 * Whether this mirror reflects the currently running isolate. |
197 * the currently running isolate. Otherwise returns | |
198 * [:false:]. | |
199 */ | 201 */ |
200 bool get isCurrent; | 202 bool get isCurrent; |
201 | 203 |
202 /** | 204 /** |
203 * Returns a [LibraryMirror] on the root library for this | 205 * The root library for the reflected isolate. |
204 * isolate. | |
205 */ | 206 */ |
206 LibraryMirror get rootLibrary; | 207 LibraryMirror get rootLibrary; |
207 | 208 |
208 /** | 209 /** |
209 * Returns [:true:] if this mirror is equal to [other]. | 210 * Whether [other] is an [IsolateMirror] on the same isolate as this mirror. |
210 * Otherwise returns [:false:]. | 211 * |
211 * The equality holds if and only if | 212 * The equality holds if and only if |
212 * (1) [other] is a mirror of the same kind | 213 * |
213 * and | 214 * 1. [other] is a mirror of the same kind, and |
214 * (2) the isolate being reflected by this mirror is the same | 215 * 2. the isolate being reflected by this mirror is the same isolate being |
215 * isolate being reflected by [other]. | 216 * reflected by [other]. |
216 */ | 217 */ |
217 bool operator == (other); | 218 bool operator == (other); |
218 } | 219 } |
219 | 220 |
220 /** | 221 /** |
221 * A [DeclarationMirror] reflects some entity declared in a Dart program. | 222 * A [DeclarationMirror] reflects some entity declared in a Dart program. |
222 */ | 223 */ |
223 abstract class DeclarationMirror implements Mirror { | 224 abstract class DeclarationMirror implements Mirror { |
224 /** | 225 /** |
225 * The simple name for this Dart language entity. | 226 * The simple name for this Dart language entity. |
226 * | 227 * |
227 * The simple name is in most cases the the identifier name of the | 228 * The simple name is in most cases the the identifier name of the entity, |
228 * entity, such as 'method' for a method [:void method() {...}:] or | 229 * such as 'myMethod' for a method, [:void myMethod() {...}:] or 'mylibrary' |
229 * 'mylibrary' for a [:library 'mylibrary';:] declaration. | 230 * for a [:library 'mylibrary';:] declaration. |
230 */ | 231 */ |
231 Symbol get simpleName; | 232 Symbol get simpleName; |
232 | 233 |
233 /** | 234 /** |
234 * The fully-qualified name for this Dart language entity. | 235 * The fully-qualified name for this Dart language entity. |
235 * | 236 * |
236 * This name is qualified by the name of the owner. For instance, | 237 * This name is qualified by the name of the owner. For instance, |
237 * the qualified name of a method 'method' in class 'Class' in | 238 * the qualified name of a method 'method' in class 'Class' in |
238 * library 'library' is 'library.Class.method'. | 239 * library 'library' is 'library.Class.method'. |
239 * | 240 * |
240 * Returns a [Symbol] constructed from a string representing the | 241 * Returns a [Symbol] constructed from a string representing the |
241 * fully qualified name of the reflectee. | 242 * fully qualified name of the reflectee. |
242 * Let *o* be the [owner] of this mirror, let *r* be the reflectee of | 243 * Let *o* be the [owner] of this mirror, let *r* be the reflectee of |
243 * this mirror, let *p* be the fully qualified | 244 * this mirror, let *p* be the fully qualified |
244 * name of the reflectee of *o*, and let *s* be the simple name of *r* | 245 * name of the reflectee of *o*, and let *s* be the simple name of *r* |
245 * computed by [simpleName]. | 246 * computed by [simpleName]. |
246 * The fully qualified name of *r* is the | 247 * The fully qualified name of *r* is the |
247 * concatenation of *p*, '.', and *s*. | 248 * concatenation of *p*, '.', and *s*. |
248 * | 249 * |
249 * Because an isolate can contain more than one library with the same name (at | 250 * Because an isolate can contain more than one library with the same name (at |
250 * different URIs), a fully-qualified name does not uniquely identify any | 251 * different URIs), a fully-qualified name does not uniquely identify any |
251 * language entity. | 252 * language entity. |
252 */ | 253 */ |
253 Symbol get qualifiedName; | 254 Symbol get qualifiedName; |
254 | 255 |
255 /** | 256 /** |
256 * A mirror on the owner of this Dart language entity. This is the declaration | 257 * A mirror on the owner of this Dart language entity. |
257 * immediately surrounding the reflectee. | |
258 * | 258 * |
259 * For a library, the owner is [:null:]. | 259 * The owner is the declaration immediately surrounding the reflectee: |
260 * For a class declaration, typedef or top level function | 260 * |
261 * or variable, the owner is the enclosing library. | 261 * * For a library, the owner is [:null:]. |
262 * For a mixin application *S with M*, the owner is the owner | 262 * * For a class declaration, typedef or top level function or variable, the |
263 * of *M*. | 263 * owner is the enclosing library. |
264 * For a constructor, the owner is the immediately enclosing class. | 264 * * For a mixin application `S with M`, the owner is the owner of `M`. |
265 * For a method, instance variable or | 265 * * For a constructor, the owner is the immediately enclosing class. |
266 * a static variable, the owner is the immediately enclosing class, | 266 * * For a method, instance variable or a static variable, the owner is the |
267 * unless the class is a mixin application *S with M*, in which case | 267 * immediately enclosing class, unless the class is a mixin application |
268 * the owner is *M*. Note that *M* may be an invocation of a generic. | 268 * `S with M`, in which case the owner is `M`. Note that `M` may be an |
269 * For a parameter, local variable or local function the owner is the | 269 * invocation of a generic. |
270 * immediately enclosing function. | 270 * * For a parameter, local variable or local function the owner is the |
| 271 * immediately enclosing function. |
271 */ | 272 */ |
272 DeclarationMirror get owner; | 273 DeclarationMirror get owner; |
273 | 274 |
274 /** | 275 /** |
275 * Returns [:true:] if this declaration is considered private | 276 * Whether this declaration is library private. |
276 * according to the Dart language specification. | |
277 * Always returns [: false :] if this declaration | |
278 * is a library. | |
279 * Otherwise return [:false:]. | |
280 * | 277 * |
| 278 * Always returns `false` for a library declaration, |
| 279 * otherwise returns `true` if the declaration's name starts with an |
| 280 * underscore character (`_`), and `false` if it doesn't. |
281 */ | 281 */ |
282 bool get isPrivate; | 282 bool get isPrivate; |
283 | 283 |
284 /** | 284 /** |
285 * Is this declaration top-level? | 285 * Whether this declaration is top-level. |
286 * | 286 * |
287 * This is defined to be equivalent to: | 287 * A declaration is considered top-level if its [owner] is a [LibraryMirror]. |
288 * [:mirror.owner != null && mirror.owner is LibraryMirror:] | |
289 */ | 288 */ |
290 bool get isTopLevel; | 289 bool get isTopLevel; |
291 | 290 |
292 /** | 291 /** |
293 * The source location of this Dart language entity, or [:null:] if the | 292 * The source location of this Dart language entity, or [:null:] if the |
294 * entity is synthetic. | 293 * entity is synthetic. |
295 * | 294 * |
296 * If the reflectee is a variable, the returned location gives the position of
* the variable name at its point of declaration. | 295 * If the reflectee is a variable, the returned location gives the position |
| 296 * of the variable name at its point of declaration. |
297 * | 297 * |
298 * If the reflectee is a library, class, typedef, function or type variable | 298 * If the reflectee is a library, class, typedef, function or type variable |
299 * with associated metadata, the returned location gives the position of the | 299 * with associated metadata, the returned location gives the position of the |
300 * first metadata declaration associated with the reflectee. | 300 * first metadata declaration associated with the reflectee. |
301 * | 301 * |
302 * Otherwise: | 302 * Otherwise: |
| 303 * |
303 * If the reflectee is a library, the returned location gives the position of | 304 * If the reflectee is a library, the returned location gives the position of |
304 * the keyword 'library' at the reflectee's point of declaration, if the | 305 * the keyword 'library' at the reflectee's point of declaration, if the |
305 * reflectee is a named library, or the first character of the first line in | 306 * reflectee is a named library, or the first character of the first line in |
306 * the compilation unit defining the reflectee if the reflectee is anonymous. | 307 * the compilation unit defining the reflectee if the reflectee is anonymous. |
307 * | 308 * |
308 * If the reflectee is an abstract class, the returned location gives the | 309 * If the reflectee is an abstract class, the returned location gives the |
309 * position of the keyword 'abstract' at the reflectee's point of declaration.
* Otherwise, if the reflectee is a class, the returned location gives the | 310 * position of the keyword 'abstract' at the reflectee's point of declaration. |
| 311 * Otherwise, if the reflectee is a class, the returned location gives the |
310 * position of the keyword 'class' at the reflectee's point of declaration. | 312 * position of the keyword 'class' at the reflectee's point of declaration. |
311 * | 313 * |
312 * If the reflectee is a typedef the returned location gives the position of | 314 * If the reflectee is a typedef the returned location gives the position of |
313 * the of the keyword 'typedef' at the reflectee's point of declaration. | 315 * the of the keyword 'typedef' at the reflectee's point of declaration. |
314 * | 316 * |
315 * If the reflectee is a function with a declared return type, the returned | 317 * If the reflectee is a function with a declared return type, the returned |
316 * location gives the position of the function's return type at the | 318 * location gives the position of the function's return type at the |
317 * reflectee's point of declaration. Otherwise. the returned location gives | 319 * reflectee's point of declaration. Otherwise. the returned location gives |
318 * the position of the function's name at the reflectee's point of | 320 * the position of the function's name at the reflectee's point of |
319 * declaration. | 321 * declaration. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 * access. Real Dart objects are represented by the [InstanceMirror] | 354 * access. Real Dart objects are represented by the [InstanceMirror] |
353 * type. | 355 * type. |
354 * | 356 * |
355 * See [InstanceMirror], [ClassMirror], and [LibraryMirror]. | 357 * See [InstanceMirror], [ClassMirror], and [LibraryMirror]. |
356 */ | 358 */ |
357 abstract class ObjectMirror implements Mirror { | 359 abstract class ObjectMirror implements Mirror { |
358 | 360 |
359 /** | 361 /** |
360 * Invokes the named function and returns a mirror on the result. | 362 * Invokes the named function and returns a mirror on the result. |
361 * | 363 * |
362 * Let *o* be the object reflected by this mirror, let | 364 * Let *o* be the object reflected by this mirror, let *f* be the simple name |
363 * *f* be the simple name of the member denoted by [memberName], | 365 * of the member denoted by [memberName], let *a1, ..., an* be the elements |
364 * let *a1, ..., an* be the elements of [positionalArguments] | 366 * of [positionalArguments], let *k1, ..., km* be the identifiers denoted by |
365 * let *k1, ..., km* be the identifiers denoted by the elements of | 367 * the elements of [namedArguments.keys], and let *v1, ..., vm* be the |
366 * [namedArguments.keys] | 368 * elements of [namedArguments.values]. Then this method will perform the |
367 * and let *v1, ..., vm* be the elements of [namedArguments.values]. | 369 * method invocation *o.f(a1, ..., an, k1: v1, ..., km: vm)* in a scope that |
368 * Then this method will perform the method invocation | 370 * has access to the private members of *o* (if *o* is a class or library) or |
369 * *o.f(a1, ..., an, k1: v1, ..., km: vm)* | 371 * the private members of the class of *o* (otherwise). |
370 * in a scope that has access to the private members | 372 * |
371 * of *o* (if *o* is a class or library) or the private members of the | 373 * If the invocation returns a result *r*, this method returns the result of |
372 * class of *o* (otherwise). | 374 * calling [reflect]\(*r*\). |
373 * If the invocation returns a result *r*, this method returns | 375 * |
374 * the result of calling [reflect]\(*r*\). | 376 * If the invocation causes a compilation error the effect is the same as if |
375 * If the invocation causes a compilation error | 377 * a non-reflective compilation error had been encountered. |
376 * the effect is the same as if a non-reflective compilation error | 378 * |
377 * had been encountered. | 379 * If the invocation throws an exception *e* (that it does not catch), this |
378 * If the invocation throws an exception *e* (that it does not catch) | 380 * method throws *e*. |
379 * this method throws *e*. | |
380 */ | 381 */ |
381 /* | 382 /* |
382 * TODO(turnidge): Handle ambiguous names. | 383 * TODO(turnidge): Handle ambiguous names. |
383 * TODO(turnidge): Handle optional & named arguments. | 384 * TODO(turnidge): Handle optional & named arguments. |
384 */ | 385 */ |
385 InstanceMirror invoke(Symbol memberName, | 386 InstanceMirror invoke(Symbol memberName, |
386 List positionalArguments, | 387 List positionalArguments, |
387 [Map<Symbol,dynamic> namedArguments]); | 388 [Map<Symbol,dynamic> namedArguments]); |
388 | 389 |
389 /** | 390 /** |
390 * Invokes a getter and returns a mirror on the result. The getter | 391 * Invokes a getter and returns a mirror on the result. |
391 * can be the implicit getter for a field or a user-defined getter | 392 * |
| 393 * The getter can be the implicit getter for a field or a user-defined getter |
392 * method. | 394 * method. |
393 * | 395 * |
394 * Let *o* be the object reflected by this mirror, let | 396 * Let *o* be the object reflected by this mirror, |
395 * *f* be the simple name of the getter denoted by [fieldName], | 397 * let *f* be the simple name of the getter denoted by [fieldName]. |
396 * Then this method will perform the getter invocation | 398 * |
397 * *o.f* | 399 * Then this method will perform the getter invocation *o.f* in a scope that |
398 * in a scope that has access to the private members | 400 * has access to the private members of *o* (if *o* is a class or library) or |
399 * of *o* (if *o* is a class or library) or the private members of the | 401 * the private members of the class of *o* (otherwise). |
400 * class of *o* (otherwise). | |
401 * | 402 * |
402 * If this mirror is an [InstanceMirror], and [fieldName] denotes an instance | 403 * If this mirror is an [InstanceMirror], and [fieldName] denotes an instance |
403 * method on its reflectee, the result of the invocation is an instance | 404 * method on its reflectee, the result of the invocation is an instance |
404 * mirror on a closure corresponding to that method. | 405 * mirror on a closure corresponding to that method. |
405 * | 406 * |
406 * If this mirror is a [LibraryMirror], and [fieldName] denotes a top-level | 407 * If this mirror is a [LibraryMirror], and [fieldName] denotes a top-level |
407 * method in the corresponding library, the result of the invocation is an | 408 * method in the corresponding library, the result of the invocation is an |
408 * instance mirror on a closure corresponding to that method. | 409 * instance mirror on a closure corresponding to that method. |
409 * | 410 * |
410 * If this mirror is a [ClassMirror], and [fieldName] denotes a static method | 411 * If this mirror is a [ClassMirror], and [fieldName] denotes a static method |
411 * in the corresponding class, the result of the invocation is an instance | 412 * in the corresponding class, the result of the invocation is an instance |
412 * mirror on a closure corresponding to that method. | 413 * mirror on a closure corresponding to that method. |
413 * | 414 * |
414 * If the invocation returns a result *r*, this method returns | 415 * If the invocation returns a result *r*, this method returns the result of |
415 * the result of calling [reflect]\(*r*\). | 416 * calling [reflect]\(*r*\). |
416 * If the invocation causes a compilation error | 417 * |
417 * the effect is the same as if a non-reflective compilation error | 418 * If the invocation causes a compilation error, the effect is the same as if |
418 * had been encountered. | 419 * a non-reflective compilation error had been encountered. |
419 * If the invocation throws an exception *e* (that it does not catch) | 420 * |
420 * this method throws *e*. | 421 * If the invocation throws an exception *e* (that it does not catch), this |
| 422 * method throws *e*. |
421 */ | 423 */ |
422 // TODO(ahe): Remove stuff about scope and private members. [fieldName] is a | 424 // TODO(ahe): Remove stuff about scope and private members. [fieldName] is a |
423 // capability giving access to private members. | 425 // capability giving access to private members. |
424 InstanceMirror getField(Symbol fieldName); | 426 InstanceMirror getField(Symbol fieldName); |
425 | 427 |
426 /** | 428 /** |
427 * Invokes a setter and returns a mirror on the result. The setter | 429 * Invokes a setter and returns a mirror on the result. |
428 * may be either the implicit setter for a non-final field or a | 430 * |
| 431 * The setter may be either the implicit setter for a non-final field or a |
429 * user-defined setter method. | 432 * user-defined setter method. |
430 * | 433 * |
431 * Let *o* be the object reflected by this mirror, let | 434 * Let *o* be the object reflected by this mirror, |
432 * *f* be the simple name of the getter denoted by [fieldName], | 435 * let *f* be the simple name of the getter denoted by [fieldName], |
433 * and let *a* be the object bound to [value]. | 436 * and let *a* be the object bound to [value]. |
434 * Then this method will perform the setter invocation | 437 * |
435 * *o.f = a* | 438 * Then this method will perform the setter invocation *o.f = a* in a scope |
436 * in a scope that has access to the private members | 439 * that has access to the private members of *o* (if *o* is a class or |
437 * of *o* (if *o* is a class or library) or the private members of the | 440 * library) or the private members of the class of *o* (otherwise). |
438 * class of *o* (otherwise). | 441 * |
439 * If the invocation returns a result *r*, this method returns | 442 * If the invocation returns a result *r*, this method returns the result of |
440 * the result of calling [reflect]\([value]\). | 443 * calling [reflect]\([value]\). |
441 * If the invocation causes a compilation error | 444 * |
442 * the effect is the same as if a non-reflective compilation error | 445 * If the invocation causes a compilation error, the effect is the same as if |
443 * had been encountered. | 446 * a non-reflective compilation error had been encountered. |
444 * If the invocation throws an exception *e* (that it does not catch) | 447 * |
445 * this method throws *e*. | 448 * If the invocation throws an exception *e* (that it does not catch) this |
| 449 * method throws *e*. |
446 */ | 450 */ |
447 /* TODO(turnidge): Handle ambiguous names.*/ | 451 /* TODO(turnidge): Handle ambiguous names.*/ |
448 InstanceMirror setField(Symbol fieldName, Object value); | 452 InstanceMirror setField(Symbol fieldName, Object value); |
449 | 453 |
450 /** | 454 /** |
451 * Perform [invocation] on [reflectee]. | 455 * Performs [invocation] on [reflectee]. |
| 456 * |
452 * Equivalent to | 457 * Equivalent to |
453 * | 458 * |
454 * if (invocation.isGetter) { | 459 * if (invocation.isGetter) { |
455 * return this.getField(invocation.memberName).reflectee; | 460 * return this.getField(invocation.memberName).reflectee; |
456 * } else if (invocation.isSetter) { | 461 * } else if (invocation.isSetter) { |
457 * return this.setField(invocation.memberName, | 462 * return this.setField(invocation.memberName, |
458 * invocation.positionArguments[0]).reflectee; | 463 * invocation.positionArguments[0]).reflectee; |
459 * } else { | 464 * } else { |
460 * return this.invoke(invocation.memberName, | 465 * return this.invoke(invocation.memberName, |
461 * invocation.positionalArguments, | 466 * invocation.positionalArguments, |
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1430 final override; | 1435 final override; |
1431 | 1436 |
1432 /** | 1437 /** |
1433 * See the documentation for [MirrorsUsed.symbols], [MirrorsUsed.targets], | 1438 * See the documentation for [MirrorsUsed.symbols], [MirrorsUsed.targets], |
1434 * [MirrorsUsed.metaTargets] and [MirrorsUsed.override] for documentation | 1439 * [MirrorsUsed.metaTargets] and [MirrorsUsed.override] for documentation |
1435 * of the parameters. | 1440 * of the parameters. |
1436 */ | 1441 */ |
1437 const MirrorsUsed( | 1442 const MirrorsUsed( |
1438 {this.symbols, this.targets, this.metaTargets, this.override}); | 1443 {this.symbols, this.targets, this.metaTargets, this.override}); |
1439 } | 1444 } |
OLD | NEW |