diff --git a/lib/message_generator.dart b/lib/message_generator.dart index f6cff19..35a3ddf 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(); diff --git a/lib/protobuf_field.dart b/lib/protobuf_field.dart index ca6d4d2..dfe5ec8 100644 --- a/lib/protobuf_field.dart +++ b/lib/protobuf_field.dart @@ -139,7 +139,7 @@ class ProtobufField { codedStreamType = 'Bool'; if (!repeats) { if (field.hasDefaultValue() && 'false' != field.defaultValue) { - initialization = '()${SP}=>${SP}${field.defaultValue}'; + initialization = '${field.defaultValue}'; } } break; @@ -155,19 +155,18 @@ class ProtobufField { if (field.hasDefaultValue() && ('0.0' != field.defaultValue || '0' != field.defaultValue)) { if (field.defaultValue == 'inf') { - initialization = '()${SP}=>${SP}double.INFINITY'; + initialization = 'double.INFINITY'; } else if (field.defaultValue == '-inf') { - initialization = '()${SP}=>${SP}double.NEGATIVE_INFINITY'; + initialization = 'double.NEGATIVE_INFINITY'; } else if (field.defaultValue == 'nan') { - initialization = '()${SP}=>${SP}double.NAN'; + initialization = 'double.NAN'; } else if (HEX_LITERAL_REGEX.hasMatch(field.defaultValue)) { - initialization = '()${SP}=>${SP}(${field.defaultValue})' - '.toDouble()'; + initialization = '(${field.defaultValue}).toDouble()'; } else if (INTEGER_LITERAL_REGEX.hasMatch(field.defaultValue)) { - initialization = '()${SP}=>${SP}${field.defaultValue}.0'; + initialization = '${field.defaultValue}.0'; } else if (DECIMAL_LITERAL_REGEX_A.hasMatch(field.defaultValue) || DECIMAL_LITERAL_REGEX_B.hasMatch(field.defaultValue)) { - initialization = '()${SP}=>${SP}${field.defaultValue}'; + initialization = '${field.defaultValue}'; } else { throw new InvalidDefaultValue.double( field.name, field.defaultValue); @@ -202,7 +201,7 @@ class ProtobufField { } if (!repeats) { if (field.hasDefaultValue() && '0' != field.defaultValue) { - initialization = '()${SP}=>${SP}${field.defaultValue}'; + initialization = '${field.defaultValue}'; } } break; @@ -234,7 +233,11 @@ class ProtobufField { if (!repeats) { final defaultValue = field.hasDefaultValue() ? field.defaultValue : '0'; - initialization = '()${SP}=>${SP}makeLongInt($defaultValue)'; + if (defaultValue == '0') { + initialization = 'Int64.ZERO'; + } else { + initialization = "parseLongInt('$defaultValue')"; + } } break; case FieldDescriptorProto_Type.TYPE_STRING: @@ -244,7 +247,7 @@ class ProtobufField { if (!repeats) { if (field.hasDefaultValue() && !field.defaultValue.isEmpty) { String defaultValue = field.defaultValue.replaceAll(r'$', r'\$'); - initialization = '()${SP}=>${SP}\'$defaultValue\''; + initialization = '\'$defaultValue\''; } } break; @@ -277,8 +280,8 @@ class ProtobufField { } else { throw 'FAILURE: Unknown group type reference ${field.typeName}'; } - initialization = '()${SP}=>${SP}new ${baseType}()'; - prefixedInitialization = '()${SP}=>${SP}new ${prefixedBaseType}()'; + initialization = '${baseType}.create'; + prefixedInitialization = '${prefixedBaseType}.create'; break; case FieldDescriptorProto_Type.TYPE_MESSAGE: ProtobufContainer messageType = context[field.typeName]; @@ -296,8 +299,8 @@ class ProtobufField { } else { throw 'FAILURE: Unknown message type reference ${field.typeName}'; } - initialization = '()${SP}=>${SP}new ${baseType}()'; - prefixedInitialization = '()${SP}=>${SP}new ${prefixedBaseType}()'; + initialization = '${baseType}.create'; + prefixedInitialization = '${prefixedBaseType}.create'; break; case FieldDescriptorProto_Type.TYPE_ENUM: EnumGenerator enumType = context[field.typeName]; @@ -316,16 +319,14 @@ class ProtobufField { if (!repeats) { if (field.hasDefaultValue() && !field.defaultValue.isEmpty) { initialization = - '()${SP}=>${SP}${baseType}.${field.defaultValue}'; + '${baseType}.${field.defaultValue}'; prefixedInitialization = - '()${SP}=>${SP}${prefixedBaseType}.${field.defaultValue}'; + '${prefixedBaseType}.${field.defaultValue}'; } else if (!enumType._canonicalValues.isEmpty) { initialization = - '()${SP}=>${SP}${baseType}.' - '${enumType._canonicalValues[0].name}'; + '${baseType}.${enumType._canonicalValues[0].name}'; prefixedInitialization = - '()${SP}=>${SP}${prefixedBaseType}.' - '${enumType._canonicalValues[0].name}'; + '${prefixedBaseType}.${enumType._canonicalValues[0].name}'; } } } else { diff --git a/lib/src/descriptor.pb.dart b/lib/src/descriptor.pb.dart index 373dcd8..c7e8c24 100644 --- a/lib/src/descriptor.pb.dart +++ b/lib/src/descriptor.pb.dart @@ -8,7 +8,7 @@ import 'package:protobuf/protobuf.dart'; class FileDescriptorSet extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('FileDescriptorSet') - ..m(1, 'file', () => new FileDescriptorProto(), () => new PbList()) + ..m(1, 'file', FileDescriptorProto.create, FileDescriptorProto.createRepeated) ; FileDescriptorSet() : super(); @@ -16,6 +16,8 @@ class FileDescriptorSet extends GeneratedMessage { FileDescriptorSet.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); FileDescriptorSet clone() => new FileDescriptorSet()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static FileDescriptorSet create() => new FileDescriptorSet(); + static PbList createRepeated() => new PbList(); List get file => getField(1); } @@ -27,12 +29,12 @@ class FileDescriptorProto extends GeneratedMessage { ..p(3, 'dependency', GeneratedMessage.PS) ..p(10, 'publicDependency', GeneratedMessage.P3) ..p(11, 'weakDependency', GeneratedMessage.P3) - ..m(4, 'messageType', () => new DescriptorProto(), () => new PbList()) - ..m(5, 'enumType', () => new EnumDescriptorProto(), () => new PbList()) - ..m(6, 'service', () => new ServiceDescriptorProto(), () => new PbList()) - ..m(7, 'extension', () => new FieldDescriptorProto(), () => new PbList()) - ..a(8, 'options', GeneratedMessage.OM, () => new FileOptions(), () => new FileOptions()) - ..a(9, 'sourceCodeInfo', GeneratedMessage.OM, () => new SourceCodeInfo(), () => new SourceCodeInfo()) + ..m(4, 'messageType', DescriptorProto.create, DescriptorProto.createRepeated) + ..m(5, 'enumType', EnumDescriptorProto.create, EnumDescriptorProto.createRepeated) + ..m(6, 'service', ServiceDescriptorProto.create, ServiceDescriptorProto.createRepeated) + ..m(7, 'extension', FieldDescriptorProto.create, FieldDescriptorProto.createRepeated) + ..a(8, 'options', GeneratedMessage.OM, FileOptions.create, FileOptions.create) + ..a(9, 'sourceCodeInfo', GeneratedMessage.OM, SourceCodeInfo.create, SourceCodeInfo.create) ; FileDescriptorProto() : super(); @@ -40,6 +42,8 @@ class FileDescriptorProto extends GeneratedMessage { FileDescriptorProto.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); FileDescriptorProto clone() => new FileDescriptorProto()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static FileDescriptorProto create() => new FileDescriptorProto(); + static PbList createRepeated() => new PbList(); String get name => getField(1); void set name(String v) { setField(1, v); } @@ -88,6 +92,8 @@ class DescriptorProto_ExtensionRange extends GeneratedMessage { DescriptorProto_ExtensionRange.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); DescriptorProto_ExtensionRange clone() => new DescriptorProto_ExtensionRange()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static DescriptorProto_ExtensionRange create() => new DescriptorProto_ExtensionRange(); + static PbList createRepeated() => new PbList(); int get start => getField(1); void set start(int v) { setField(1, v); } @@ -103,12 +109,12 @@ class DescriptorProto_ExtensionRange extends GeneratedMessage { class DescriptorProto extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('DescriptorProto') ..a(1, 'name', GeneratedMessage.OS) - ..m(2, 'field', () => new FieldDescriptorProto(), () => new PbList()) - ..m(6, 'extension', () => new FieldDescriptorProto(), () => new PbList()) - ..m(3, 'nestedType', () => new DescriptorProto(), () => new PbList()) - ..m(4, 'enumType', () => new EnumDescriptorProto(), () => new PbList()) - ..m(5, 'extensionRange', () => new DescriptorProto_ExtensionRange(), () => new PbList()) - ..a(7, 'options', GeneratedMessage.OM, () => new MessageOptions(), () => new MessageOptions()) + ..m(2, 'field', FieldDescriptorProto.create, FieldDescriptorProto.createRepeated) + ..m(6, 'extension', FieldDescriptorProto.create, FieldDescriptorProto.createRepeated) + ..m(3, 'nestedType', DescriptorProto.create, DescriptorProto.createRepeated) + ..m(4, 'enumType', EnumDescriptorProto.create, EnumDescriptorProto.createRepeated) + ..m(5, 'extensionRange', DescriptorProto_ExtensionRange.create, DescriptorProto_ExtensionRange.createRepeated) + ..a(7, 'options', GeneratedMessage.OM, MessageOptions.create, MessageOptions.create) ; DescriptorProto() : super(); @@ -116,6 +122,8 @@ class DescriptorProto extends GeneratedMessage { DescriptorProto.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); DescriptorProto clone() => new DescriptorProto()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static DescriptorProto create() => new DescriptorProto(); + static PbList createRepeated() => new PbList(); String get name => getField(1); void set name(String v) { setField(1, v); } @@ -206,12 +214,12 @@ class FieldDescriptorProto extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('FieldDescriptorProto') ..a(1, 'name', GeneratedMessage.OS) ..a(3, 'number', GeneratedMessage.O3) - ..e(4, 'label', GeneratedMessage.OE, () => FieldDescriptorProto_Label.LABEL_OPTIONAL, (var v) => FieldDescriptorProto_Label.valueOf(v)) - ..e(5, 'type', GeneratedMessage.OE, () => FieldDescriptorProto_Type.TYPE_DOUBLE, (var v) => FieldDescriptorProto_Type.valueOf(v)) + ..e(4, 'label', GeneratedMessage.OE, FieldDescriptorProto_Label.LABEL_OPTIONAL, (var v) => FieldDescriptorProto_Label.valueOf(v)) + ..e(5, 'type', GeneratedMessage.OE, FieldDescriptorProto_Type.TYPE_DOUBLE, (var v) => FieldDescriptorProto_Type.valueOf(v)) ..a(6, 'typeName', GeneratedMessage.OS) ..a(2, 'extendee', GeneratedMessage.OS) ..a(7, 'defaultValue', GeneratedMessage.OS) - ..a(8, 'options', GeneratedMessage.OM, () => new FieldOptions(), () => new FieldOptions()) + ..a(8, 'options', GeneratedMessage.OM, FieldOptions.create, FieldOptions.create) ; FieldDescriptorProto() : super(); @@ -219,6 +227,8 @@ class FieldDescriptorProto extends GeneratedMessage { FieldDescriptorProto.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); FieldDescriptorProto clone() => new FieldDescriptorProto()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static FieldDescriptorProto create() => new FieldDescriptorProto(); + static PbList createRepeated() => new PbList(); String get name => getField(1); void set name(String v) { setField(1, v); } @@ -264,8 +274,8 @@ class FieldDescriptorProto extends GeneratedMessage { class EnumDescriptorProto extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('EnumDescriptorProto') ..a(1, 'name', GeneratedMessage.OS) - ..m(2, 'value', () => new EnumValueDescriptorProto(), () => new PbList()) - ..a(3, 'options', GeneratedMessage.OM, () => new EnumOptions(), () => new EnumOptions()) + ..m(2, 'value', EnumValueDescriptorProto.create, EnumValueDescriptorProto.createRepeated) + ..a(3, 'options', GeneratedMessage.OM, EnumOptions.create, EnumOptions.create) ; EnumDescriptorProto() : super(); @@ -273,6 +283,8 @@ class EnumDescriptorProto extends GeneratedMessage { EnumDescriptorProto.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); EnumDescriptorProto clone() => new EnumDescriptorProto()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static EnumDescriptorProto create() => new EnumDescriptorProto(); + static PbList createRepeated() => new PbList(); String get name => getField(1); void set name(String v) { setField(1, v); } @@ -291,7 +303,7 @@ class EnumValueDescriptorProto extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('EnumValueDescriptorProto') ..a(1, 'name', GeneratedMessage.OS) ..a(2, 'number', GeneratedMessage.O3) - ..a(3, 'options', GeneratedMessage.OM, () => new EnumValueOptions(), () => new EnumValueOptions()) + ..a(3, 'options', GeneratedMessage.OM, EnumValueOptions.create, EnumValueOptions.create) ; EnumValueDescriptorProto() : super(); @@ -299,6 +311,8 @@ class EnumValueDescriptorProto extends GeneratedMessage { EnumValueDescriptorProto.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); EnumValueDescriptorProto clone() => new EnumValueDescriptorProto()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static EnumValueDescriptorProto create() => new EnumValueDescriptorProto(); + static PbList createRepeated() => new PbList(); String get name => getField(1); void set name(String v) { setField(1, v); } @@ -319,9 +333,9 @@ class EnumValueDescriptorProto extends GeneratedMessage { class ServiceDescriptorProto extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('ServiceDescriptorProto') ..a(1, 'name', GeneratedMessage.OS) - ..m(2, 'method', () => new MethodDescriptorProto(), () => new PbList()) - ..m(4, 'stream', () => new StreamDescriptorProto(), () => new PbList()) - ..a(3, 'options', GeneratedMessage.OM, () => new ServiceOptions(), () => new ServiceOptions()) + ..m(2, 'method', MethodDescriptorProto.create, MethodDescriptorProto.createRepeated) + ..m(4, 'stream', StreamDescriptorProto.create, StreamDescriptorProto.createRepeated) + ..a(3, 'options', GeneratedMessage.OM, ServiceOptions.create, ServiceOptions.create) ; ServiceDescriptorProto() : super(); @@ -329,6 +343,8 @@ class ServiceDescriptorProto extends GeneratedMessage { ServiceDescriptorProto.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); ServiceDescriptorProto clone() => new ServiceDescriptorProto()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static ServiceDescriptorProto create() => new ServiceDescriptorProto(); + static PbList createRepeated() => new PbList(); String get name => getField(1); void set name(String v) { setField(1, v); } @@ -350,7 +366,7 @@ class MethodDescriptorProto extends GeneratedMessage { ..a(1, 'name', GeneratedMessage.OS) ..a(2, 'inputType', GeneratedMessage.OS) ..a(3, 'outputType', GeneratedMessage.OS) - ..a(4, 'options', GeneratedMessage.OM, () => new MethodOptions(), () => new MethodOptions()) + ..a(4, 'options', GeneratedMessage.OM, MethodOptions.create, MethodOptions.create) ; MethodDescriptorProto() : super(); @@ -358,6 +374,8 @@ class MethodDescriptorProto extends GeneratedMessage { MethodDescriptorProto.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); MethodDescriptorProto clone() => new MethodDescriptorProto()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static MethodDescriptorProto create() => new MethodDescriptorProto(); + static PbList createRepeated() => new PbList(); String get name => getField(1); void set name(String v) { setField(1, v); } @@ -385,7 +403,7 @@ class StreamDescriptorProto extends GeneratedMessage { ..a(1, 'name', GeneratedMessage.OS) ..a(2, 'clientMessageType', GeneratedMessage.OS) ..a(3, 'serverMessageType', GeneratedMessage.OS) - ..a(4, 'options', GeneratedMessage.OM, () => new StreamOptions(), () => new StreamOptions()) + ..a(4, 'options', GeneratedMessage.OM, StreamOptions.create, StreamOptions.create) ; StreamDescriptorProto() : super(); @@ -393,6 +411,8 @@ class StreamDescriptorProto extends GeneratedMessage { StreamDescriptorProto.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); StreamDescriptorProto clone() => new StreamDescriptorProto()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static StreamDescriptorProto create() => new StreamDescriptorProto(); + static PbList createRepeated() => new PbList(); String get name => getField(1); void set name(String v) { setField(1, v); } @@ -438,11 +458,11 @@ class FileOptions extends GeneratedMessage { ..a(8, 'javaOuterClassname', GeneratedMessage.OS) ..a(10, 'javaMultipleFiles', GeneratedMessage.OB) ..a(20, 'javaGenerateEqualsAndHash', GeneratedMessage.OB) - ..e(9, 'optimizeFor', GeneratedMessage.OE, () => FileOptions_OptimizeMode.SPEED, (var v) => FileOptions_OptimizeMode.valueOf(v)) + ..e(9, 'optimizeFor', GeneratedMessage.OE, FileOptions_OptimizeMode.SPEED, (var v) => FileOptions_OptimizeMode.valueOf(v)) ..a(16, 'ccGenericServices', GeneratedMessage.OB) ..a(17, 'javaGenericServices', GeneratedMessage.OB) ..a(18, 'pyGenericServices', GeneratedMessage.OB) - ..m(999, 'uninterpretedOption', () => new UninterpretedOption(), () => new PbList()) + ..m(999, 'uninterpretedOption', UninterpretedOption.create, UninterpretedOption.createRepeated) ..hasExtensions = true ; @@ -451,6 +471,8 @@ class FileOptions extends GeneratedMessage { FileOptions.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); FileOptions clone() => new FileOptions()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static FileOptions create() => new FileOptions(); + static PbList createRepeated() => new PbList(); String get javaPackage => getField(1); void set javaPackage(String v) { setField(1, v); } @@ -499,7 +521,7 @@ class MessageOptions extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('MessageOptions') ..a(1, 'messageSetWireFormat', GeneratedMessage.OB) ..a(2, 'noStandardDescriptorAccessor', GeneratedMessage.OB) - ..m(999, 'uninterpretedOption', () => new UninterpretedOption(), () => new PbList()) + ..m(999, 'uninterpretedOption', UninterpretedOption.create, UninterpretedOption.createRepeated) ..hasExtensions = true ; @@ -508,6 +530,8 @@ class MessageOptions extends GeneratedMessage { MessageOptions.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); MessageOptions clone() => new MessageOptions()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static MessageOptions create() => new MessageOptions(); + static PbList createRepeated() => new PbList(); bool get messageSetWireFormat => getField(1); void set messageSetWireFormat(bool v) { setField(1, v); } @@ -537,12 +561,12 @@ class FieldOptions_CType extends ProtobufEnum { class FieldOptions extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('FieldOptions') - ..e(1, 'ctype', GeneratedMessage.OE, () => FieldOptions_CType.STRING, (var v) => FieldOptions_CType.valueOf(v)) + ..e(1, 'ctype', GeneratedMessage.OE, FieldOptions_CType.STRING, (var v) => FieldOptions_CType.valueOf(v)) ..a(2, 'packed', GeneratedMessage.OB) ..a(5, 'lazy', GeneratedMessage.OB) ..a(3, 'deprecated', GeneratedMessage.OB) ..a(9, 'experimentalMapKey', GeneratedMessage.OS) - ..m(999, 'uninterpretedOption', () => new UninterpretedOption(), () => new PbList()) + ..m(999, 'uninterpretedOption', UninterpretedOption.create, UninterpretedOption.createRepeated) ..hasExtensions = true ; @@ -551,6 +575,8 @@ class FieldOptions extends GeneratedMessage { FieldOptions.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); FieldOptions clone() => new FieldOptions()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static FieldOptions create() => new FieldOptions(); + static PbList createRepeated() => new PbList(); FieldOptions_CType get ctype => getField(1); void set ctype(FieldOptions_CType v) { setField(1, v); } @@ -582,8 +608,8 @@ class FieldOptions extends GeneratedMessage { class EnumOptions extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('EnumOptions') - ..a(2, 'allowAlias', GeneratedMessage.OB, () => true) - ..m(999, 'uninterpretedOption', () => new UninterpretedOption(), () => new PbList()) + ..a(2, 'allowAlias', GeneratedMessage.OB, true) + ..m(999, 'uninterpretedOption', UninterpretedOption.create, UninterpretedOption.createRepeated) ..hasExtensions = true ; @@ -592,6 +618,8 @@ class EnumOptions extends GeneratedMessage { EnumOptions.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); EnumOptions clone() => new EnumOptions()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static EnumOptions create() => new EnumOptions(); + static PbList createRepeated() => new PbList(); bool get allowAlias => getField(2); void set allowAlias(bool v) { setField(2, v); } @@ -603,7 +631,7 @@ class EnumOptions extends GeneratedMessage { class EnumValueOptions extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('EnumValueOptions') - ..m(999, 'uninterpretedOption', () => new UninterpretedOption(), () => new PbList()) + ..m(999, 'uninterpretedOption', UninterpretedOption.create, UninterpretedOption.createRepeated) ..hasExtensions = true ; @@ -612,13 +640,15 @@ class EnumValueOptions extends GeneratedMessage { EnumValueOptions.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); EnumValueOptions clone() => new EnumValueOptions()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static EnumValueOptions create() => new EnumValueOptions(); + static PbList createRepeated() => new PbList(); List get uninterpretedOption => getField(999); } class ServiceOptions extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('ServiceOptions') - ..m(999, 'uninterpretedOption', () => new UninterpretedOption(), () => new PbList()) + ..m(999, 'uninterpretedOption', UninterpretedOption.create, UninterpretedOption.createRepeated) ..hasExtensions = true ; @@ -627,13 +657,15 @@ class ServiceOptions extends GeneratedMessage { ServiceOptions.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); ServiceOptions clone() => new ServiceOptions()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static ServiceOptions create() => new ServiceOptions(); + static PbList createRepeated() => new PbList(); List get uninterpretedOption => getField(999); } class MethodOptions extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('MethodOptions') - ..m(999, 'uninterpretedOption', () => new UninterpretedOption(), () => new PbList()) + ..m(999, 'uninterpretedOption', UninterpretedOption.create, UninterpretedOption.createRepeated) ..hasExtensions = true ; @@ -642,13 +674,15 @@ class MethodOptions extends GeneratedMessage { MethodOptions.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); MethodOptions clone() => new MethodOptions()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static MethodOptions create() => new MethodOptions(); + static PbList createRepeated() => new PbList(); List get uninterpretedOption => getField(999); } class StreamOptions extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('StreamOptions') - ..m(999, 'uninterpretedOption', () => new UninterpretedOption(), () => new PbList()) + ..m(999, 'uninterpretedOption', UninterpretedOption.create, UninterpretedOption.createRepeated) ..hasExtensions = true ; @@ -657,6 +691,8 @@ class StreamOptions extends GeneratedMessage { StreamOptions.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); StreamOptions clone() => new StreamOptions()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static StreamOptions create() => new StreamOptions(); + static PbList createRepeated() => new PbList(); List get uninterpretedOption => getField(999); } @@ -672,6 +708,8 @@ class UninterpretedOption_NamePart extends GeneratedMessage { UninterpretedOption_NamePart.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); UninterpretedOption_NamePart clone() => new UninterpretedOption_NamePart()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static UninterpretedOption_NamePart create() => new UninterpretedOption_NamePart(); + static PbList createRepeated() => new PbList(); String get namePart => getField(1); void set namePart(String v) { setField(1, v); } @@ -686,10 +724,10 @@ class UninterpretedOption_NamePart extends GeneratedMessage { class UninterpretedOption extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('UninterpretedOption') - ..m(2, 'name', () => new UninterpretedOption_NamePart(), () => new PbList()) + ..m(2, 'name', UninterpretedOption_NamePart.create, UninterpretedOption_NamePart.createRepeated) ..a(3, 'identifierValue', GeneratedMessage.OS) - ..a(4, 'positiveIntValue', GeneratedMessage.OU6, () => makeLongInt(0)) - ..a(5, 'negativeIntValue', GeneratedMessage.O6, () => makeLongInt(0)) + ..a(4, 'positiveIntValue', GeneratedMessage.OU6, Int64.ZERO) + ..a(5, 'negativeIntValue', GeneratedMessage.O6, Int64.ZERO) ..a(6, 'doubleValue', GeneratedMessage.OD) ..a(7, 'stringValue', GeneratedMessage.OY) ..a(8, 'aggregateValue', GeneratedMessage.OS) @@ -700,6 +738,8 @@ class UninterpretedOption extends GeneratedMessage { UninterpretedOption.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); UninterpretedOption clone() => new UninterpretedOption()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static UninterpretedOption create() => new UninterpretedOption(); + static PbList createRepeated() => new PbList(); List get name => getField(2); @@ -746,6 +786,8 @@ class SourceCodeInfo_Location extends GeneratedMessage { SourceCodeInfo_Location.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); SourceCodeInfo_Location clone() => new SourceCodeInfo_Location()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static SourceCodeInfo_Location create() => new SourceCodeInfo_Location(); + static PbList createRepeated() => new PbList(); List get path => getField(1); @@ -754,7 +796,7 @@ class SourceCodeInfo_Location extends GeneratedMessage { class SourceCodeInfo extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('SourceCodeInfo') - ..m(1, 'location', () => new SourceCodeInfo_Location(), () => new PbList()) + ..m(1, 'location', SourceCodeInfo_Location.create, SourceCodeInfo_Location.createRepeated) ..hasRequiredFields = false ; @@ -763,6 +805,8 @@ class SourceCodeInfo extends GeneratedMessage { SourceCodeInfo.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); SourceCodeInfo clone() => new SourceCodeInfo()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static SourceCodeInfo create() => new SourceCodeInfo(); + static PbList createRepeated() => new PbList(); List get location => getField(1); } diff --git a/lib/src/plugin.pb.dart b/lib/src/plugin.pb.dart index 1e6868e..a2b38a4 100644 --- a/lib/src/plugin.pb.dart +++ b/lib/src/plugin.pb.dart @@ -5,14 +5,13 @@ library proto2.compiler; import 'package:fixnum/fixnum.dart'; import 'package:protobuf/protobuf.dart'; -import 'descriptor.pb.dart'; +import 'descriptor.pb.dart' as proto2; class CodeGeneratorRequest extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('CodeGeneratorRequest') ..p(1, 'fileToGenerate', GeneratedMessage.PS) ..a(2, 'parameter', GeneratedMessage.OS) - ..m(15, 'protoFile', () => new FileDescriptorProto(), () => new PbList()) - ..hasRequiredFields = false + ..m(15, 'protoFile', proto2.FileDescriptorProto.create, proto2.FileDescriptorProto.createRepeated) ; CodeGeneratorRequest() : super(); @@ -20,6 +19,8 @@ class CodeGeneratorRequest extends GeneratedMessage { CodeGeneratorRequest.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); CodeGeneratorRequest clone() => new CodeGeneratorRequest()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static CodeGeneratorRequest create() => new CodeGeneratorRequest(); + static PbList createRepeated() => new PbList(); List get fileToGenerate => getField(1); @@ -28,7 +29,7 @@ class CodeGeneratorRequest extends GeneratedMessage { bool hasParameter() => hasField(2); void clearParameter() => clearField(2); - List get protoFile => getField(15); + List get protoFile => getField(15); } class CodeGeneratorResponse_File extends GeneratedMessage { @@ -44,6 +45,8 @@ class CodeGeneratorResponse_File extends GeneratedMessage { CodeGeneratorResponse_File.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); CodeGeneratorResponse_File clone() => new CodeGeneratorResponse_File()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static CodeGeneratorResponse_File create() => new CodeGeneratorResponse_File(); + static PbList createRepeated() => new PbList(); String get name => getField(1); void set name(String v) { setField(1, v); } @@ -64,7 +67,7 @@ class CodeGeneratorResponse_File extends GeneratedMessage { class CodeGeneratorResponse extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('CodeGeneratorResponse') ..a(1, 'error', GeneratedMessage.OS) - ..m(15, 'file', () => new CodeGeneratorResponse_File(), () => new PbList()) + ..m(15, 'file', CodeGeneratorResponse_File.create, CodeGeneratorResponse_File.createRepeated) ..hasRequiredFields = false ; @@ -73,6 +76,8 @@ class CodeGeneratorResponse extends GeneratedMessage { CodeGeneratorResponse.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); CodeGeneratorResponse clone() => new CodeGeneratorResponse()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static CodeGeneratorResponse create() => new CodeGeneratorResponse(); + static PbList createRepeated() => new PbList(); String get error => getField(1); void set error(String v) { setField(1, v); } diff --git a/pubspec.yaml b/pubspec.yaml index 0b2c917..5230dd0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,12 @@ name: protoc_plugin -version: 0.3.4 +version: 0.3.5 author: Dart Team description: Protoc compiler plugin to generate Dart code homepage: https://github.com/dart-lang/dart-protoc-plugin environment: sdk: '>=1.0.0 <2.0.0' dependencies: - protobuf: '>=0.3.3 <0.4.0' + protobuf: '>=0.3.5 <0.4.0' path: '>=1.0.0 <2.0.0' dev_dependencies: unittest: '>=0.9.0 <0.11.0' diff --git a/test/file_generator_test.dart b/test/file_generator_test.dart index efaaa46..78f537e 100644 --- a/test/file_generator_test.dart +++ b/test/file_generator_test.dart @@ -81,7 +81,7 @@ class PhoneNumber extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('PhoneNumber') ..a(1, 'number', GeneratedMessage.QS) ..a(2, 'type', GeneratedMessage.O3) - ..a(3, 'name', GeneratedMessage.OS, () => '\$') + ..a(3, 'name', GeneratedMessage.OS, '\$') ; PhoneNumber() : super(); @@ -89,6 +89,8 @@ class PhoneNumber extends GeneratedMessage { PhoneNumber.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); PhoneNumber clone() => new PhoneNumber()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static PhoneNumber create() => new PhoneNumber(); + static PbList createRepeated() => new PbList(); String get number => getField(1); void set number(String v) { setField(1, v); } @@ -151,8 +153,8 @@ class PhoneType extends ProtobufEnum { class PhoneNumber extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('PhoneNumber') ..a(1, 'number', GeneratedMessage.QS) - ..e(2, 'type', GeneratedMessage.OE, () => PhoneType.MOBILE, (var v) => PhoneType.valueOf(v)) - ..a(3, 'name', GeneratedMessage.OS, () => '\$') + ..e(2, 'type', GeneratedMessage.OE, PhoneType.MOBILE, (var v) => PhoneType.valueOf(v)) + ..a(3, 'name', GeneratedMessage.OS, '\$') ; PhoneNumber() : super(); @@ -160,6 +162,8 @@ class PhoneNumber extends GeneratedMessage { PhoneNumber.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); PhoneNumber clone() => new PhoneNumber()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static PhoneNumber create() => new PhoneNumber(); + static PbList createRepeated() => new PbList(); String get number => getField(1); void set number(String v) { setField(1, v); } @@ -204,7 +208,7 @@ class PhoneNumber extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('PhoneNumber') ..a(1, 'number', GeneratedMessage.QS) ..a(2, 'type', GeneratedMessage.O3) - ..a(3, 'name', GeneratedMessage.OS, () => '\$') + ..a(3, 'name', GeneratedMessage.OS, '\$') ; PhoneNumber() : super(); @@ -212,6 +216,8 @@ class PhoneNumber extends GeneratedMessage { PhoneNumber.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); PhoneNumber clone() => new PhoneNumber()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static PhoneNumber create() => new PhoneNumber(); + static PbList createRepeated() => new PbList(); String get number => getField(1); void set number(String v) { setField(1, v); } @@ -257,7 +263,7 @@ class PhoneNumber extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('PhoneNumber') ..a(1, 'no', GeneratedMessage.QS) ..a(2, 'the_type', GeneratedMessage.O3) - ..a(3, 'name_', GeneratedMessage.OS, () => '\$') + ..a(3, 'name_', GeneratedMessage.OS, '\$') ; PhoneNumber() : super(); @@ -265,6 +271,8 @@ class PhoneNumber extends GeneratedMessage { PhoneNumber.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); PhoneNumber clone() => new PhoneNumber()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static PhoneNumber create() => new PhoneNumber(); + static PbList createRepeated() => new PbList(); String get no => getField(1); void set no(String v) { setField(1, v); } @@ -313,9 +321,9 @@ import 'package2.pb.dart' as p2; class M extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('M') - ..a(1, 'm', GeneratedMessage.OM, () => new M(), () => new M()) - ..a(2, 'm1', GeneratedMessage.OM, () => new p1.M(), () => new p1.M()) - ..a(3, 'm2', GeneratedMessage.OM, () => new p2.M(), () => new p2.M()) + ..a(1, 'm', GeneratedMessage.OM, M.create, M.create) + ..a(2, 'm1', GeneratedMessage.OM, p1.M.create, p1.M.create) + ..a(3, 'm2', GeneratedMessage.OM, p2.M.create, p2.M.create) ..hasRequiredFields = false ; @@ -324,6 +332,8 @@ class M extends GeneratedMessage { M.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); M clone() => new M()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static M create() => new M(); + static PbList createRepeated() => new PbList(); M get m => getField(1); void set m(M v) { setField(1, v); } diff --git a/test/generated_message_test.dart b/test/generated_message_test.dart index eaa1824..55e582e 100755 --- a/test/generated_message_test.dart +++ b/test/generated_message_test.dart @@ -147,6 +147,8 @@ void main() { expect(message.negInfFloat, same(double.NEGATIVE_INFINITY)); expect(message.nanFloat, same(double.NAN)); expect(message.cppTrigraph, '? ? ?? ?? ??? ??/ ??-'); + expect(message.smallInt64.toRadixString(16).toUpperCase(), + '-7FFFFFFFFFFFFFFF'); }); test('testClear', () { diff --git a/test/message_generator_test.dart b/test/message_generator_test.dart index 39e1ed6..dcf62b3 100755 --- a/test/message_generator_test.dart +++ b/test/message_generator_test.dart @@ -36,8 +36,8 @@ class PhoneNumber_PhoneType extends ProtobufEnum { class PhoneNumber extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('PhoneNumber') ..a(1, 'number', GeneratedMessage.QS) - ..e(2, 'type', GeneratedMessage.OE, () => PhoneNumber_PhoneType.MOBILE, (var v) => PhoneNumber_PhoneType.valueOf(v)) - ..a(3, 'name', GeneratedMessage.OS, () => '\$') + ..e(2, 'type', GeneratedMessage.OE, PhoneNumber_PhoneType.MOBILE, (var v) => PhoneNumber_PhoneType.valueOf(v)) + ..a(3, 'name', GeneratedMessage.OS, '\$') ; PhoneNumber() : super(); @@ -45,6 +45,8 @@ class PhoneNumber extends GeneratedMessage { PhoneNumber.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); PhoneNumber clone() => new PhoneNumber()..mergeFromMessage(this); BuilderInfo get info_ => _i; + static PhoneNumber create() => new PhoneNumber(); + static PbList createRepeated() => new PbList(); String get number => getField(1); void set number(String v) { setField(1, v); }