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 part of serialization; | 5 part of serialization; |
6 | 6 |
7 // TODO(alanknight): Figure out how to reasonably separate out the things | 7 // TODO(alanknight): Figure out how to reasonably separate out the things |
8 // that require reflection without making the API more awkward. Or if that is | 8 // that require reflection without making the API more awkward. Or if that is |
9 // in fact necessary. Maybe the tree-shaking will just remove it if unused. | 9 // in fact necessary. Maybe the tree-shaking will just remove it if unused. |
10 | 10 |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 * using [setFieldWith]. | 368 * using [setFieldWith]. |
369 */ | 369 */ |
370 bool get isEssential => super.isEssential || customSetter != null; | 370 bool get isEssential => super.isEssential || customSetter != null; |
371 | 371 |
372 /** Set the [value] of our field in the given mirrored [object]. */ | 372 /** Set the [value] of our field in the given mirrored [object]. */ |
373 void setValue(InstanceMirror object, value) { | 373 void setValue(InstanceMirror object, value) { |
374 setter(object, value); | 374 setter(object, value); |
375 } | 375 } |
376 | 376 |
377 valueIn(InstanceMirror mirror) => | 377 valueIn(InstanceMirror mirror) => |
378 deprecatedFutureValue(mirror.getField(name)).reflectee; | 378 deprecatedFutureValue(mirror.getFieldAsync(name)).reflectee; |
379 | 379 |
380 /** Return the function to use to set our value. */ | 380 /** Return the function to use to set our value. */ |
381 Function get setter => | 381 Function get setter => |
382 (customSetter != null) ? customSetter : defaultSetter; | 382 (customSetter != null) ? customSetter : defaultSetter; |
383 | 383 |
384 /** Return a default setter function. */ | 384 /** Return a default setter function. */ |
385 void defaultSetter(InstanceMirror object, value) { | 385 void defaultSetter(InstanceMirror object, value) { |
386 object.setField(name, reflect(value)); | 386 object.setFieldAsync(name, reflect(value)); |
387 } | 387 } |
388 | 388 |
389 String toString() => 'Field($name)'; | 389 String toString() => 'Field($name)'; |
390 } | 390 } |
391 | 391 |
392 /** | 392 /** |
393 * This represents a constant value that will be passed as a constructor | 393 * This represents a constant value that will be passed as a constructor |
394 * parameter. Rather than having a name it has a constant value. | 394 * parameter. Rather than having a name it has a constant value. |
395 */ | 395 */ |
396 class _ConstantField extends _Field { | 396 class _ConstantField extends _Field { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 } | 608 } |
609 | 609 |
610 /** | 610 /** |
611 * Find the field values in [state] and pass them to the constructor. | 611 * Find the field values in [state] and pass them to the constructor. |
612 * If any of [fieldNumbers] is not an int, then use it as a literal value. | 612 * If any of [fieldNumbers] is not an int, then use it as a literal value. |
613 */ | 613 */ |
614 constructFrom(state, Reader r) { | 614 constructFrom(state, Reader r) { |
615 // TODO(alanknight): Handle named parameters | 615 // TODO(alanknight): Handle named parameters |
616 Iterable inflated = fieldNumbers.map( | 616 Iterable inflated = fieldNumbers.map( |
617 (x) => (x is int) ? reflect(r.inflateReference(state[x])) : reflect(x)); | 617 (x) => (x is int) ? reflect(r.inflateReference(state[x])) : reflect(x)); |
618 var result = type.newInstance(name, inflated.toList()); | 618 var result = type.newInstanceAsync(name, inflated.toList()); |
619 return deprecatedFutureValue(result); | 619 return deprecatedFutureValue(result); |
620 } | 620 } |
621 } | 621 } |
622 | 622 |
623 /** | 623 /** |
624 * This wraps a map to make it indexable by integer field numbers. It translates | 624 * This wraps a map to make it indexable by integer field numbers. It translates |
625 * from the index into a field name and then looks it up in the map. | 625 * from the index into a field name and then looks it up in the map. |
626 */ | 626 */ |
627 class _MapWrapper { | 627 class _MapWrapper { |
628 final _map; | 628 final _map; |
629 List fieldList; | 629 List fieldList; |
630 _MapWrapper(this.fieldList) : _map = new Map(); | 630 _MapWrapper(this.fieldList) : _map = new Map(); |
631 _MapWrapper.fromMap(this._map, this.fieldList); | 631 _MapWrapper.fromMap(this._map, this.fieldList); |
632 | 632 |
633 operator [](key) => _map[fieldList[key].name]; | 633 operator [](key) => _map[fieldList[key].name]; |
634 | 634 |
635 operator []=(key, value) { _map[fieldList[key].name] = value; } | 635 operator []=(key, value) { _map[fieldList[key].name] = value; } |
636 get length => _map.length; | 636 get length => _map.length; |
637 | 637 |
638 asMap() => _map; | 638 asMap() => _map; |
639 } | 639 } |
OLD | NEW |