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 // VM-specific implementation of the dart:mirrors library. | 5 // VM-specific implementation of the dart:mirrors library. |
6 | 6 |
7 import "dart:collection" show UnmodifiableListView, UnmodifiableMapView; | 7 import "dart:collection" show UnmodifiableListView, UnmodifiableMapView; |
8 import "dart:_internal" as internal; | 8 import "dart:_internal" as internal; |
9 | 9 |
10 var _dirty = false; | 10 var _dirty = false; |
(...skipping 10 matching lines...) Expand all Loading... |
21 Symbol _s(String name) { | 21 Symbol _s(String name) { |
22 if (name == null) return null; | 22 if (name == null) return null; |
23 return new internal.Symbol.unvalidated(name); | 23 return new internal.Symbol.unvalidated(name); |
24 } | 24 } |
25 | 25 |
26 Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) { | 26 Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) { |
27 if (owner == null) return simpleName; | 27 if (owner == null) return simpleName; |
28 return _s('${_n(owner.qualifiedName)}.${_n(simpleName)}'); | 28 return _s('${_n(owner.qualifiedName)}.${_n(simpleName)}'); |
29 } | 29 } |
30 | 30 |
31 String _makeSignatureString(TypeMirror returnType, | 31 String _makeSignatureString( |
32 List<ParameterMirror> parameters) { | 32 TypeMirror returnType, List<ParameterMirror> parameters) { |
33 StringBuffer buf = new StringBuffer(); | 33 StringBuffer buf = new StringBuffer(); |
34 buf.write('('); | 34 buf.write('('); |
35 bool found_optional_positional = false; | 35 bool found_optional_positional = false; |
36 bool found_optional_named = false; | 36 bool found_optional_named = false; |
37 | 37 |
38 for (int i = 0; i < parameters.length; i++) { | 38 for (int i = 0; i < parameters.length; i++) { |
39 var param = parameters[i]; | 39 var param = parameters[i]; |
40 if (param.isOptional && param.isNamed && !found_optional_named) { | 40 if (param.isOptional && param.isNamed && !found_optional_named) { |
41 buf.write('{'); | 41 buf.write('{'); |
42 found_optional_named = true; | 42 found_optional_named = true; |
(...skipping 15 matching lines...) Expand all Loading... |
58 buf.write('}'); | 58 buf.write('}'); |
59 } | 59 } |
60 if (found_optional_positional) { | 60 if (found_optional_positional) { |
61 buf.write(']'); | 61 buf.write(']'); |
62 } | 62 } |
63 buf.write(') -> '); | 63 buf.write(') -> '); |
64 buf.write(_n(returnType.qualifiedName)); | 64 buf.write(_n(returnType.qualifiedName)); |
65 return buf.toString(); | 65 return buf.toString(); |
66 } | 66 } |
67 | 67 |
68 SourceLocation _location(reflectee) | 68 SourceLocation _location(reflectee) native "DeclarationMirror_location"; |
69 native "DeclarationMirror_location"; | |
70 | 69 |
71 List _metadata(reflectee) | 70 List _metadata(reflectee) native 'DeclarationMirror_metadata'; |
72 native 'DeclarationMirror_metadata'; | |
73 | 71 |
74 bool _subtypeTest(Type a, Type b) | 72 bool _subtypeTest(Type a, Type b) native 'TypeMirror_subtypeTest'; |
75 native 'TypeMirror_subtypeTest'; | |
76 | 73 |
77 class _AccessorCacheAssociation { | 74 class _AccessorCacheAssociation { |
78 String key; | 75 String key; |
79 Function value; | 76 Function value; |
80 bool usedSinceGrowth = true; | 77 bool usedSinceGrowth = true; |
81 _AccessorCacheAssociation(this.key, this.value); | 78 _AccessorCacheAssociation(this.key, this.value); |
82 } | 79 } |
83 | 80 |
84 /** | 81 /** |
85 * A map that will grow as associations are added but will prefer to evict | 82 * A map that will grow as associations are added but will prefer to evict |
86 * associations that have not been used since the last growth when needing to | 83 * associations that have not been used since the last growth when needing to |
87 * grow again. Implemented as an open addressing hash table. | 84 * grow again. Implemented as an open addressing hash table. |
88 */ | 85 */ |
89 class _AccessorCache { | 86 class _AccessorCache { |
90 List table; | 87 List table; |
91 int shift; | 88 int shift; |
92 int mask; | 89 int mask; |
93 int capacity; // Max number of associations before we start evicting/growing. | 90 int capacity; // Max number of associations before we start evicting/growing. |
94 int size = 0; // Current number of associations. | 91 int size = 0; // Current number of associations. |
95 | 92 |
96 /** | 93 /** |
97 * Create a cache whose capacity is 75% of 2^shift. | 94 * Create a cache whose capacity is 75% of 2^shift. |
98 */ | 95 */ |
99 _AccessorCache.withInitialShift(int shift) { | 96 _AccessorCache.withInitialShift(int shift) { |
100 // The scheme used here for handling collisions relies on there always | 97 // The scheme used here for handling collisions relies on there always |
101 // being at least one empty slot. | 98 // being at least one empty slot. |
102 if (shift < 1) throw new Exception("_AccessorCache requires a shift >= 1"); | 99 if (shift < 1) throw new Exception("_AccessorCache requires a shift >= 1"); |
103 initWithShift(shift); | 100 initWithShift(shift); |
104 } | 101 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 213 } |
217 } | 214 } |
218 | 215 |
219 class _LocalMirrorSystem extends MirrorSystem { | 216 class _LocalMirrorSystem extends MirrorSystem { |
220 final TypeMirror dynamicType = new _SpecialTypeMirror('dynamic'); | 217 final TypeMirror dynamicType = new _SpecialTypeMirror('dynamic'); |
221 final TypeMirror voidType = new _SpecialTypeMirror('void'); | 218 final TypeMirror voidType = new _SpecialTypeMirror('void'); |
222 | 219 |
223 var _libraries; | 220 var _libraries; |
224 Map<Uri, LibraryMirror> get libraries { | 221 Map<Uri, LibraryMirror> get libraries { |
225 if ((_libraries == null) || _dirty) { | 222 if ((_libraries == null) || _dirty) { |
226 _libraries = new Map<Uri, LibraryMirror>.fromIterable( | 223 _libraries = new Map<Uri, LibraryMirror>.fromIterable(_computeLibraries(), |
227 _computeLibraries(), key: (e) => e.uri); | 224 key: (e) => e.uri); |
228 _dirty = false; | 225 _dirty = false; |
229 } | 226 } |
230 return _libraries; | 227 return _libraries; |
231 } | 228 } |
| 229 |
232 static _computeLibraries() native "MirrorSystem_libraries"; | 230 static _computeLibraries() native "MirrorSystem_libraries"; |
233 | 231 |
234 var _isolate; | 232 var _isolate; |
235 IsolateMirror get isolate { | 233 IsolateMirror get isolate { |
236 if (_isolate == null) { | 234 if (_isolate == null) { |
237 _isolate = _computeIsolate(); | 235 _isolate = _computeIsolate(); |
238 } | 236 } |
239 return _isolate; | 237 return _isolate; |
240 } | 238 } |
| 239 |
241 static _computeIsolate() native "MirrorSystem_isolate"; | 240 static _computeIsolate() native "MirrorSystem_isolate"; |
242 | 241 |
243 String toString() => "MirrorSystem for isolate '${isolate.debugName}'"; | 242 String toString() => "MirrorSystem for isolate '${isolate.debugName}'"; |
244 } | 243 } |
245 | 244 |
246 class _SourceLocation implements SourceLocation { | 245 class _SourceLocation implements SourceLocation { |
247 _SourceLocation(uriString, this.line, this.column) | 246 _SourceLocation(uriString, this.line, this.column) |
248 : this.sourceUri = Uri.parse(uriString); | 247 : this.sourceUri = Uri.parse(uriString); |
249 | 248 |
250 // Line and column positions are 1-origin, or 0 if unknown. | 249 // Line and column positions are 1-origin, or 0 if unknown. |
(...skipping 21 matching lines...) Expand all Loading... |
272 } | 271 } |
273 | 272 |
274 class _SyntheticAccessor implements MethodMirror { | 273 class _SyntheticAccessor implements MethodMirror { |
275 final DeclarationMirror owner; | 274 final DeclarationMirror owner; |
276 final Symbol simpleName; | 275 final Symbol simpleName; |
277 final bool isGetter; | 276 final bool isGetter; |
278 final bool isStatic; | 277 final bool isStatic; |
279 final bool isTopLevel; | 278 final bool isTopLevel; |
280 final _target; | 279 final _target; |
281 | 280 |
282 _SyntheticAccessor(this.owner, | 281 _SyntheticAccessor(this.owner, this.simpleName, this.isGetter, this.isStatic, |
283 this.simpleName, | 282 this.isTopLevel, this._target); |
284 this.isGetter, | |
285 this.isStatic, | |
286 this.isTopLevel, | |
287 this._target); | |
288 | 283 |
289 bool get isSynthetic => true; | 284 bool get isSynthetic => true; |
290 bool get isRegularMethod => false; | 285 bool get isRegularMethod => false; |
291 bool get isOperator => false; | 286 bool get isOperator => false; |
292 bool get isConstructor => false; | 287 bool get isConstructor => false; |
293 bool get isConstConstructor => false; | 288 bool get isConstConstructor => false; |
294 bool get isGenerativeConstructor => false; | 289 bool get isGenerativeConstructor => false; |
295 bool get isFactoryConstructor => false; | 290 bool get isFactoryConstructor => false; |
296 bool get isExternal => false; | 291 bool get isExternal => false; |
297 bool get isRedirectingConstructor => false; | 292 bool get isRedirectingConstructor => false; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 InstanceMirror get defaultValue => null; | 331 InstanceMirror get defaultValue => null; |
337 SourceLocation get location => null; | 332 SourceLocation get location => null; |
338 List<InstanceMirror> get metadata => _emptyList; | 333 List<InstanceMirror> get metadata => _emptyList; |
339 } | 334 } |
340 | 335 |
341 abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror { | 336 abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror { |
342 final _reflectee; // May be a MirrorReference or an ordinary object. | 337 final _reflectee; // May be a MirrorReference or an ordinary object. |
343 | 338 |
344 _LocalObjectMirror(this._reflectee); | 339 _LocalObjectMirror(this._reflectee); |
345 | 340 |
346 InstanceMirror invoke(Symbol memberName, | 341 InstanceMirror invoke(Symbol memberName, List positionalArguments, |
347 List positionalArguments, | 342 [Map<Symbol, dynamic> namedArguments]) { |
348 [Map<Symbol, dynamic> namedArguments]) { | |
349 int numPositionalArguments = positionalArguments.length; | 343 int numPositionalArguments = positionalArguments.length; |
350 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; | 344 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; |
351 int numArguments = numPositionalArguments + numNamedArguments; | 345 int numArguments = numPositionalArguments + numNamedArguments; |
352 List arguments = new List(numArguments); | 346 List arguments = new List(numArguments); |
353 arguments.setRange(0, numPositionalArguments, positionalArguments); | 347 arguments.setRange(0, numPositionalArguments, positionalArguments); |
354 List names = new List(numNamedArguments); | 348 List names = new List(numNamedArguments); |
355 int argumentIndex = numPositionalArguments; | 349 int argumentIndex = numPositionalArguments; |
356 int nameIndex = 0; | 350 int nameIndex = 0; |
357 if (numNamedArguments > 0) { | 351 if (numNamedArguments > 0) { |
358 namedArguments.forEach((name, value) { | 352 namedArguments.forEach((name, value) { |
359 arguments[argumentIndex++] = value; | 353 arguments[argumentIndex++] = value; |
360 names[nameIndex++] = _n(name); | 354 names[nameIndex++] = _n(name); |
361 }); | 355 }); |
362 } | 356 } |
363 | 357 |
364 return reflect(this._invoke(_reflectee, _n(memberName), arguments, names)); | 358 return reflect(this._invoke(_reflectee, _n(memberName), arguments, names)); |
365 } | 359 } |
366 | 360 |
367 InstanceMirror getField(Symbol memberName) { | 361 InstanceMirror getField(Symbol memberName) { |
368 return reflect(this._invokeGetter(_reflectee, _n(memberName))); | 362 return reflect(this._invokeGetter(_reflectee, _n(memberName))); |
369 } | 363 } |
370 | 364 |
371 InstanceMirror setField(Symbol memberName, Object value) { | 365 InstanceMirror setField(Symbol memberName, Object value) { |
372 this._invokeSetter(_reflectee, _n(memberName), value); | 366 this._invokeSetter(_reflectee, _n(memberName), value); |
373 return reflect(value); | 367 return reflect(value); |
374 } | 368 } |
375 | 369 |
376 delegate(Invocation invocation) { | 370 delegate(Invocation invocation) { |
377 if (invocation.isMethod) { | 371 if (invocation.isMethod) { |
378 return this.invoke(invocation.memberName, | 372 return this |
379 invocation.positionalArguments, | 373 .invoke(invocation.memberName, invocation.positionalArguments, |
380 invocation.namedArguments).reflectee; | 374 invocation.namedArguments) |
| 375 .reflectee; |
381 } | 376 } |
382 if (invocation.isGetter) { | 377 if (invocation.isGetter) { |
383 return this.getField(invocation.memberName).reflectee; | 378 return this.getField(invocation.memberName).reflectee; |
384 } | 379 } |
385 if (invocation.isSetter) { | 380 if (invocation.isSetter) { |
386 var unwrapped = _n(invocation.memberName); | 381 var unwrapped = _n(invocation.memberName); |
387 var withoutEqual = _s(unwrapped.substring(0, unwrapped.length - 1)); | 382 var withoutEqual = _s(unwrapped.substring(0, unwrapped.length - 1)); |
388 var arg = invocation.positionalArguments[0]; | 383 var arg = invocation.positionalArguments[0]; |
389 this.setField(withoutEqual, arg).reflectee; | 384 this.setField(withoutEqual, arg).reflectee; |
390 return arg; | 385 return arg; |
391 } | 386 } |
392 throw "UNREACHABLE"; | 387 throw "UNREACHABLE"; |
393 } | 388 } |
394 } | 389 } |
395 | 390 |
396 class _LocalInstanceMirror extends _LocalObjectMirror | 391 class _LocalInstanceMirror extends _LocalObjectMirror |
397 implements InstanceMirror { | 392 implements InstanceMirror { |
398 | |
399 _LocalInstanceMirror(reflectee) : super(reflectee); | 393 _LocalInstanceMirror(reflectee) : super(reflectee); |
400 | 394 |
401 ClassMirror _type; | 395 ClassMirror _type; |
402 ClassMirror get type { | 396 ClassMirror get type { |
403 if (_type == null) { | 397 if (_type == null) { |
404 // Note it not safe to use reflectee.runtimeType because runtimeType may | 398 // Note it not safe to use reflectee.runtimeType because runtimeType may |
405 // be overridden. | 399 // be overridden. |
406 _type = reflectType(_computeType(reflectee)); | 400 _type = reflectType(_computeType(reflectee)); |
407 } | 401 } |
408 return _type; | 402 return _type; |
409 } | 403 } |
410 | 404 |
411 // LocalInstanceMirrors always reflect local instances | 405 // LocalInstanceMirrors always reflect local instances |
412 bool get hasReflectee => true; | 406 bool get hasReflectee => true; |
413 | 407 |
414 get reflectee => _reflectee; | 408 get reflectee => _reflectee; |
415 | 409 |
416 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; | 410 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; |
417 | 411 |
418 bool operator ==(other) { | 412 bool operator ==(other) { |
419 return other is _LocalInstanceMirror && | 413 return other is _LocalInstanceMirror && |
420 identical(_reflectee, other._reflectee); | 414 identical(_reflectee, other._reflectee); |
421 } | 415 } |
422 | 416 |
423 int get hashCode { | 417 int get hashCode { |
424 // Avoid hash collisions with the reflectee. This constant is in Smi range | 418 // Avoid hash collisions with the reflectee. This constant is in Smi range |
425 // and happens to be the inner padding from RFC 2104. | 419 // and happens to be the inner padding from RFC 2104. |
426 return identityHashCode(_reflectee) ^ 0x36363636; | 420 return identityHashCode(_reflectee) ^ 0x36363636; |
427 } | 421 } |
428 | 422 |
429 static var _getFieldClosures = new _AccessorCache.withInitialShift(4); | 423 static var _getFieldClosures = new _AccessorCache.withInitialShift(4); |
430 static var _setFieldClosures = new _AccessorCache.withInitialShift(4); | 424 static var _setFieldClosures = new _AccessorCache.withInitialShift(4); |
431 | 425 |
432 _createGetterClosure(unwrapped) { | 426 _createGetterClosure(unwrapped) { |
433 var atPosition = unwrapped.indexOf('@'); | 427 var atPosition = unwrapped.indexOf('@'); |
434 if (atPosition == -1) { | 428 if (atPosition == -1) { |
435 // Public symbol. | 429 // Public symbol. |
436 return _eval('(x) => x.$unwrapped', null); | 430 return _eval('(x) => x.$unwrapped', null); |
437 } else { | 431 } else { |
438 // Private symbol. | 432 // Private symbol. |
439 var withoutKey = unwrapped.substring(0, atPosition); | 433 var withoutKey = unwrapped.substring(0, atPosition); |
440 var privateKey = unwrapped.substring(atPosition); | 434 var privateKey = unwrapped.substring(atPosition); |
441 return _eval('(x) => x.$withoutKey', privateKey); | 435 return _eval('(x) => x.$withoutKey', privateKey); |
442 } | 436 } |
443 } | 437 } |
444 | 438 |
445 _getFieldSlow(unwrapped) { | 439 _getFieldSlow(unwrapped) { |
446 // Slow path factored out to give the fast path a better chance at being | 440 // Slow path factored out to give the fast path a better chance at being |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 var f = _setFieldClosures[unwrapped]; | 494 var f = _setFieldClosures[unwrapped]; |
501 return (f == null) | 495 return (f == null) |
502 ? _setFieldSlow(unwrapped, arg) | 496 ? _setFieldSlow(unwrapped, arg) |
503 : reflect(f(_reflectee, arg)); | 497 : reflect(f(_reflectee, arg)); |
504 } | 498 } |
505 | 499 |
506 static _eval(expression, privateKey) | 500 static _eval(expression, privateKey) |
507 native "Mirrors_evalInLibraryWithPrivateKey"; | 501 native "Mirrors_evalInLibraryWithPrivateKey"; |
508 | 502 |
509 // Override to include the receiver in the arguments. | 503 // Override to include the receiver in the arguments. |
510 InstanceMirror invoke(Symbol memberName, | 504 InstanceMirror invoke(Symbol memberName, List positionalArguments, |
511 List positionalArguments, | 505 [Map<Symbol, dynamic> namedArguments]) { |
512 [Map<Symbol, dynamic> namedArguments]) { | 506 int numPositionalArguments = positionalArguments.length + 1; // Receiver. |
513 int numPositionalArguments = positionalArguments.length + 1; // Receiver. | |
514 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; | 507 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; |
515 int numArguments = numPositionalArguments + numNamedArguments; | 508 int numArguments = numPositionalArguments + numNamedArguments; |
516 List arguments = new List(numArguments); | 509 List arguments = new List(numArguments); |
517 arguments[0] = _reflectee; // Receiver. | 510 arguments[0] = _reflectee; // Receiver. |
518 arguments.setRange(1, numPositionalArguments, positionalArguments); | 511 arguments.setRange(1, numPositionalArguments, positionalArguments); |
519 List names = new List(numNamedArguments); | 512 List names = new List(numNamedArguments); |
520 int argumentIndex = numPositionalArguments; | 513 int argumentIndex = numPositionalArguments; |
521 int nameIndex = 0; | 514 int nameIndex = 0; |
522 if (numNamedArguments > 0) { | 515 if (numNamedArguments > 0) { |
523 namedArguments.forEach((name, value) { | 516 namedArguments.forEach((name, value) { |
524 arguments[argumentIndex++] = value; | 517 arguments[argumentIndex++] = value; |
525 names[nameIndex++] = _n(name); | 518 names[nameIndex++] = _n(name); |
526 }); | 519 }); |
527 } | 520 } |
528 | 521 |
529 return reflect(this._invoke(_reflectee, _n(memberName), arguments, names)); | 522 return reflect(this._invoke(_reflectee, _n(memberName), arguments, names)); |
530 } | 523 } |
531 | 524 |
532 _invoke(reflectee, functionName, arguments, argumentNames) | 525 _invoke(reflectee, functionName, arguments, argumentNames) |
533 native 'InstanceMirror_invoke'; | 526 native 'InstanceMirror_invoke'; |
534 | 527 |
535 _invokeGetter(reflectee, getterName) | 528 _invokeGetter(reflectee, getterName) native 'InstanceMirror_invokeGetter'; |
536 native 'InstanceMirror_invokeGetter'; | |
537 | 529 |
538 _invokeSetter(reflectee, setterName, value) | 530 _invokeSetter(reflectee, setterName, value) |
539 native 'InstanceMirror_invokeSetter'; | 531 native 'InstanceMirror_invokeSetter'; |
540 | 532 |
541 static _computeType(reflectee) | 533 static _computeType(reflectee) native 'InstanceMirror_computeType'; |
542 native 'InstanceMirror_computeType'; | |
543 } | 534 } |
544 | 535 |
545 class _LocalClosureMirror extends _LocalInstanceMirror | 536 class _LocalClosureMirror extends _LocalInstanceMirror |
546 implements ClosureMirror { | 537 implements ClosureMirror { |
547 _LocalClosureMirror(reflectee) : super(reflectee); | 538 _LocalClosureMirror(reflectee) : super(reflectee); |
548 | 539 |
549 MethodMirror _function; | 540 MethodMirror _function; |
550 MethodMirror get function { | 541 MethodMirror get function { |
551 if (_function == null) { | 542 if (_function == null) { |
552 _function = _computeFunction(reflectee); | 543 _function = _computeFunction(reflectee); |
553 } | 544 } |
554 return _function; | 545 return _function; |
555 } | 546 } |
556 | 547 |
557 InstanceMirror apply(List<Object> positionalArguments, | 548 InstanceMirror apply(List<Object> positionalArguments, |
558 [Map<Symbol, Object> namedArguments]) { | 549 [Map<Symbol, Object> namedArguments]) { |
559 return this.invoke(#call, positionalArguments, namedArguments); | 550 return this.invoke(#call, positionalArguments, namedArguments); |
560 } | 551 } |
561 | 552 |
562 String toString() => "ClosureMirror on '${Error.safeToString(_reflectee)}'"; | 553 String toString() => "ClosureMirror on '${Error.safeToString(_reflectee)}'"; |
563 | 554 |
564 static _computeFunction(reflectee) | 555 static _computeFunction(reflectee) native 'ClosureMirror_function'; |
565 native 'ClosureMirror_function'; | |
566 } | 556 } |
567 | 557 |
568 class _LocalClassMirror extends _LocalObjectMirror | 558 class _LocalClassMirror extends _LocalObjectMirror implements ClassMirror { |
569 implements ClassMirror { | |
570 final Type _reflectedType; | 559 final Type _reflectedType; |
571 Symbol _simpleName; | 560 Symbol _simpleName; |
572 DeclarationMirror _owner; | 561 DeclarationMirror _owner; |
573 final bool isAbstract; | 562 final bool isAbstract; |
574 final bool _isGeneric; | 563 final bool _isGeneric; |
575 final bool _isMixinAlias; | 564 final bool _isMixinAlias; |
576 final bool _isGenericDeclaration; | 565 final bool _isGenericDeclaration; |
577 final bool isEnum; | 566 final bool isEnum; |
578 Type _instantiator; | 567 Type _instantiator; |
579 | 568 |
580 _LocalClassMirror(reflectee, | 569 _LocalClassMirror( |
581 reflectedType, | 570 reflectee, |
582 String simpleName, | 571 reflectedType, |
583 this._owner, | 572 String simpleName, |
584 this.isAbstract, | 573 this._owner, |
585 this._isGeneric, | 574 this.isAbstract, |
586 this._isMixinAlias, | 575 this._isGeneric, |
587 this._isGenericDeclaration, | 576 this._isMixinAlias, |
588 this.isEnum) | 577 this._isGenericDeclaration, |
| 578 this.isEnum) |
589 : this._simpleName = _s(simpleName), | 579 : this._simpleName = _s(simpleName), |
590 this._reflectedType = reflectedType, | 580 this._reflectedType = reflectedType, |
591 this._instantiator = reflectedType, | 581 this._instantiator = reflectedType, |
592 super(reflectee); | 582 super(reflectee); |
593 | 583 |
594 | |
595 bool get hasReflectedType => !_isGenericDeclaration; | 584 bool get hasReflectedType => !_isGenericDeclaration; |
596 Type get reflectedType { | 585 Type get reflectedType { |
597 if (!hasReflectedType) { | 586 if (!hasReflectedType) { |
598 throw new UnsupportedError( | 587 throw new UnsupportedError( |
599 "Declarations of generics have no reflected type"); | 588 "Declarations of generics have no reflected type"); |
600 } | 589 } |
601 return _reflectedType; | 590 return _reflectedType; |
602 } | 591 } |
603 | 592 |
604 Symbol get simpleName { | 593 Symbol get simpleName { |
605 // All but anonymous mixin applications have their name set at construction. | 594 // All but anonymous mixin applications have their name set at construction. |
606 if(_simpleName == null) { | 595 if (_simpleName == null) { |
607 _simpleName = this._mixinApplicationName; | 596 _simpleName = this._mixinApplicationName; |
608 } | 597 } |
609 return _simpleName; | 598 return _simpleName; |
610 } | 599 } |
611 | 600 |
612 Symbol _qualifiedName = null; | 601 Symbol _qualifiedName = null; |
613 Symbol get qualifiedName { | 602 Symbol get qualifiedName { |
614 if (_qualifiedName == null) { | 603 if (_qualifiedName == null) { |
615 _qualifiedName = _computeQualifiedName(owner, simpleName); | 604 _qualifiedName = _computeQualifiedName(owner, simpleName); |
616 } | 605 } |
(...skipping 24 matching lines...) Expand all Loading... |
641 : _supertypeInstantiated(_reflectedType); | 630 : _supertypeInstantiated(_reflectedType); |
642 if (supertype == null) { | 631 if (supertype == null) { |
643 // Object has no superclass. | 632 // Object has no superclass. |
644 return null; | 633 return null; |
645 } | 634 } |
646 _trueSuperclassField = reflectType(supertype); | 635 _trueSuperclassField = reflectType(supertype); |
647 _trueSuperclassField._instantiator = _instantiator; | 636 _trueSuperclassField._instantiator = _instantiator; |
648 } | 637 } |
649 return _trueSuperclassField; | 638 return _trueSuperclassField; |
650 } | 639 } |
| 640 |
651 ClassMirror get superclass { | 641 ClassMirror get superclass { |
652 return _isMixinAlias ? _trueSuperclass._trueSuperclass : _trueSuperclass; | 642 return _isMixinAlias ? _trueSuperclass._trueSuperclass : _trueSuperclass; |
653 } | 643 } |
654 | 644 |
655 var _superinterfaces; | 645 var _superinterfaces; |
656 List<ClassMirror> get superinterfaces { | 646 List<ClassMirror> get superinterfaces { |
657 if (_superinterfaces == null) { | 647 if (_superinterfaces == null) { |
658 _superinterfaces = isOriginalDeclaration | 648 _superinterfaces = isOriginalDeclaration |
659 ? _nativeInterfaces(_reflectedType) | 649 ? _nativeInterfaces(_reflectedType) |
660 : _nativeInterfacesInstantiated(_reflectedType); | 650 : _nativeInterfacesInstantiated(_reflectedType); |
661 _superinterfaces = | 651 _superinterfaces = |
662 new UnmodifiableListView(_superinterfaces.map(reflectType)); | 652 new UnmodifiableListView(_superinterfaces.map(reflectType)); |
663 } | 653 } |
664 return _superinterfaces; | 654 return _superinterfaces; |
665 } | 655 } |
666 | 656 |
667 get _mixinApplicationName { | 657 get _mixinApplicationName { |
668 var mixins = new List<ClassMirror>(); | 658 var mixins = new List<ClassMirror>(); |
669 var klass = this; | 659 var klass = this; |
670 while (_nativeMixin(klass._reflectedType) != null) { | 660 while (_nativeMixin(klass._reflectedType) != null) { |
671 mixins.add(klass.mixin); | 661 mixins.add(klass.mixin); |
672 klass = klass.superclass; | 662 klass = klass.superclass; |
673 } | 663 } |
674 return _s( | 664 return _s(_n(klass.qualifiedName) + |
675 _n(klass.qualifiedName) | 665 ' with ' + |
676 + ' with ' | 666 mixins.reversed.map((m) => _n(m.qualifiedName)).join(', ')); |
677 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', ')); | |
678 } | 667 } |
679 | 668 |
680 var _mixin; | 669 var _mixin; |
681 ClassMirror get mixin { | 670 ClassMirror get mixin { |
682 if (_mixin == null) { | 671 if (_mixin == null) { |
683 if (_isMixinAlias) { | 672 if (_isMixinAlias) { |
684 Type mixinType = _nativeMixinInstantiated( | 673 Type mixinType = _nativeMixinInstantiated( |
685 _trueSuperclass._reflectedType, _instantiator); | 674 _trueSuperclass._reflectedType, _instantiator); |
686 _mixin = reflectType(mixinType); | 675 _mixin = reflectType(mixinType); |
687 } else { | 676 } else { |
688 Type mixinType = _nativeMixinInstantiated(_reflectedType, | 677 Type mixinType = |
689 _instantiator); | 678 _nativeMixinInstantiated(_reflectedType, _instantiator); |
690 if (mixinType == null) { | 679 if (mixinType == null) { |
691 // The reflectee is not a mixin application. | 680 // The reflectee is not a mixin application. |
692 _mixin = this; | 681 _mixin = this; |
693 } else { | 682 } else { |
694 _mixin = reflectType(mixinType); | 683 _mixin = reflectType(mixinType); |
695 } | 684 } |
696 } | 685 } |
697 } | 686 } |
698 return _mixin; | 687 return _mixin; |
699 } | 688 } |
(...skipping 24 matching lines...) Expand all Loading... |
724 } | 713 } |
725 | 714 |
726 var _cachedInstanceMembers; | 715 var _cachedInstanceMembers; |
727 Map<Symbol, MethodMirror> get instanceMembers { | 716 Map<Symbol, MethodMirror> get instanceMembers { |
728 if (_cachedInstanceMembers == null) { | 717 if (_cachedInstanceMembers == null) { |
729 var result = new Map<Symbol, MethodMirror>(); | 718 var result = new Map<Symbol, MethodMirror>(); |
730 if (superclass != null) { | 719 if (superclass != null) { |
731 result.addAll(superclass.instanceMembers); | 720 result.addAll(superclass.instanceMembers); |
732 } | 721 } |
733 declarations.values.forEach((decl) { | 722 declarations.values.forEach((decl) { |
734 if (decl is MethodMirror && !decl.isStatic && | 723 if (decl is MethodMirror && |
735 !decl.isConstructor && !decl.isAbstract) { | 724 !decl.isStatic && |
| 725 !decl.isConstructor && |
| 726 !decl.isAbstract) { |
736 result[decl.simpleName] = decl; | 727 result[decl.simpleName] = decl; |
737 } | 728 } |
738 if (decl is VariableMirror && !decl.isStatic) { | 729 if (decl is VariableMirror && !decl.isStatic) { |
739 var getterName = decl.simpleName; | 730 var getterName = decl.simpleName; |
740 result[getterName] = | 731 result[getterName] = new _SyntheticAccessor( |
741 new _SyntheticAccessor(this, getterName, true, false, false, decl)
; | 732 this, getterName, true, false, false, decl); |
742 if (!decl.isFinal) { | 733 if (!decl.isFinal) { |
743 var setterName = _asSetter(decl.simpleName, this.owner); | 734 var setterName = _asSetter(decl.simpleName, this.owner); |
744 result[setterName] = new _SyntheticAccessor( | 735 result[setterName] = new _SyntheticAccessor( |
745 this, setterName, false, false, false, decl); | 736 this, setterName, false, false, false, decl); |
746 } | 737 } |
747 } | 738 } |
748 }); | 739 }); |
749 _cachedInstanceMembers = | 740 _cachedInstanceMembers = |
750 new UnmodifiableMapView<Symbol, MethodMirror>(result); | 741 new UnmodifiableMapView<Symbol, MethodMirror>(result); |
751 } | 742 } |
752 return _cachedInstanceMembers; | 743 return _cachedInstanceMembers; |
753 } | 744 } |
754 | 745 |
755 Map<Symbol, DeclarationMirror> _declarations; | 746 Map<Symbol, DeclarationMirror> _declarations; |
756 Map<Symbol, DeclarationMirror> get declarations { | 747 Map<Symbol, DeclarationMirror> get declarations { |
757 if (_declarations != null) return _declarations; | 748 if (_declarations != null) return _declarations; |
758 | 749 |
759 var decls = new Map<Symbol, DeclarationMirror>(); | 750 var decls = new Map<Symbol, DeclarationMirror>(); |
760 | 751 |
761 var whoseMembers = _isMixinAlias ? _trueSuperclass : this; | 752 var whoseMembers = _isMixinAlias ? _trueSuperclass : this; |
762 var members = mixin._computeMembers(_instantiator, | 753 var members = |
763 whoseMembers.mixin._reflectee); | 754 mixin._computeMembers(_instantiator, whoseMembers.mixin._reflectee); |
764 for (var member in members) { | 755 for (var member in members) { |
765 decls[member.simpleName] = member; | 756 decls[member.simpleName] = member; |
766 } | 757 } |
767 | 758 |
768 var constructors = _computeConstructors(_instantiator, _reflectee); | 759 var constructors = _computeConstructors(_instantiator, _reflectee); |
769 var stringName = _n(simpleName); | 760 var stringName = _n(simpleName); |
770 for (var constructor in constructors) { | 761 for (var constructor in constructors) { |
771 constructor._patchConstructorName(stringName); | 762 constructor._patchConstructorName(stringName); |
772 decls[constructor.simpleName] = constructor; | 763 decls[constructor.simpleName] = constructor; |
773 } | 764 } |
774 | 765 |
775 for (var typeVariable in typeVariables) { | 766 for (var typeVariable in typeVariables) { |
776 decls[typeVariable.simpleName] = typeVariable; | 767 decls[typeVariable.simpleName] = typeVariable; |
777 } | 768 } |
778 | 769 |
779 return _declarations = | 770 return _declarations = |
780 new UnmodifiableMapView<Symbol, DeclarationMirror>(decls); | 771 new UnmodifiableMapView<Symbol, DeclarationMirror>(decls); |
781 } | 772 } |
782 | 773 |
783 bool get _isAnonymousMixinApplication { | 774 bool get _isAnonymousMixinApplication { |
784 if (_isMixinAlias) return false; // Named mixin application. | 775 if (_isMixinAlias) return false; // Named mixin application. |
785 if (mixin == this) return false; // Not a mixin application. | 776 if (mixin == this) return false; // Not a mixin application. |
786 return true; | 777 return true; |
787 } | 778 } |
788 | 779 |
789 List<TypeVariableMirror> _typeVariables = null; | 780 List<TypeVariableMirror> _typeVariables = null; |
790 List<TypeVariableMirror> get typeVariables { | 781 List<TypeVariableMirror> get typeVariables { |
791 if (_typeVariables == null) { | 782 if (_typeVariables == null) { |
792 if (_isAnonymousMixinApplication) return _typeVariables = _emptyList; | 783 if (_isAnonymousMixinApplication) return _typeVariables = _emptyList; |
793 _typeVariables = new List<TypeVariableMirror>(); | 784 _typeVariables = new List<TypeVariableMirror>(); |
794 | 785 |
795 List params = _ClassMirror_type_variables(_reflectee); | 786 List params = _ClassMirror_type_variables(_reflectee); |
796 ClassMirror owner = originalDeclaration; | 787 ClassMirror owner = originalDeclaration; |
797 var mirror; | 788 var mirror; |
798 for (var i = 0; i < params.length; i += 2) { | 789 for (var i = 0; i < params.length; i += 2) { |
799 mirror = new _LocalTypeVariableMirror( | 790 mirror = new _LocalTypeVariableMirror(params[i + 1], params[i], owner); |
800 params[i + 1], params[i], owner); | |
801 _typeVariables.add(mirror); | 791 _typeVariables.add(mirror); |
802 } | 792 } |
803 _typeVariables = new UnmodifiableListView(_typeVariables); | 793 _typeVariables = new UnmodifiableListView(_typeVariables); |
804 } | 794 } |
805 return _typeVariables; | 795 return _typeVariables; |
806 } | 796 } |
807 | 797 |
808 List<TypeMirror> _typeArguments = null; | 798 List<TypeMirror> _typeArguments = null; |
809 List<TypeMirror> get typeArguments { | 799 List<TypeMirror> get typeArguments { |
810 if(_typeArguments == null) { | 800 if (_typeArguments == null) { |
811 if(_isGenericDeclaration || _isAnonymousMixinApplication) { | 801 if (_isGenericDeclaration || _isAnonymousMixinApplication) { |
812 _typeArguments = _emptyList; | 802 _typeArguments = _emptyList; |
813 } else { | 803 } else { |
814 _typeArguments = | 804 _typeArguments = |
815 new UnmodifiableListView(_computeTypeArguments(_reflectedType)); | 805 new UnmodifiableListView(_computeTypeArguments(_reflectedType)); |
816 } | 806 } |
817 } | 807 } |
818 return _typeArguments; | 808 return _typeArguments; |
819 } | 809 } |
820 | 810 |
821 bool get isOriginalDeclaration => !_isGeneric || _isGenericDeclaration; | 811 bool get isOriginalDeclaration => !_isGeneric || _isGenericDeclaration; |
822 | 812 |
823 ClassMirror get originalDeclaration { | 813 ClassMirror get originalDeclaration { |
824 if (isOriginalDeclaration) { | 814 if (isOriginalDeclaration) { |
825 return this; | 815 return this; |
826 } else { | 816 } else { |
827 return reflectClass(_reflectedType); | 817 return reflectClass(_reflectedType); |
828 } | 818 } |
829 } | 819 } |
830 | 820 |
831 String toString() => "ClassMirror on '${MirrorSystem.getName(simpleName)}'"; | 821 String toString() => "ClassMirror on '${MirrorSystem.getName(simpleName)}'"; |
832 | 822 |
833 InstanceMirror newInstance(Symbol constructorName, | 823 InstanceMirror newInstance(Symbol constructorName, List positionalArguments, |
834 List positionalArguments, | 824 [Map<Symbol, dynamic> namedArguments]) { |
835 [Map<Symbol, dynamic> namedArguments]) { | |
836 // Native code will add the 1 or 2 implicit arguments depending on whether | 825 // Native code will add the 1 or 2 implicit arguments depending on whether |
837 // we end up invoking a factory or constructor respectively. | 826 // we end up invoking a factory or constructor respectively. |
838 int numPositionalArguments = positionalArguments.length; | 827 int numPositionalArguments = positionalArguments.length; |
839 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; | 828 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; |
840 int numArguments = numPositionalArguments + numNamedArguments; | 829 int numArguments = numPositionalArguments + numNamedArguments; |
841 List arguments = new List(numArguments); | 830 List arguments = new List(numArguments); |
842 arguments.setRange(0, numPositionalArguments, positionalArguments); | 831 arguments.setRange(0, numPositionalArguments, positionalArguments); |
843 List names = new List(numNamedArguments); | 832 List names = new List(numNamedArguments); |
844 int argumentIndex = numPositionalArguments; | 833 int argumentIndex = numPositionalArguments; |
845 int nameIndex = 0; | 834 int nameIndex = 0; |
846 if (numNamedArguments > 0) { | 835 if (numNamedArguments > 0) { |
847 namedArguments.forEach((name, value) { | 836 namedArguments.forEach((name, value) { |
848 arguments[argumentIndex++] = value; | 837 arguments[argumentIndex++] = value; |
849 names[nameIndex++] = _n(name); | 838 names[nameIndex++] = _n(name); |
850 }); | 839 }); |
851 } | 840 } |
852 | 841 |
853 return reflect(_invokeConstructor(_reflectee, | 842 return reflect(_invokeConstructor( |
854 _reflectedType, | 843 _reflectee, _reflectedType, _n(constructorName), arguments, names)); |
855 _n(constructorName), | |
856 arguments, | |
857 names)); | |
858 } | 844 } |
859 | 845 |
860 List<InstanceMirror> get metadata { | 846 List<InstanceMirror> get metadata { |
861 // Get the metadata objects, convert them into InstanceMirrors using | 847 // Get the metadata objects, convert them into InstanceMirrors using |
862 // reflect() and then make them into a Dart list. | 848 // reflect() and then make them into a Dart list. |
863 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); | 849 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); |
864 } | 850 } |
865 | 851 |
866 bool operator ==(other) { | 852 bool operator ==(other) { |
867 return this.runtimeType == other.runtimeType && | 853 return this.runtimeType == other.runtimeType && |
868 this._reflectee == other._reflectee && | 854 this._reflectee == other._reflectee && |
869 this._reflectedType == other._reflectedType && | 855 this._reflectedType == other._reflectedType && |
870 this._isGenericDeclaration == other._isGenericDeclaration; | 856 this._isGenericDeclaration == other._isGenericDeclaration; |
871 } | 857 } |
872 | 858 |
873 int get hashCode => simpleName.hashCode; | 859 int get hashCode => simpleName.hashCode; |
874 | 860 |
875 bool isSubtypeOf(TypeMirror other) { | 861 bool isSubtypeOf(TypeMirror other) { |
876 if (other == currentMirrorSystem().dynamicType) return true; | 862 if (other == currentMirrorSystem().dynamicType) return true; |
877 if (other == currentMirrorSystem().voidType) return false; | 863 if (other == currentMirrorSystem().voidType) return false; |
878 return _subtypeTest(_reflectedType, other._reflectedType); | 864 return _subtypeTest(_reflectedType, other._reflectedType); |
879 } | 865 } |
880 | 866 |
881 bool isAssignableTo(TypeMirror other) { | 867 bool isAssignableTo(TypeMirror other) { |
882 if (other == currentMirrorSystem().dynamicType) return true; | 868 if (other == currentMirrorSystem().dynamicType) return true; |
883 if (other == currentMirrorSystem().voidType) return false; | 869 if (other == currentMirrorSystem().voidType) return false; |
884 return _subtypeTest(_reflectedType, other._reflectedType) | 870 return _subtypeTest(_reflectedType, other._reflectedType) || |
885 || _subtypeTest(other._reflectedType, _reflectedType); | 871 _subtypeTest(other._reflectedType, _reflectedType); |
886 } | 872 } |
887 | 873 |
888 bool isSubclassOf(ClassMirror other) { | 874 bool isSubclassOf(ClassMirror other) { |
889 if (other is! ClassMirror) throw new ArgumentError(other); | 875 if (other is! ClassMirror) throw new ArgumentError(other); |
890 ClassMirror otherDeclaration = other.originalDeclaration; | 876 ClassMirror otherDeclaration = other.originalDeclaration; |
891 ClassMirror c = this; | 877 ClassMirror c = this; |
892 while (c != null) { | 878 while (c != null) { |
893 c = c.originalDeclaration; | 879 c = c.originalDeclaration; |
894 if (c == otherDeclaration) return true; | 880 if (c == otherDeclaration) return true; |
895 c = c.superclass; | 881 c = c.superclass; |
896 } | 882 } |
897 return false; | 883 return false; |
898 } | 884 } |
899 | 885 |
900 static _libraryUri(reflectee) | 886 static _libraryUri(reflectee) native "ClassMirror_libraryUri"; |
901 native "ClassMirror_libraryUri"; | |
902 | 887 |
903 static _supertype(reflectedType) | 888 static _supertype(reflectedType) native "ClassMirror_supertype"; |
904 native "ClassMirror_supertype"; | |
905 | 889 |
906 static _supertypeInstantiated(reflectedType) | 890 static _supertypeInstantiated(reflectedType) |
907 native "ClassMirror_supertype_instantiated"; | 891 native "ClassMirror_supertype_instantiated"; |
908 | 892 |
909 static _nativeInterfaces(reflectedType) | 893 static _nativeInterfaces(reflectedType) native "ClassMirror_interfaces"; |
910 native "ClassMirror_interfaces"; | |
911 | 894 |
912 static _nativeInterfacesInstantiated(reflectedType) | 895 static _nativeInterfacesInstantiated(reflectedType) |
913 native "ClassMirror_interfaces_instantiated"; | 896 native "ClassMirror_interfaces_instantiated"; |
914 | 897 |
915 static _nativeMixin(reflectedType) | 898 static _nativeMixin(reflectedType) native "ClassMirror_mixin"; |
916 native "ClassMirror_mixin"; | |
917 | 899 |
918 static _nativeMixinInstantiated(reflectedType, instantiator) | 900 static _nativeMixinInstantiated(reflectedType, instantiator) |
919 native "ClassMirror_mixin_instantiated"; | 901 native "ClassMirror_mixin_instantiated"; |
920 | 902 |
921 _computeMembers(reflectee, instantiator) | 903 _computeMembers(reflectee, instantiator) native "ClassMirror_members"; |
922 native "ClassMirror_members"; | |
923 | 904 |
924 _computeConstructors(reflectee, instantiator) | 905 _computeConstructors(reflectee, instantiator) |
925 native "ClassMirror_constructors"; | 906 native "ClassMirror_constructors"; |
926 | 907 |
927 _invoke(reflectee, memberName, arguments, argumentNames) | 908 _invoke(reflectee, memberName, arguments, argumentNames) |
928 native 'ClassMirror_invoke'; | 909 native 'ClassMirror_invoke'; |
929 | 910 |
930 _invokeGetter(reflectee, getterName) | 911 _invokeGetter(reflectee, getterName) native 'ClassMirror_invokeGetter'; |
931 native 'ClassMirror_invokeGetter'; | |
932 | 912 |
933 _invokeSetter(reflectee, setterName, value) | 913 _invokeSetter(reflectee, setterName, value) native 'ClassMirror_invokeSetter'; |
934 native 'ClassMirror_invokeSetter'; | |
935 | 914 |
936 static _invokeConstructor(reflectee, type, constructorName, arguments, argumen
tNames) | 915 static _invokeConstructor(reflectee, type, constructorName, arguments, |
937 native 'ClassMirror_invokeConstructor'; | 916 argumentNames) native 'ClassMirror_invokeConstructor'; |
938 | 917 |
939 static _ClassMirror_type_variables(reflectee) | 918 static _ClassMirror_type_variables(reflectee) |
940 native "ClassMirror_type_variables"; | 919 native "ClassMirror_type_variables"; |
941 | 920 |
942 static _computeTypeArguments(reflectee) | 921 static _computeTypeArguments(reflectee) native "ClassMirror_type_arguments"; |
943 native "ClassMirror_type_arguments"; | |
944 } | 922 } |
945 | 923 |
946 class _LocalFunctionTypeMirror extends _LocalClassMirror | 924 class _LocalFunctionTypeMirror extends _LocalClassMirror |
947 implements FunctionTypeMirror { | 925 implements FunctionTypeMirror { |
948 final _functionReflectee; | 926 final _functionReflectee; |
949 _LocalFunctionTypeMirror(reflectee, this._functionReflectee, reflectedType) | 927 _LocalFunctionTypeMirror(reflectee, this._functionReflectee, reflectedType) |
950 : super(reflectee, reflectedType, null, null, false, false, false, false,
false); | 928 : super(reflectee, reflectedType, null, null, false, false, false, false, |
| 929 false); |
951 | 930 |
952 bool get _isAnonymousMixinApplication => false; | 931 bool get _isAnonymousMixinApplication => false; |
953 | 932 |
954 // FunctionTypeMirrors have a simpleName generated from their signature. | 933 // FunctionTypeMirrors have a simpleName generated from their signature. |
955 Symbol _simpleName = null; | 934 Symbol _simpleName = null; |
956 Symbol get simpleName { | 935 Symbol get simpleName { |
957 if (_simpleName == null) { | 936 if (_simpleName == null) { |
958 _simpleName = _s(_makeSignatureString(returnType, parameters)); | 937 _simpleName = _s(_makeSignatureString(returnType, parameters)); |
959 } | 938 } |
960 return _simpleName; | 939 return _simpleName; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 } | 1008 } |
1030 | 1009 |
1031 List<InstanceMirror> get metadata { | 1010 List<InstanceMirror> get metadata { |
1032 // Get the metadata objects, convert them into InstanceMirrors using | 1011 // Get the metadata objects, convert them into InstanceMirrors using |
1033 // reflect() and then make them into a Dart list. | 1012 // reflect() and then make them into a Dart list. |
1034 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); | 1013 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); |
1035 } | 1014 } |
1036 | 1015 |
1037 bool operator ==(other) { | 1016 bool operator ==(other) { |
1038 return this.runtimeType == other.runtimeType && | 1017 return this.runtimeType == other.runtimeType && |
1039 this._reflectee == other._reflectee; | 1018 this._reflectee == other._reflectee; |
1040 } | 1019 } |
1041 | 1020 |
1042 int get hashCode => simpleName.hashCode; | 1021 int get hashCode => simpleName.hashCode; |
1043 } | 1022 } |
1044 | 1023 |
1045 class _LocalTypeVariableMirror extends _LocalDeclarationMirror | 1024 class _LocalTypeVariableMirror extends _LocalDeclarationMirror |
1046 implements TypeVariableMirror { | 1025 implements TypeVariableMirror { |
1047 _LocalTypeVariableMirror(reflectee, | 1026 _LocalTypeVariableMirror(reflectee, String simpleName, this._owner) |
1048 String simpleName, | |
1049 this._owner) | |
1050 : super(reflectee, _s(simpleName)); | 1027 : super(reflectee, _s(simpleName)); |
1051 | 1028 |
1052 DeclarationMirror _owner; | 1029 DeclarationMirror _owner; |
1053 DeclarationMirror get owner { | 1030 DeclarationMirror get owner { |
1054 if (_owner == null) { | 1031 if (_owner == null) { |
1055 _owner = _TypeVariableMirror_owner(_reflectee).originalDeclaration; | 1032 _owner = _TypeVariableMirror_owner(_reflectee).originalDeclaration; |
1056 } | 1033 } |
1057 return _owner; | 1034 return _owner; |
1058 } | 1035 } |
1059 | 1036 |
1060 bool get isStatic => false; | 1037 bool get isStatic => false; |
1061 bool get isTopLevel => false; | 1038 bool get isTopLevel => false; |
1062 | 1039 |
1063 TypeMirror _upperBound = null; | 1040 TypeMirror _upperBound = null; |
1064 TypeMirror get upperBound { | 1041 TypeMirror get upperBound { |
1065 if (_upperBound == null) { | 1042 if (_upperBound == null) { |
1066 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee)); | 1043 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee)); |
1067 } | 1044 } |
1068 return _upperBound; | 1045 return _upperBound; |
1069 } | 1046 } |
1070 | 1047 |
1071 bool get hasReflectedType => false; | 1048 bool get hasReflectedType => false; |
1072 Type get reflectedType { | 1049 Type get reflectedType { |
1073 throw new UnsupportedError('Type variables have no reflected type'); | 1050 throw new UnsupportedError('Type variables have no reflected type'); |
1074 } | 1051 } |
| 1052 |
1075 Type get _reflectedType => _reflectee; | 1053 Type get _reflectedType => _reflectee; |
1076 | 1054 |
1077 List<TypeVariableMirror> get typeVariables => _emptyList; | 1055 List<TypeVariableMirror> get typeVariables => _emptyList; |
1078 List<TypeMirror> get typeArguments => _emptyList; | 1056 List<TypeMirror> get typeArguments => _emptyList; |
1079 | 1057 |
1080 bool get isOriginalDeclaration => true; | 1058 bool get isOriginalDeclaration => true; |
1081 TypeMirror get originalDeclaration => this; | 1059 TypeMirror get originalDeclaration => this; |
1082 | 1060 |
1083 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; | 1061 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; |
1084 | 1062 |
1085 operator ==(other) { | 1063 operator ==(other) { |
1086 return other is TypeVariableMirror | 1064 return other is TypeVariableMirror && |
1087 && simpleName == other.simpleName | 1065 simpleName == other.simpleName && |
1088 && owner == other.owner; | 1066 owner == other.owner; |
1089 } | 1067 } |
| 1068 |
1090 int get hashCode => simpleName.hashCode; | 1069 int get hashCode => simpleName.hashCode; |
1091 | 1070 |
1092 bool isSubtypeOf(TypeMirror other) { | 1071 bool isSubtypeOf(TypeMirror other) { |
1093 if (other == currentMirrorSystem().dynamicType) return true; | 1072 if (other == currentMirrorSystem().dynamicType) return true; |
1094 if (other == currentMirrorSystem().voidType) return false; | 1073 if (other == currentMirrorSystem().voidType) return false; |
1095 return _subtypeTest(_reflectedType, other._reflectedType); | 1074 return _subtypeTest(_reflectedType, other._reflectedType); |
1096 } | 1075 } |
1097 | 1076 |
1098 bool isAssignableTo(TypeMirror other) { | 1077 bool isAssignableTo(TypeMirror other) { |
1099 if (other == currentMirrorSystem().dynamicType) return true; | 1078 if (other == currentMirrorSystem().dynamicType) return true; |
1100 if (other == currentMirrorSystem().voidType) return false; | 1079 if (other == currentMirrorSystem().voidType) return false; |
1101 return _subtypeTest(_reflectedType, other._reflectedType) | 1080 return _subtypeTest(_reflectedType, other._reflectedType) || |
1102 || _subtypeTest(other._reflectedType, _reflectedType); | 1081 _subtypeTest(other._reflectedType, _reflectedType); |
1103 } | 1082 } |
1104 | 1083 |
1105 static DeclarationMirror _TypeVariableMirror_owner(reflectee) | 1084 static DeclarationMirror _TypeVariableMirror_owner(reflectee) |
1106 native "TypeVariableMirror_owner"; | 1085 native "TypeVariableMirror_owner"; |
1107 | 1086 |
1108 static Type _TypeVariableMirror_upper_bound(reflectee) | 1087 static Type _TypeVariableMirror_upper_bound(reflectee) |
1109 native "TypeVariableMirror_upper_bound"; | 1088 native "TypeVariableMirror_upper_bound"; |
1110 } | 1089 } |
1111 | 1090 |
1112 | |
1113 class _LocalTypedefMirror extends _LocalDeclarationMirror | 1091 class _LocalTypedefMirror extends _LocalDeclarationMirror |
1114 implements TypedefMirror { | 1092 implements TypedefMirror { |
1115 final Type _reflectedType; | 1093 final Type _reflectedType; |
1116 final bool _isGeneric; | 1094 final bool _isGeneric; |
1117 final bool _isGenericDeclaration; | 1095 final bool _isGenericDeclaration; |
1118 | 1096 |
1119 _LocalTypedefMirror(reflectee, | 1097 _LocalTypedefMirror(reflectee, this._reflectedType, String simpleName, |
1120 this._reflectedType, | 1098 this._isGeneric, this._isGenericDeclaration, this._owner) |
1121 String simpleName, | |
1122 this._isGeneric, | |
1123 this._isGenericDeclaration, | |
1124 this._owner) | |
1125 : super(reflectee, _s(simpleName)); | 1099 : super(reflectee, _s(simpleName)); |
1126 | 1100 |
1127 bool get isTopLevel => true; | 1101 bool get isTopLevel => true; |
1128 | 1102 |
1129 DeclarationMirror _owner; | 1103 DeclarationMirror _owner; |
1130 DeclarationMirror get owner { | 1104 DeclarationMirror get owner { |
1131 if (_owner == null) { | 1105 if (_owner == null) { |
1132 var uri = _LocalClassMirror._libraryUri(_reflectee); | 1106 var uri = _LocalClassMirror._libraryUri(_reflectee); |
1133 _owner = currentMirrorSystem().libraries[Uri.parse(uri)]; | 1107 _owner = currentMirrorSystem().libraries[Uri.parse(uri)]; |
1134 } | 1108 } |
(...skipping 29 matching lines...) Expand all Loading... |
1164 } | 1138 } |
1165 | 1139 |
1166 List<TypeVariableMirror> _typeVariables = null; | 1140 List<TypeVariableMirror> _typeVariables = null; |
1167 List<TypeVariableMirror> get typeVariables { | 1141 List<TypeVariableMirror> get typeVariables { |
1168 if (_typeVariables == null) { | 1142 if (_typeVariables == null) { |
1169 _typeVariables = new List<TypeVariableMirror>(); | 1143 _typeVariables = new List<TypeVariableMirror>(); |
1170 List params = _LocalClassMirror._ClassMirror_type_variables(_reflectee); | 1144 List params = _LocalClassMirror._ClassMirror_type_variables(_reflectee); |
1171 TypedefMirror owner = originalDeclaration; | 1145 TypedefMirror owner = originalDeclaration; |
1172 var mirror; | 1146 var mirror; |
1173 for (var i = 0; i < params.length; i += 2) { | 1147 for (var i = 0; i < params.length; i += 2) { |
1174 mirror = new _LocalTypeVariableMirror( | 1148 mirror = new _LocalTypeVariableMirror(params[i + 1], params[i], owner); |
1175 params[i + 1], params[i], owner); | |
1176 _typeVariables.add(mirror); | 1149 _typeVariables.add(mirror); |
1177 } | 1150 } |
1178 } | 1151 } |
1179 return _typeVariables; | 1152 return _typeVariables; |
1180 } | 1153 } |
1181 | 1154 |
1182 List<TypeMirror> _typeArguments = null; | 1155 List<TypeMirror> _typeArguments = null; |
1183 List<TypeMirror> get typeArguments { | 1156 List<TypeMirror> get typeArguments { |
1184 if(_typeArguments == null) { | 1157 if (_typeArguments == null) { |
1185 if(_isGenericDeclaration) { | 1158 if (_isGenericDeclaration) { |
1186 _typeArguments = _emptyList; | 1159 _typeArguments = _emptyList; |
1187 } else { | 1160 } else { |
1188 _typeArguments = new UnmodifiableListView( | 1161 _typeArguments = new UnmodifiableListView( |
1189 _LocalClassMirror._computeTypeArguments(_reflectedType)); | 1162 _LocalClassMirror._computeTypeArguments(_reflectedType)); |
1190 } | 1163 } |
1191 } | 1164 } |
1192 return _typeArguments; | 1165 return _typeArguments; |
1193 } | 1166 } |
1194 | 1167 |
1195 String toString() => "TypedefMirror on '${_n(simpleName)}'"; | 1168 String toString() => "TypedefMirror on '${_n(simpleName)}'"; |
1196 | 1169 |
1197 bool isSubtypeOf(TypeMirror other) { | 1170 bool isSubtypeOf(TypeMirror other) { |
1198 if (other == currentMirrorSystem().dynamicType) return true; | 1171 if (other == currentMirrorSystem().dynamicType) return true; |
1199 if (other == currentMirrorSystem().voidType) return false; | 1172 if (other == currentMirrorSystem().voidType) return false; |
1200 return _subtypeTest(_reflectedType, other._reflectedType); | 1173 return _subtypeTest(_reflectedType, other._reflectedType); |
1201 } | 1174 } |
1202 | 1175 |
1203 bool isAssignableTo(TypeMirror other) { | 1176 bool isAssignableTo(TypeMirror other) { |
1204 if (other == currentMirrorSystem().dynamicType) return true; | 1177 if (other == currentMirrorSystem().dynamicType) return true; |
1205 if (other == currentMirrorSystem().voidType) return false; | 1178 if (other == currentMirrorSystem().voidType) return false; |
1206 return _subtypeTest(_reflectedType, other._reflectedType) | 1179 return _subtypeTest(_reflectedType, other._reflectedType) || |
1207 || _subtypeTest(other._reflectedType, _reflectedType); | 1180 _subtypeTest(other._reflectedType, _reflectedType); |
1208 } | 1181 } |
1209 | 1182 |
1210 static _nativeReferent(reflectedType) | 1183 static _nativeReferent(reflectedType) native "TypedefMirror_referent"; |
1211 native "TypedefMirror_referent"; | |
1212 | 1184 |
1213 static _nativeDeclaration(reflectedType) | 1185 static _nativeDeclaration(reflectedType) native "TypedefMirror_declaration"; |
1214 native "TypedefMirror_declaration"; | |
1215 } | 1186 } |
1216 | 1187 |
1217 Symbol _asSetter(Symbol getter, LibraryMirror library) { | 1188 Symbol _asSetter(Symbol getter, LibraryMirror library) { |
1218 var unwrapped = MirrorSystem.getName(getter); | 1189 var unwrapped = MirrorSystem.getName(getter); |
1219 return MirrorSystem.getSymbol('${unwrapped}=', library); | 1190 return MirrorSystem.getSymbol('${unwrapped}=', library); |
1220 } | 1191 } |
1221 | 1192 |
1222 class _LocalLibraryMirror extends _LocalObjectMirror implements LibraryMirror { | 1193 class _LocalLibraryMirror extends _LocalObjectMirror implements LibraryMirror { |
1223 final Symbol simpleName; | 1194 final Symbol simpleName; |
1224 final Uri uri; | 1195 final Uri uri; |
1225 | 1196 |
1226 _LocalLibraryMirror(reflectee, | 1197 _LocalLibraryMirror(reflectee, String simpleName, String url) |
1227 String simpleName, | |
1228 String url) | |
1229 : this.simpleName = _s(simpleName), | 1198 : this.simpleName = _s(simpleName), |
1230 this.uri = Uri.parse(url), | 1199 this.uri = Uri.parse(url), |
1231 super(reflectee); | 1200 super(reflectee); |
1232 | 1201 |
1233 // The simple name and the qualified name are the same for a library. | 1202 // The simple name and the qualified name are the same for a library. |
1234 Symbol get qualifiedName => simpleName; | 1203 Symbol get qualifiedName => simpleName; |
1235 | 1204 |
1236 DeclarationMirror get owner => null; | 1205 DeclarationMirror get owner => null; |
1237 | 1206 |
1238 bool get isPrivate => false; | 1207 bool get isPrivate => false; |
(...skipping 20 matching lines...) Expand all Loading... |
1259 } | 1228 } |
1260 | 1229 |
1261 List<InstanceMirror> get metadata { | 1230 List<InstanceMirror> get metadata { |
1262 // Get the metadata objects, convert them into InstanceMirrors using | 1231 // Get the metadata objects, convert them into InstanceMirrors using |
1263 // reflect() and then make them into a Dart list. | 1232 // reflect() and then make them into a Dart list. |
1264 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); | 1233 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); |
1265 } | 1234 } |
1266 | 1235 |
1267 bool operator ==(other) { | 1236 bool operator ==(other) { |
1268 return this.runtimeType == other.runtimeType && | 1237 return this.runtimeType == other.runtimeType && |
1269 this._reflectee == other._reflectee; | 1238 this._reflectee == other._reflectee; |
1270 } | 1239 } |
1271 | 1240 |
1272 int get hashCode => simpleName.hashCode; | 1241 int get hashCode => simpleName.hashCode; |
1273 | 1242 |
1274 String toString() => "LibraryMirror on '${_n(simpleName)}'"; | 1243 String toString() => "LibraryMirror on '${_n(simpleName)}'"; |
1275 | 1244 |
1276 var _cachedLibraryDependencies; | 1245 var _cachedLibraryDependencies; |
1277 get libraryDependencies { | 1246 get libraryDependencies { |
1278 if (_cachedLibraryDependencies == null) { | 1247 if (_cachedLibraryDependencies == null) { |
1279 _cachedLibraryDependencies = _libraryDependencies(_reflectee); | 1248 _cachedLibraryDependencies = _libraryDependencies(_reflectee); |
1280 } | 1249 } |
1281 return _cachedLibraryDependencies; | 1250 return _cachedLibraryDependencies; |
1282 } | 1251 } |
1283 | 1252 |
1284 _libraryDependencies(reflectee) | 1253 _libraryDependencies(reflectee) native 'LibraryMirror_libraryDependencies'; |
1285 native 'LibraryMirror_libraryDependencies'; | |
1286 | 1254 |
1287 _invoke(reflectee, memberName, arguments, argumentNames) | 1255 _invoke(reflectee, memberName, arguments, argumentNames) |
1288 native 'LibraryMirror_invoke'; | 1256 native 'LibraryMirror_invoke'; |
1289 | 1257 |
1290 _invokeGetter(reflectee, getterName) | 1258 _invokeGetter(reflectee, getterName) native 'LibraryMirror_invokeGetter'; |
1291 native 'LibraryMirror_invokeGetter'; | |
1292 | 1259 |
1293 _invokeSetter(reflectee, setterName, value) | 1260 _invokeSetter(reflectee, setterName, value) |
1294 native 'LibraryMirror_invokeSetter'; | 1261 native 'LibraryMirror_invokeSetter'; |
1295 | 1262 |
1296 _computeMembers(reflectee) | 1263 _computeMembers(reflectee) native "LibraryMirror_members"; |
1297 native "LibraryMirror_members"; | |
1298 } | 1264 } |
1299 | 1265 |
1300 class _LocalLibraryDependencyMirror | 1266 class _LocalLibraryDependencyMirror extends _LocalMirror |
1301 extends _LocalMirror implements LibraryDependencyMirror { | 1267 implements LibraryDependencyMirror { |
1302 final LibraryMirror sourceLibrary; | 1268 final LibraryMirror sourceLibrary; |
1303 var _targetMirrorOrPrefix; | 1269 var _targetMirrorOrPrefix; |
1304 final List<CombinatorMirror> combinators; | 1270 final List<CombinatorMirror> combinators; |
1305 final Symbol prefix; | 1271 final Symbol prefix; |
1306 final bool isImport; | 1272 final bool isImport; |
1307 final bool isDeferred; | 1273 final bool isDeferred; |
1308 final List<InstanceMirror> metadata; | 1274 final List<InstanceMirror> metadata; |
1309 | 1275 |
1310 _LocalLibraryDependencyMirror(this.sourceLibrary, | 1276 _LocalLibraryDependencyMirror( |
1311 this._targetMirrorOrPrefix, | 1277 this.sourceLibrary, |
1312 this.combinators, | 1278 this._targetMirrorOrPrefix, |
1313 prefixString, | 1279 this.combinators, |
1314 this.isImport, | 1280 prefixString, |
1315 this.isDeferred, | 1281 this.isImport, |
1316 unwrappedMetadata) | 1282 this.isDeferred, |
| 1283 unwrappedMetadata) |
1317 : prefix = _s(prefixString), | 1284 : prefix = _s(prefixString), |
1318 metadata = new UnmodifiableListView(unwrappedMetadata.map(reflect)); | 1285 metadata = new UnmodifiableListView(unwrappedMetadata.map(reflect)); |
1319 | 1286 |
1320 bool get isExport => !isImport; | 1287 bool get isExport => !isImport; |
1321 | 1288 |
1322 LibraryMirror get targetLibrary { | 1289 LibraryMirror get targetLibrary { |
1323 if (_targetMirrorOrPrefix is _LocalLibraryMirror) { | 1290 if (_targetMirrorOrPrefix is _LocalLibraryMirror) { |
1324 return _targetMirrorOrPrefix; | 1291 return _targetMirrorOrPrefix; |
1325 } | 1292 } |
1326 var mirrorOrNull = _tryUpgradePrefix(_targetMirrorOrPrefix); | 1293 var mirrorOrNull = _tryUpgradePrefix(_targetMirrorOrPrefix); |
(...skipping 25 matching lines...) Expand all Loading... |
1352 | 1319 |
1353 bool get isHide => !isShow; | 1320 bool get isHide => !isShow; |
1354 } | 1321 } |
1355 | 1322 |
1356 class _LocalMethodMirror extends _LocalDeclarationMirror | 1323 class _LocalMethodMirror extends _LocalDeclarationMirror |
1357 implements MethodMirror { | 1324 implements MethodMirror { |
1358 final Type _instantiator; | 1325 final Type _instantiator; |
1359 final bool isStatic; | 1326 final bool isStatic; |
1360 final int _kindFlags; | 1327 final int _kindFlags; |
1361 | 1328 |
1362 _LocalMethodMirror(reflectee, | 1329 _LocalMethodMirror(reflectee, String simpleName, this._owner, |
1363 String simpleName, | 1330 this._instantiator, this.isStatic, this._kindFlags) |
1364 this._owner, | |
1365 this._instantiator, | |
1366 this.isStatic, | |
1367 this._kindFlags) | |
1368 : super(reflectee, _s(simpleName)); | 1331 : super(reflectee, _s(simpleName)); |
1369 | 1332 |
1370 static const kAbstract = 0; | 1333 static const kAbstract = 0; |
1371 static const kGetter = 1; | 1334 static const kGetter = 1; |
1372 static const kSetter = 2; | 1335 static const kSetter = 2; |
1373 static const kConstructor = 3; | 1336 static const kConstructor = 3; |
1374 static const kConstCtor = 4; | 1337 static const kConstCtor = 4; |
1375 static const kGenerativeCtor = 5; | 1338 static const kGenerativeCtor = 5; |
1376 static const kRedirectingCtor = 6; | 1339 static const kRedirectingCtor = 6; |
1377 static const kFactoryCtor = 7; | 1340 static const kFactoryCtor = 7; |
1378 static const kExternal = 8; | 1341 static const kExternal = 8; |
1379 | 1342 |
1380 // These offsets much be kept in sync with those in mirrors.h. | 1343 // These offsets much be kept in sync with those in mirrors.h. |
1381 bool get isAbstract => 0 != (_kindFlags & (1 << kAbstract)); | 1344 bool get isAbstract => 0 != (_kindFlags & (1 << kAbstract)); |
1382 bool get isGetter => 0 != (_kindFlags & (1 << kGetter)); | 1345 bool get isGetter => 0 != (_kindFlags & (1 << kGetter)); |
1383 bool get isSetter => 0 != (_kindFlags & (1 << kSetter)); | 1346 bool get isSetter => 0 != (_kindFlags & (1 << kSetter)); |
1384 bool get isConstructor => 0 != (_kindFlags & (1 << kConstructor)); | 1347 bool get isConstructor => 0 != (_kindFlags & (1 << kConstructor)); |
1385 bool get isConstConstructor => 0 != (_kindFlags & (1 << kConstCtor)); | 1348 bool get isConstConstructor => 0 != (_kindFlags & (1 << kConstCtor)); |
1386 bool get isGenerativeConstructor => 0 != (_kindFlags & (1 << kGenerativeCtor)
); | 1349 bool get isGenerativeConstructor => |
1387 bool get isRedirectingConstructor => 0 != (_kindFlags & (1 << kRedirectingCtor
)); | 1350 0 != (_kindFlags & (1 << kGenerativeCtor)); |
1388 bool get isFactoryConstructor => 0 != (_kindFlags & (1 << kFactoryCtor)); | 1351 bool get isRedirectingConstructor => |
1389 bool get isExternal => 0 != (_kindFlags & (1 << kExternal)); | 1352 0 != (_kindFlags & (1 << kRedirectingCtor)); |
| 1353 bool get isFactoryConstructor => 0 != (_kindFlags & (1 << kFactoryCtor)); |
| 1354 bool get isExternal => 0 != (_kindFlags & (1 << kExternal)); |
1390 | 1355 |
1391 static const _operators = const ["%", "&", "*", "+", "-", "/", "<", "<<", | 1356 static const _operators = const [ |
1392 "<=", "==", ">", ">=", ">>", "[]", "[]=", "^", "|", "~", "unary-", "~/"]; | 1357 "%", "&", "*", "+", "-", "/", "<", "<<", // |
| 1358 "<=", "==", ">", ">=", ">>", "[]", "[]=", |
| 1359 "^", "|", "~", "unary-", "~/", |
| 1360 ]; |
1393 bool get isOperator => _operators.contains(_n(simpleName)); | 1361 bool get isOperator => _operators.contains(_n(simpleName)); |
1394 | 1362 |
1395 DeclarationMirror _owner; | 1363 DeclarationMirror _owner; |
1396 DeclarationMirror get owner { | 1364 DeclarationMirror get owner { |
1397 // For nested closures it is possible, that the mirror for the owner has not | 1365 // For nested closures it is possible, that the mirror for the owner has not |
1398 // been created yet. | 1366 // been created yet. |
1399 if (_owner == null) { | 1367 if (_owner == null) { |
1400 _owner = _MethodMirror_owner(_reflectee, _instantiator); | 1368 _owner = _MethodMirror_owner(_reflectee, _instantiator); |
1401 } | 1369 } |
1402 return _owner; | 1370 return _owner; |
1403 } | 1371 } |
1404 | 1372 |
1405 bool get isPrivate => _n(simpleName).startsWith('_') || | 1373 bool get isPrivate => |
1406 _n(constructorName).startsWith('_'); | 1374 _n(simpleName).startsWith('_') || _n(constructorName).startsWith('_'); |
1407 | 1375 |
1408 bool get isTopLevel => owner is LibraryMirror; | 1376 bool get isTopLevel => owner is LibraryMirror; |
1409 bool get isSynthetic => false; | 1377 bool get isSynthetic => false; |
1410 | 1378 |
1411 TypeMirror _returnType = null; | 1379 TypeMirror _returnType = null; |
1412 TypeMirror get returnType { | 1380 TypeMirror get returnType { |
1413 if (_returnType == null) { | 1381 if (_returnType == null) { |
1414 if (isConstructor) { | 1382 if (isConstructor) { |
1415 _returnType = owner; | 1383 _returnType = owner; |
1416 } else { | 1384 } else { |
1417 _returnType = reflectType( | 1385 _returnType = |
1418 _MethodMirror_return_type(_reflectee, _instantiator)); | 1386 reflectType(_MethodMirror_return_type(_reflectee, _instantiator)); |
1419 } | 1387 } |
1420 } | 1388 } |
1421 return _returnType; | 1389 return _returnType; |
1422 } | 1390 } |
1423 | 1391 |
1424 List<ParameterMirror> _parameters = null; | 1392 List<ParameterMirror> _parameters = null; |
1425 List<ParameterMirror> get parameters { | 1393 List<ParameterMirror> get parameters { |
1426 if (_parameters == null) { | 1394 if (_parameters == null) { |
1427 _parameters = _MethodMirror_parameters(_reflectee); | 1395 _parameters = _MethodMirror_parameters(_reflectee); |
1428 _parameters = new UnmodifiableListView(_parameters); | 1396 _parameters = new UnmodifiableListView(_parameters); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 | 1437 |
1470 static dynamic _MethodMirror_owner(reflectee, instantiator) | 1438 static dynamic _MethodMirror_owner(reflectee, instantiator) |
1471 native "MethodMirror_owner"; | 1439 native "MethodMirror_owner"; |
1472 | 1440 |
1473 static dynamic _MethodMirror_return_type(reflectee, instantiator) | 1441 static dynamic _MethodMirror_return_type(reflectee, instantiator) |
1474 native "MethodMirror_return_type"; | 1442 native "MethodMirror_return_type"; |
1475 | 1443 |
1476 List<ParameterMirror> _MethodMirror_parameters(reflectee) | 1444 List<ParameterMirror> _MethodMirror_parameters(reflectee) |
1477 native "MethodMirror_parameters"; | 1445 native "MethodMirror_parameters"; |
1478 | 1446 |
1479 static String _MethodMirror_source(reflectee) | 1447 static String _MethodMirror_source(reflectee) native "MethodMirror_source"; |
1480 native "MethodMirror_source"; | |
1481 } | 1448 } |
1482 | 1449 |
1483 class _LocalVariableMirror extends _LocalDeclarationMirror | 1450 class _LocalVariableMirror extends _LocalDeclarationMirror |
1484 implements VariableMirror { | 1451 implements VariableMirror { |
1485 final DeclarationMirror owner; | 1452 final DeclarationMirror owner; |
1486 final bool isStatic; | 1453 final bool isStatic; |
1487 final bool isFinal; | 1454 final bool isFinal; |
1488 final bool isConst; | 1455 final bool isConst; |
1489 | 1456 |
1490 _LocalVariableMirror(reflectee, | 1457 _LocalVariableMirror(reflectee, String simpleName, this.owner, this._type, |
1491 String simpleName, | 1458 this.isStatic, this.isFinal, this.isConst) |
1492 this.owner, | |
1493 this._type, | |
1494 this.isStatic, | |
1495 this.isFinal, | |
1496 this.isConst) | |
1497 : super(reflectee, _s(simpleName)); | 1459 : super(reflectee, _s(simpleName)); |
1498 | 1460 |
1499 bool get isTopLevel => owner is LibraryMirror; | 1461 bool get isTopLevel => owner is LibraryMirror; |
1500 | 1462 |
1501 Type get _instantiator { | 1463 Type get _instantiator { |
1502 return owner._instantiator; | 1464 return owner._instantiator; |
1503 } | 1465 } |
1504 | 1466 |
1505 TypeMirror _type; | 1467 TypeMirror _type; |
1506 TypeMirror get type { | 1468 TypeMirror get type { |
1507 if (_type == null) { | 1469 if (_type == null) { |
1508 _type = reflectType(_VariableMirror_type(_reflectee, _instantiator)); | 1470 _type = reflectType(_VariableMirror_type(_reflectee, _instantiator)); |
1509 } | 1471 } |
1510 return _type; | 1472 return _type; |
1511 } | 1473 } |
1512 | 1474 |
1513 String toString() => "VariableMirror on '${MirrorSystem.getName(simpleName)}'"
; | 1475 String toString() => |
| 1476 "VariableMirror on '${MirrorSystem.getName(simpleName)}'"; |
1514 | 1477 |
1515 static _VariableMirror_type(reflectee, instantiator) | 1478 static _VariableMirror_type(reflectee, instantiator) |
1516 native "VariableMirror_type"; | 1479 native "VariableMirror_type"; |
1517 } | 1480 } |
1518 | 1481 |
1519 class _LocalParameterMirror extends _LocalVariableMirror | 1482 class _LocalParameterMirror extends _LocalVariableMirror |
1520 implements ParameterMirror { | 1483 implements ParameterMirror { |
1521 final int _position; | 1484 final int _position; |
1522 final bool isOptional; | 1485 final bool isOptional; |
1523 final bool isNamed; | 1486 final bool isNamed; |
1524 final List _unmirroredMetadata; | 1487 final List _unmirroredMetadata; |
1525 | 1488 |
1526 _LocalParameterMirror(reflectee, | 1489 _LocalParameterMirror( |
1527 String simpleName, | 1490 reflectee, |
1528 DeclarationMirror owner, | 1491 String simpleName, |
1529 this._position, | 1492 DeclarationMirror owner, |
1530 this.isOptional, | 1493 this._position, |
1531 this.isNamed, | 1494 this.isOptional, |
1532 bool isFinal, | 1495 this.isNamed, |
1533 this._defaultValueReflectee, | 1496 bool isFinal, |
1534 this._unmirroredMetadata) | 1497 this._defaultValueReflectee, |
1535 : super(reflectee, | 1498 this._unmirroredMetadata) |
1536 simpleName, | 1499 : super( |
1537 owner, | 1500 reflectee, |
1538 null, // We override the type. | 1501 simpleName, |
1539 false, // isStatic does not apply. | 1502 owner, |
1540 isFinal, | 1503 null, // We override the type. |
1541 false // Not const. | 1504 false, // isStatic does not apply. |
1542 ); | 1505 isFinal, |
| 1506 false // Not const. |
| 1507 ); |
1543 | 1508 |
1544 Object _defaultValueReflectee; | 1509 Object _defaultValueReflectee; |
1545 InstanceMirror _defaultValue; | 1510 InstanceMirror _defaultValue; |
1546 InstanceMirror get defaultValue { | 1511 InstanceMirror get defaultValue { |
1547 if (!isOptional) { | 1512 if (!isOptional) { |
1548 return null; | 1513 return null; |
1549 } | 1514 } |
1550 if (_defaultValue == null) { | 1515 if (_defaultValue == null) { |
1551 _defaultValue = reflect(_defaultValueReflectee); | 1516 _defaultValue = reflect(_defaultValueReflectee); |
1552 } | 1517 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 _instantiationCache[key] = typeMirror; | 1641 _instantiationCache[key] = typeMirror; |
1677 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1642 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
1678 _declarationCache[key] = typeMirror; | 1643 _declarationCache[key] = typeMirror; |
1679 } | 1644 } |
1680 } | 1645 } |
1681 return typeMirror; | 1646 return typeMirror; |
1682 } | 1647 } |
1683 | 1648 |
1684 static Type _instantiateType(Type key, List<Type> typeArguments) { | 1649 static Type _instantiateType(Type key, List<Type> typeArguments) { |
1685 if (typeArguments.isEmpty) { | 1650 if (typeArguments.isEmpty) { |
1686 throw new ArgumentError.value( | 1651 throw new ArgumentError.value(typeArguments, 'typeArguments', |
1687 typeArguments, 'typeArguments', 'Type arguments list cannot be empty.'); | 1652 'Type arguments list cannot be empty.'); |
1688 } | 1653 } |
1689 return instantiateGenericType(key, typeArguments.toList(growable: false)); | 1654 return instantiateGenericType(key, typeArguments.toList(growable: false)); |
1690 } | 1655 } |
1691 } | 1656 } |
OLD | NEW |