| 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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 * that are listed in the constructor fields. | 567 * that are listed in the constructor fields. |
| 568 */ | 568 */ |
| 569 void figureOutFields() { | 569 void figureOutFields() { |
| 570 Iterable names(Iterable<DeclarationMirror> mirrors) => | 570 Iterable names(Iterable<DeclarationMirror> mirrors) => |
| 571 mirrors.map((each) => each.simpleName).toList(); | 571 mirrors.map((each) => each.simpleName).toList(); |
| 572 | 572 |
| 573 if (!_shouldFigureOutFields || !regularFields().isEmpty) return; | 573 if (!_shouldFigureOutFields || !regularFields().isEmpty) return; |
| 574 var fields = publicFields(mirror); | 574 var fields = publicFields(mirror); |
| 575 var getters = publicGetters(mirror); | 575 var getters = publicGetters(mirror); |
| 576 var gettersWithSetters = getters.where( (each) | 576 var gettersWithSetters = getters.where( (each) |
| 577 => mirror.setters[ | 577 => mirror.declarations[ |
| 578 new Symbol("${MirrorSystem.getName(each.simpleName)}=")] != null); | 578 new Symbol("${MirrorSystem.getName(each.simpleName)}=")] != null); |
| 579 var gettersThatMatchConstructor = getters.where((each) | 579 var gettersThatMatchConstructor = getters.where((each) |
| 580 => (named(each.simpleName) != null) && | 580 => (named(each.simpleName) != null) && |
| 581 (named(each.simpleName).usedInConstructor)).toList(); | 581 (named(each.simpleName).usedInConstructor)).toList(); |
| 582 addAllNotExplicitlyExcluded(names(fields)); | 582 addAllNotExplicitlyExcluded(names(fields)); |
| 583 addAllNotExplicitlyExcluded(names(gettersWithSetters)); | 583 addAllNotExplicitlyExcluded(names(gettersWithSetters)); |
| 584 addAllNotExplicitlyExcluded(names(gettersThatMatchConstructor)); | 584 addAllNotExplicitlyExcluded(names(gettersThatMatchConstructor)); |
| 585 } | 585 } |
| 586 | 586 |
| 587 toString() => "FieldList($contents)"; | 587 toString() => "FieldList($contents)"; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 } | 623 } |
| 624 | 624 |
| 625 /** | 625 /** |
| 626 * Find the field values in [state] and pass them to the constructor. | 626 * Find the field values in [state] and pass them to the constructor. |
| 627 * If any of [fieldNumbers] is not an int, then use it as a literal value. | 627 * If any of [fieldNumbers] is not an int, then use it as a literal value. |
| 628 */ | 628 */ |
| 629 constructFrom(state, Reader r) { | 629 constructFrom(state, Reader r) { |
| 630 // TODO(alanknight): Handle named parameters | 630 // TODO(alanknight): Handle named parameters |
| 631 Iterable inflated = fieldNumbers.map( | 631 Iterable inflated = fieldNumbers.map( |
| 632 (x) => (x is int) ? r.inflateReference(state[x]) : x); | 632 (x) => (x is int) ? r.inflateReference(state[x]) : x); |
| 633 var result; | 633 return type.newInstance(nameSymbol, inflated.toList()); |
| 634 try { | |
| 635 result = type.newInstance(nameSymbol, inflated.toList()); | |
| 636 } on MirroredError catch (e) { | |
| 637 // Mirrored "compile-time" errors do not get treated as exceptions | |
| 638 // in the debugger, so explicitly re-throw. Issue dartbug.com/10054. | |
| 639 throw e; | |
| 640 } | |
| 641 return result; | |
| 642 } | 634 } |
| 643 } | 635 } |
| 644 | 636 |
| 645 /** | 637 /** |
| 646 * This wraps a map to make it indexable by integer field numbers. It translates | 638 * This wraps a map to make it indexable by integer field numbers. It translates |
| 647 * from the index into a field name and then looks it up in the map. | 639 * from the index into a field name and then looks it up in the map. |
| 648 */ | 640 */ |
| 649 class _MapWrapper { | 641 class _MapWrapper { |
| 650 final Map _map; | 642 final Map _map; |
| 651 final List fieldList; | 643 final List fieldList; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 670 if (value is String) { | 662 if (value is String) { |
| 671 try { | 663 try { |
| 672 return new Symbol(value); | 664 return new Symbol(value); |
| 673 } on ArgumentError { | 665 } on ArgumentError { |
| 674 return null; | 666 return null; |
| 675 }; | 667 }; |
| 676 } else { | 668 } else { |
| 677 return null; | 669 return null; |
| 678 } | 670 } |
| 679 } | 671 } |
| OLD | NEW |