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

Unified Diff: lib/message_generator.dart

Issue 813373003: Protobuf changes for smaller dart2js code, Int64 fixes (Closed) Base URL: https://github.com/dart-lang/dart-protoc-plugin@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 | « no previous file | lib/protobuf_field.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/message_generator.dart
diff --git a/lib/message_generator.dart b/lib/message_generator.dart
index f6cff19ce426d6332839c61b6652150cf8f18311..35a3ddffe7ac21e4827112fcefbd3466017f31ab 100644
--- a/lib/message_generator.dart
+++ b/lib/message_generator.dart
@@ -105,8 +105,10 @@ class MessageGenerator extends ProtobufContainer {
makeDefault = field.initializationForPackage(package);
}
String subBuilder = null;
+ String subBuilderRepeated = null;
if (field.message || field.group) {
- subBuilder = '()${SP}=>${SP}new ${fieldType}()';
+ subBuilder = '${fieldType}.create';
+ subBuilderRepeated = '${fieldType}.createRepeated';
}
String valueOf = null;
if (field.enm) {
@@ -116,7 +118,7 @@ class MessageGenerator extends ProtobufContainer {
// Repeated message: default is an empty list
out.println('..m(${field.number},${SP}'
'\'${field.externalFieldName}\',${SP}$subBuilder,'
- '${SP}()${SP}=>${SP}new PbList<${fieldType}>())');
+ '${SP}$subBuilderRepeated)');
} else if (type[0] == 'P' && type != 'PG' && type != 'PE') {
// Repeated, not a message or enum: default is an empty list,
// subBuilder is null, valueOf is null.
@@ -172,6 +174,12 @@ class MessageGenerator extends ProtobufContainer {
out.println('BuilderInfo get info_${SP}=>${SP}_i;');
+ // Factory functions which can be used as default value closures.
+ out.println('static ${classname}${SP}create()${SP}=>'
+ '${SP}new ${classname}();');
+ out.println('static PbList<${classname}>${SP}createRepeated()${SP}=>'
+ '${SP}new PbList<${classname}>();');
+
generateFieldsAccessorsMutators(out);
});
out.println();
« no previous file with comments | « no previous file | lib/protobuf_field.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698