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

Unified Diff: lib/src/protobuf/field_info.dart

Issue 814213003: Allow constants as field initial values as well as creation thunks (Closed) Base URL: https://github.com/dart-lang/dart-protobuf@master
Patch Set: Created 6 years 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 | « lib/src/protobuf/extension.dart ('k') | lib/src/protobuf/generated_message.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/protobuf/field_info.dart
diff --git a/lib/src/protobuf/field_info.dart b/lib/src/protobuf/field_info.dart
index d46f1a48a1cd9453debac8a3d8c84b1491ee7188..a26c1ee2d9421942c45e63c36129ad51d183e86d 100644
--- a/lib/src/protobuf/field_info.dart
+++ b/lib/src/protobuf/field_info.dart
@@ -16,12 +16,17 @@ class FieldInfo {
final ValueOfFunc valueOf;
FieldInfo(this.name, this.tagNumber, int type,
- [MakeDefaultFunc makeDefault,
+ [dynamic defaultOrMaker,
this.subBuilder,
this.valueOf])
: this.type = type,
- this.makeDefault = makeDefault == null ?
- GeneratedMessage._defaultForType(type) : makeDefault;
+ this.makeDefault = findMakeDefault(type, defaultOrMaker);
+
+ static MakeDefaultFunc findMakeDefault(int type, dynamic defaultOrMaker) {
+ if (defaultOrMaker == null) return GeneratedMessage._defaultForType(type);
+ if (defaultOrMaker is MakeDefaultFunc) return defaultOrMaker;
+ return () => defaultOrMaker;
+ }
String toString() => name;
}
« no previous file with comments | « lib/src/protobuf/extension.dart ('k') | lib/src/protobuf/generated_message.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698