Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Unified Diff: pkg/serialization/lib/src/basic_rule.dart

Issue 22375012: pkg/serialization updates (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: a bit more Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/serialization/lib/serialization.dart ('k') | pkg/serialization/lib/src/serialization_rule.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/serialization/lib/src/basic_rule.dart
diff --git a/pkg/serialization/lib/src/basic_rule.dart b/pkg/serialization/lib/src/basic_rule.dart
index 927f3167673d307132ee2e17f48292f706384a51..005580a53f978b95e703111e6962bafb66bdd584 100644
--- a/pkg/serialization/lib/src/basic_rule.dart
+++ b/pkg/serialization/lib/src/basic_rule.dart
@@ -25,10 +25,10 @@ class BasicRule extends SerializationRule {
final ClassMirror type;
/** Used to create new objects when reading. */
- Constructor constructor;
+ final Constructor constructor;
/** This holds onto our list of fields, and can also calculate them. */
- _FieldList _fields;
+ final _FieldList _fields;
/**
* Instances can either use maps or lists to hold the object's state. The list
@@ -58,12 +58,23 @@ class BasicRule extends SerializationRule {
* [excludeFields] lets you tell it to find the fields automatically, but
* omit some that would otherwise be included.
*/
- BasicRule(ClassMirror this.type, String constructorName,
- List constructorFields, List regularFields,
- List excludeFields) {
- _findFields(constructorFields, regularFields, excludeFields);
- constructor = new Constructor(
- type, constructorName, _fields.constructorFieldIndices());
+ factory BasicRule(ClassMirror type, String constructorName,
+ List constructorFields, List regularFields, List excludeFields) {
+
+ var fields = new _FieldList(type);
+ fields.constructorFields = constructorFields;
+ fields.regular = regularFields;
+ // TODO(alanknight): The order of this matters. It shouldn't.
+ fields.exclude = excludeFields;
+ fields.figureOutFields();
+
+ var constructor = new Constructor(type, constructorName,
+ fields.constructorFieldIndices());
+
+ return new BasicRule._(type, constructor, fields);
+ }
+
+ BasicRule._(this.type, this.constructor, this._fields) {
configureForLists();
}
@@ -243,20 +254,6 @@ class BasicRule extends SerializationRule {
// TODO(alanknight): This seems likely to be slow. Verify. Other options?
bool appliesTo(object, Writer w) => reflect(object).type == type;
- /**
- * Given the various field lists provided by the user, construct the list
- * of field names that we want.
- */
- void _findFields(List constructorFields, List regularFields,
- List excludeFields) {
- _fields = new _FieldList(type);
- _fields.constructorFields = constructorFields;
- _fields.regular = regularFields;
- // TODO(alanknight): The order of this matters. It shouldn't.
- _fields.exclude = excludeFields;
- _fields.figureOutFields();
- }
-
bool get hasVariableLengthEntries => false;
int get dataLength => _fields.length;
« no previous file with comments | « pkg/serialization/lib/serialization.dart ('k') | pkg/serialization/lib/src/serialization_rule.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698