diff --git a/protobuf/lib/src/protobuf/builder_info.dart b/protobuf/lib/src/protobuf/builder_info.dart index 1ae34413..05112088 100644 --- a/protobuf/lib/src/protobuf/builder_info.dart +++ b/protobuf/lib/src/protobuf/builder_info.dart @@ -61,7 +61,7 @@ class BuilderInfo { int? fieldType, dynamic defaultOrMaker, CreateBuilderFunc? subBuilder, - ValueOfFunc? valueOf, + Map? enumValueMap, List? enumValues, {String? protoName}) { final index = byIndex.length; @@ -70,7 +70,7 @@ class BuilderInfo { : FieldInfo(name, tagNumber, index, fieldType!, defaultOrMaker: defaultOrMaker, subBuilder: subBuilder, - valueOf: valueOf, + enumValueMap: enumValueMap, enumValues: enumValues, protoName: protoName); _addField(fieldInfo); @@ -97,14 +97,14 @@ class BuilderInfo { int fieldType, CheckFunc check, CreateBuilderFunc? subBuilder, - ValueOfFunc? valueOf, + Map? enumValueMap, List? enumValues, {ProtobufEnum? defaultEnumValue, String? protoName}) { final index = byIndex.length; _addField(FieldInfo.repeated( name, tagNumber, index, fieldType, check, subBuilder, - valueOf: valueOf, + enumValueMap: enumValueMap, enumValues: enumValues, defaultEnumValue: defaultEnumValue, protoName: protoName)); @@ -126,10 +126,10 @@ class BuilderInfo { void a(int tagNumber, String name, int fieldType, {dynamic defaultOrMaker, CreateBuilderFunc? subBuilder, - ValueOfFunc? valueOf, + Map? enumValueMap, List? enumValues, String? protoName}) { - add(tagNumber, name, fieldType, defaultOrMaker, subBuilder, valueOf, + add(tagNumber, name, fieldType, defaultOrMaker, subBuilder, enumValueMap, enumValues, protoName: protoName); } @@ -169,11 +169,11 @@ class BuilderInfo { // Enum. void e(int tagNumber, String name, int fieldType, {dynamic defaultOrMaker, - ValueOfFunc? valueOf, + Map? enumValueMap, List? enumValues, String? protoName}) { - add( - tagNumber, name, fieldType, defaultOrMaker, null, valueOf, enumValues, + add(tagNumber, name, fieldType, defaultOrMaker, null, enumValueMap, + enumValues, protoName: protoName); } @@ -188,13 +188,13 @@ class BuilderInfo { // Repeated message, group, or enum. void pc(int tagNumber, String name, int fieldType, {CreateBuilderFunc? subBuilder, - ValueOfFunc? valueOf, + Map? enumValueMap, List? enumValues, ProtobufEnum? defaultEnumValue, String? protoName}) { assert(_isGroupOrMessage(fieldType) || _isEnum(fieldType)); addRepeated(tagNumber, name, fieldType, _checkNotNull, subBuilder, - valueOf, enumValues, + enumValueMap, enumValues, defaultEnumValue: defaultEnumValue, protoName: protoName); } @@ -237,7 +237,7 @@ class BuilderInfo { required int keyFieldType, required int valueFieldType, CreateBuilderFunc? valueCreator, - ValueOfFunc? valueOf, + Map? enumValueMap, List? enumValues, ProtobufEnum? defaultEnumValue, PackageName packageName = const PackageName(''), @@ -247,7 +247,7 @@ class BuilderInfo { package: packageName) ..add(PbMap._keyFieldNumber, 'key', keyFieldType, null, null, null, null) ..add(PbMap._valueFieldNumber, 'value', valueFieldType, - valueDefaultOrMaker, valueCreator, valueOf, enumValues); + valueDefaultOrMaker, valueCreator, enumValueMap, enumValues); addMapField(tagNumber, name, keyFieldType, valueFieldType, mapEntryBuilderInfo, valueCreator, @@ -287,11 +287,6 @@ class BuilderInfo { return i?.tagNumber; } - ValueOfFunc? valueOfFunc(int tagNumber) { - final i = fieldInfo[tagNumber]; - return i?.valueOf; - } - /// The [FieldInfo] for each field in tag number order. List get sortedByTag => _sortedByTag ??= _computeSortedByTag(); @@ -323,13 +318,12 @@ class BuilderInfo { ProtobufEnum? _decodeEnum( int tagNumber, ExtensionRegistry? registry, int rawValue) { - final f = valueOfFunc(tagNumber); - if (f != null) { - return f(rawValue); + final valueMap = fieldInfo[tagNumber]?.enumValueMap; + if (valueMap != null) { + return valueMap[rawValue]; } return registry ?.getExtension(qualifiedMessageName, tagNumber) - ?.valueOf - ?.call(rawValue); + ?.enumValueMap?[rawValue]; } } diff --git a/protobuf/lib/src/protobuf/extension.dart b/protobuf/lib/src/protobuf/extension.dart index 1144443f..8d70ba1c 100644 --- a/protobuf/lib/src/protobuf/extension.dart +++ b/protobuf/lib/src/protobuf/extension.dart @@ -11,24 +11,26 @@ class Extension extends FieldInfo { Extension(this.extendee, String name, int tagNumber, int fieldType, {dynamic defaultOrMaker, CreateBuilderFunc? subBuilder, - ValueOfFunc? valueOf, + Map? enumValueMap, List? enumValues, String? protoName}) : super(name, tagNumber, null, fieldType, defaultOrMaker: defaultOrMaker, subBuilder: subBuilder, - valueOf: valueOf, + enumValueMap: enumValueMap, enumValues: enumValues, protoName: protoName); Extension.repeated(this.extendee, String name, int tagNumber, int fieldType, {required CheckFunc check, CreateBuilderFunc? subBuilder, - ValueOfFunc? valueOf, + Map? enumValueMap, List? enumValues, String? protoName}) : super.repeated(name, tagNumber, null, fieldType, check, subBuilder, - valueOf: valueOf, enumValues: enumValues, protoName: protoName); + enumValueMap: enumValueMap, + enumValues: enumValues, + protoName: protoName); @override int get hashCode => extendee.hashCode * 31 + tagNumber; diff --git a/protobuf/lib/src/protobuf/field_info.dart b/protobuf/lib/src/protobuf/field_info.dart index 1777e090..ba0b449d 100644 --- a/protobuf/lib/src/protobuf/field_info.dart +++ b/protobuf/lib/src/protobuf/field_info.dart @@ -91,7 +91,7 @@ class FieldInfo { /// Mapping from enum integer values to enum values. /// /// Only available in enum fields. - final ValueOfFunc? valueOf; + final Map? enumValueMap; /// Function to verify items when adding to a repeated field. /// @@ -101,7 +101,7 @@ class FieldInfo { FieldInfo(this.name, this.tagNumber, this.index, this.type, {dynamic defaultOrMaker, this.subBuilder, - this.valueOf, + this.enumValueMap, this.enumValues, this.defaultEnumValue, String? protoName}) @@ -112,7 +112,7 @@ class FieldInfo { assert(!_isGroupOrMessage(type) || subBuilder != null || _isMapField(type)), - assert(!_isEnum(type) || valueOf != null); + assert(!_isEnum(type) || enumValueMap != null); // Represents a field that has been removed by a program transformation. FieldInfo.dummy(this.index) @@ -121,7 +121,7 @@ class FieldInfo { tagNumber = 0, type = 0, makeDefault = null, - valueOf = null, + enumValueMap = null, check = null, enumValues = null, defaultEnumValue = null, @@ -129,11 +129,14 @@ class FieldInfo { FieldInfo.repeated(this.name, this.tagNumber, this.index, this.type, CheckFunc this.check, this.subBuilder, - {this.valueOf, this.enumValues, this.defaultEnumValue, String? protoName}) + {this.enumValueMap, + this.enumValues, + this.defaultEnumValue, + String? protoName}) : makeDefault = (() => PbList(check: check)), _protoName = protoName, assert(_isRepeated(type)), - assert(!_isEnum(type) || valueOf != null); + assert(!_isEnum(type) || enumValueMap != null); static MakeDefaultFunc? findMakeDefault(int type, dynamic defaultOrMaker) { if (defaultOrMaker == null) return PbFieldType._defaultForType(type); @@ -277,7 +280,7 @@ class MapFieldInfo extends FieldInfo?> { defaultOrMaker: () => PbMap(keyFieldType, valueFieldType), defaultEnumValue: defaultEnumValue, protoName: protoName) { - assert(!_isEnum(type) || valueOf != null); + assert(!_isEnum(type) || enumValueMap != null); } FieldInfo get valueFieldInfo => diff --git a/protobuf/lib/src/protobuf/proto3_json.dart b/protobuf/lib/src/protobuf/proto3_json.dart index c40806d4..c811a03d 100644 --- a/protobuf/lib/src/protobuf/proto3_json.dart +++ b/protobuf/lib/src/protobuf/proto3_json.dart @@ -213,7 +213,7 @@ void _mergeFromProto3Json( if ((result != null) || ignoreUnknownFields) return result; throw context.parseException('Unknown enum value', value); } else if (value is int) { - return fieldInfo.valueOf!(value) ?? + return fieldInfo.enumValueMap![value] ?? (ignoreUnknownFields ? null : (throw context.parseException( diff --git a/protobuf/test/mock_util.dart b/protobuf/test/mock_util.dart index 73176354..f7e67929 100644 --- a/protobuf/test/mock_util.dart +++ b/protobuf/test/mock_util.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:collection/collection.dart'; import 'package:fixnum/fixnum.dart' show Int64; import 'package:protobuf/protobuf.dart' show @@ -23,7 +22,8 @@ BuilderInfo mockInfo(String className, CreateBuilderFunc create) { // 6 is reserved for extensions in other tests. ..e(7, 'enm', PbFieldType.OE, defaultOrMaker: mockEnumValues.first, - valueOf: (i) => mockEnumValues.firstWhereOrNull((e) => e.value == i), + enumValueMap: + Map.fromEntries(mockEnumValues.map((e) => MapEntry(e.value, e))), enumValues: mockEnumValues); } diff --git a/protoc_plugin/lib/src/enum_generator.dart b/protoc_plugin/lib/src/enum_generator.dart index a1cd8b5f..9b65f614 100644 --- a/protoc_plugin/lib/src/enum_generator.dart +++ b/protoc_plugin/lib/src/enum_generator.dart @@ -176,10 +176,8 @@ class EnumGenerator extends ProtobufContainer { out.println(); out.println( - 'static final $coreImportPrefix.Map<$coreImportPrefix.int, $classname> _byValue =' + 'static final $coreImportPrefix.Map<$coreImportPrefix.int, $classname> byValue =' ' $protobufImportPrefix.ProtobufEnum.initByValue(values);'); - out.println('static $classname? valueOf($coreImportPrefix.int value) =>' - ' _byValue[value];'); out.println(); out.println('const $classname._(super.v, super.n);'); diff --git a/protoc_plugin/lib/src/extension_generator.dart b/protoc_plugin/lib/src/extension_generator.dart index f9eef30f..84c90185 100644 --- a/protoc_plugin/lib/src/extension_generator.dart +++ b/protoc_plugin/lib/src/extension_generator.dart @@ -119,7 +119,7 @@ class ExtensionGenerator { if (type.isMessage || type.isGroup) { named['subBuilder'] = '$dartType.create'; } else if (type.isEnum) { - named['valueOf'] = '$dartType.valueOf'; + named['enumValueMap'] = '$dartType.byValue'; named['enumValues'] = '$dartType.values'; } } else { @@ -129,7 +129,7 @@ class ExtensionGenerator { named['subBuilder'] = '$dartType.create'; } else if (type.isEnum) { final dartEnum = type.getDartType(fileGen!); - named['valueOf'] = '$dartEnum.valueOf'; + named['enumValueMap'] = '$dartEnum.byValue'; named['enumValues'] = '$dartEnum.values'; } } diff --git a/protoc_plugin/lib/src/generated/descriptor.pb.dart b/protoc_plugin/lib/src/generated/descriptor.pb.dart index a4dfd4cb..332e4981 100644 --- a/protoc_plugin/lib/src/generated/descriptor.pb.dart +++ b/protoc_plugin/lib/src/generated/descriptor.pb.dart @@ -767,12 +767,12 @@ class FieldDescriptorProto extends $pb.GeneratedMessage { ..e( 4, _omitFieldNames ? '' : 'label', $pb.PbFieldType.OE, defaultOrMaker: FieldDescriptorProto_Label.LABEL_OPTIONAL, - valueOf: FieldDescriptorProto_Label.valueOf, + enumValueMap: FieldDescriptorProto_Label.byValue, enumValues: FieldDescriptorProto_Label.values) ..e( 5, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, defaultOrMaker: FieldDescriptorProto_Type.TYPE_DOUBLE, - valueOf: FieldDescriptorProto_Type.valueOf, + enumValueMap: FieldDescriptorProto_Type.byValue, enumValues: FieldDescriptorProto_Type.values) ..aOS(6, _omitFieldNames ? '' : 'typeName') ..aOS(7, _omitFieldNames ? '' : 'defaultValue') @@ -1733,7 +1733,7 @@ class FileOptions extends $pb.GeneratedMessage { ..e( 9, _omitFieldNames ? '' : 'optimizeFor', $pb.PbFieldType.OE, defaultOrMaker: FileOptions_OptimizeMode.SPEED, - valueOf: FileOptions_OptimizeMode.valueOf, + enumValueMap: FileOptions_OptimizeMode.byValue, enumValues: FileOptions_OptimizeMode.values) ..aOB(10, _omitFieldNames ? '' : 'javaMultipleFiles') ..aOS(11, _omitFieldNames ? '' : 'goPackage') @@ -2312,7 +2312,7 @@ class FieldOptions extends $pb.GeneratedMessage { ..e( 1, _omitFieldNames ? '' : 'ctype', $pb.PbFieldType.OE, defaultOrMaker: FieldOptions_CType.STRING, - valueOf: FieldOptions_CType.valueOf, + enumValueMap: FieldOptions_CType.byValue, enumValues: FieldOptions_CType.values) ..aOB(2, _omitFieldNames ? '' : 'packed') ..aOB(3, _omitFieldNames ? '' : 'deprecated') @@ -2320,7 +2320,7 @@ class FieldOptions extends $pb.GeneratedMessage { ..e( 6, _omitFieldNames ? '' : 'jstype', $pb.PbFieldType.OE, defaultOrMaker: FieldOptions_JSType.JS_NORMAL, - valueOf: FieldOptions_JSType.valueOf, + enumValueMap: FieldOptions_JSType.byValue, enumValues: FieldOptions_JSType.values) ..aOB(10, _omitFieldNames ? '' : 'weak') ..pc( @@ -2821,7 +2821,7 @@ class MethodOptions extends $pb.GeneratedMessage { ..e( 34, _omitFieldNames ? '' : 'idempotencyLevel', $pb.PbFieldType.OE, defaultOrMaker: MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN, - valueOf: MethodOptions_IdempotencyLevel.valueOf, + enumValueMap: MethodOptions_IdempotencyLevel.byValue, enumValues: MethodOptions_IdempotencyLevel.values) ..pc( 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, diff --git a/protoc_plugin/lib/src/generated/descriptor.pbenum.dart b/protoc_plugin/lib/src/generated/descriptor.pbenum.dart index dc6f349d..2df50316 100644 --- a/protoc_plugin/lib/src/generated/descriptor.pbenum.dart +++ b/protoc_plugin/lib/src/generated/descriptor.pbenum.dart @@ -88,9 +88,8 @@ class FieldDescriptorProto_Type extends $pb.ProtobufEnum { TYPE_SINT64, ]; - static final $core.Map<$core.int, FieldDescriptorProto_Type> _byValue = + static final $core.Map<$core.int, FieldDescriptorProto_Type> byValue = $pb.ProtobufEnum.initByValue(values); - static FieldDescriptorProto_Type? valueOf($core.int value) => _byValue[value]; const FieldDescriptorProto_Type._(super.v, super.n); } @@ -111,10 +110,8 @@ class FieldDescriptorProto_Label extends $pb.ProtobufEnum { LABEL_REPEATED, ]; - static final $core.Map<$core.int, FieldDescriptorProto_Label> _byValue = + static final $core.Map<$core.int, FieldDescriptorProto_Label> byValue = $pb.ProtobufEnum.initByValue(values); - static FieldDescriptorProto_Label? valueOf($core.int value) => - _byValue[value]; const FieldDescriptorProto_Label._(super.v, super.n); } @@ -137,9 +134,8 @@ class FileOptions_OptimizeMode extends $pb.ProtobufEnum { LITE_RUNTIME, ]; - static final $core.Map<$core.int, FileOptions_OptimizeMode> _byValue = + static final $core.Map<$core.int, FileOptions_OptimizeMode> byValue = $pb.ProtobufEnum.initByValue(values); - static FileOptions_OptimizeMode? valueOf($core.int value) => _byValue[value]; const FileOptions_OptimizeMode._(super.v, super.n); } @@ -159,9 +155,8 @@ class FieldOptions_CType extends $pb.ProtobufEnum { STRING_PIECE, ]; - static final $core.Map<$core.int, FieldOptions_CType> _byValue = + static final $core.Map<$core.int, FieldOptions_CType> byValue = $pb.ProtobufEnum.initByValue(values); - static FieldOptions_CType? valueOf($core.int value) => _byValue[value]; const FieldOptions_CType._(super.v, super.n); } @@ -185,9 +180,8 @@ class FieldOptions_JSType extends $pb.ProtobufEnum { JS_NUMBER, ]; - static final $core.Map<$core.int, FieldOptions_JSType> _byValue = + static final $core.Map<$core.int, FieldOptions_JSType> byValue = $pb.ProtobufEnum.initByValue(values); - static FieldOptions_JSType? valueOf($core.int value) => _byValue[value]; const FieldOptions_JSType._(super.v, super.n); } @@ -212,10 +206,8 @@ class MethodOptions_IdempotencyLevel extends $pb.ProtobufEnum { IDEMPOTENT, ]; - static final $core.Map<$core.int, MethodOptions_IdempotencyLevel> _byValue = + static final $core.Map<$core.int, MethodOptions_IdempotencyLevel> byValue = $pb.ProtobufEnum.initByValue(values); - static MethodOptions_IdempotencyLevel? valueOf($core.int value) => - _byValue[value]; const MethodOptions_IdempotencyLevel._(super.v, super.n); } diff --git a/protoc_plugin/lib/src/generated/plugin.pbenum.dart b/protoc_plugin/lib/src/generated/plugin.pbenum.dart index 399158c5..62219bc2 100644 --- a/protoc_plugin/lib/src/generated/plugin.pbenum.dart +++ b/protoc_plugin/lib/src/generated/plugin.pbenum.dart @@ -27,10 +27,8 @@ class CodeGeneratorResponse_Feature extends $pb.ProtobufEnum { FEATURE_PROTO3_OPTIONAL, ]; - static final $core.Map<$core.int, CodeGeneratorResponse_Feature> _byValue = + static final $core.Map<$core.int, CodeGeneratorResponse_Feature> byValue = $pb.ProtobufEnum.initByValue(values); - static CodeGeneratorResponse_Feature? valueOf($core.int value) => - _byValue[value]; const CodeGeneratorResponse_Feature._(super.v, super.n); } diff --git a/protoc_plugin/lib/src/protobuf_field.dart b/protoc_plugin/lib/src/protobuf_field.dart index 7906cbec..80c67327 100644 --- a/protoc_plugin/lib/src/protobuf_field.dart +++ b/protoc_plugin/lib/src/protobuf_field.dart @@ -238,7 +238,7 @@ class ProtobufField { named['valueDefaultOrMaker'] = value.generateDefaultFunction(); } if (value.baseType.isEnum) { - named['valueOf'] = '$valueType.valueOf'; + named['enumValueMap'] = '$valueType.byValue'; named['enumValues'] = '$valueType.values'; named['valueDefaultOrMaker'] = value.generateDefaultFunction(); named['defaultEnumValue'] = value.generateDefaultFunction(); @@ -261,7 +261,7 @@ class ProtobufField { if (baseType.isMessage || baseType.isGroup) { named['subBuilder'] = '$type.create'; } else if (baseType.isEnum) { - named['valueOf'] = '$type.valueOf'; + named['enumValueMap'] = '$type.byValue'; named['enumValues'] = '$type.values'; named['defaultEnumValue'] = generateDefaultFunction(); } @@ -273,7 +273,7 @@ class ProtobufField { if (baseType.isEnum) { args.add(typeConstant); named['defaultOrMaker'] = makeDefault; - named['valueOf'] = '$type.valueOf'; + named['enumValueMap'] = '$type.byValue'; named['enumValues'] = '$type.values'; invocation = 'e<$type>'; } else if (makeDefault == null) { diff --git a/protoc_plugin/test/generated_message_test.dart b/protoc_plugin/test/generated_message_test.dart index a25f6a4d..1c40ffcf 100644 --- a/protoc_plugin/test/generated_message_test.dart +++ b/protoc_plugin/test/generated_message_test.dart @@ -151,9 +151,9 @@ void main() { test('testEnumMap', () { for (final value in ForeignEnum.values) { - expect(ForeignEnum.valueOf(value.value), value); + expect(ForeignEnum.byValue[value.value], value); } - expect(ForeignEnum.valueOf(12345), isNull); + expect(ForeignEnum.byValue[12345], isNull); }); test('testParsePackedToUnpacked', () { diff --git a/protoc_plugin/test/goldens/deprecations.pbenum b/protoc_plugin/test/goldens/deprecations.pbenum index 30bc5d78..ea85a190 100644 --- a/protoc_plugin/test/goldens/deprecations.pbenum +++ b/protoc_plugin/test/goldens/deprecations.pbenum @@ -24,9 +24,8 @@ class A extends $pb.ProtobufEnum { A2, ]; - static final $core.Map<$core.int, A> _byValue = + static final $core.Map<$core.int, A> byValue = $pb.ProtobufEnum.initByValue(values); - static A? valueOf($core.int value) => _byValue[value]; const A._(super.v, super.n); } diff --git a/protoc_plugin/test/goldens/doc_comments.pbenum b/protoc_plugin/test/goldens/doc_comments.pbenum index 7cde50e1..7cf625ae 100644 --- a/protoc_plugin/test/goldens/doc_comments.pbenum +++ b/protoc_plugin/test/goldens/doc_comments.pbenum @@ -26,9 +26,8 @@ class A extends $pb.ProtobufEnum { A2, ]; - static final $core.Map<$core.int, A> _byValue = + static final $core.Map<$core.int, A> byValue = $pb.ProtobufEnum.initByValue(values); - static A? valueOf($core.int value) => _byValue[value]; const A._(super.v, super.n); } diff --git a/protoc_plugin/test/goldens/enum b/protoc_plugin/test/goldens/enum index 812247dd..670351a4 100644 --- a/protoc_plugin/test/goldens/enum +++ b/protoc_plugin/test/goldens/enum @@ -11,8 +11,7 @@ class PhoneType extends $pb.ProtobufEnum { WORK, ]; - static final $core.Map<$core.int, PhoneType> _byValue = $pb.ProtobufEnum.initByValue(values); - static PhoneType? valueOf($core.int value) => _byValue[value]; + static final $core.Map<$core.int, PhoneType> byValue = $pb.ProtobufEnum.initByValue(values); const PhoneType._(super.v, super.n); } diff --git a/protoc_plugin/test/goldens/messageGenerator b/protoc_plugin/test/goldens/messageGenerator index 5eab0203..98084bd2 100644 --- a/protoc_plugin/test/goldens/messageGenerator +++ b/protoc_plugin/test/goldens/messageGenerator @@ -6,7 +6,7 @@ class PhoneNumber extends $pb.GeneratedMessage { static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'PhoneNumber', createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'number') - ..e(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, defaultOrMaker: PhoneNumber_PhoneType.MOBILE, valueOf: PhoneNumber_PhoneType.valueOf, enumValues: PhoneNumber_PhoneType.values) + ..e(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, defaultOrMaker: PhoneNumber_PhoneType.MOBILE, enumValueMap: PhoneNumber_PhoneType.byValue, enumValues: PhoneNumber_PhoneType.values) ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldType.OS, defaultOrMaker: '\$') ..aOS(4, _omitFieldNames ? '' : 'deprecatedField') ; diff --git a/protoc_plugin/test/goldens/messageGenerator.meta b/protoc_plugin/test/goldens/messageGenerator.meta index c398f603..8c76702b 100644 --- a/protoc_plugin/test/goldens/messageGenerator.meta +++ b/protoc_plugin/test/goldens/messageGenerator.meta @@ -18,8 +18,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2003 - end: 2009 + begin: 2008 + end: 2014 } annotation: { path: 4 @@ -27,8 +27,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2051 - end: 2057 + begin: 2056 + end: 2062 } annotation: { path: 4 @@ -36,8 +36,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2130 - end: 2139 + begin: 2135 + end: 2144 } annotation: { path: 4 @@ -45,8 +45,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2182 - end: 2193 + begin: 2187 + end: 2198 } annotation: { path: 4 @@ -54,8 +54,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2265 - end: 2269 + begin: 2270 + end: 2274 } annotation: { path: 4 @@ -63,8 +63,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2310 - end: 2314 + begin: 2315 + end: 2319 } annotation: { path: 4 @@ -72,8 +72,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2395 - end: 2402 + begin: 2400 + end: 2407 } annotation: { path: 4 @@ -81,8 +81,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2445 - end: 2454 + begin: 2450 + end: 2459 } annotation: { path: 4 @@ -90,8 +90,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2517 - end: 2521 + begin: 2522 + end: 2526 } annotation: { path: 4 @@ -99,8 +99,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2568 - end: 2572 + begin: 2573 + end: 2577 } annotation: { path: 4 @@ -108,8 +108,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2645 - end: 2652 + begin: 2650 + end: 2657 } annotation: { path: 4 @@ -117,8 +117,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2695 - end: 2704 + begin: 2700 + end: 2709 } annotation: { path: 4 @@ -126,8 +126,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2816 - end: 2831 + begin: 2821 + end: 2836 } annotation: { path: 4 @@ -135,8 +135,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2922 - end: 2937 + begin: 2927 + end: 2942 } annotation: { path: 4 @@ -144,8 +144,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 3059 - end: 3077 + begin: 3064 + end: 3082 } annotation: { path: 4 @@ -153,6 +153,6 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 3169 - end: 3189 + begin: 3174 + end: 3194 } diff --git a/protoc_plugin/test/goldens/messageGeneratorEnums b/protoc_plugin/test/goldens/messageGeneratorEnums index 3469c7ba..74d743db 100644 --- a/protoc_plugin/test/goldens/messageGeneratorEnums +++ b/protoc_plugin/test/goldens/messageGeneratorEnums @@ -11,8 +11,7 @@ class PhoneNumber_PhoneType extends $pb.ProtobufEnum { WORK, ]; - static final $core.Map<$core.int, PhoneNumber_PhoneType> _byValue = $pb.ProtobufEnum.initByValue(values); - static PhoneNumber_PhoneType? valueOf($core.int value) => _byValue[value]; + static final $core.Map<$core.int, PhoneNumber_PhoneType> byValue = $pb.ProtobufEnum.initByValue(values); const PhoneNumber_PhoneType._(super.v, super.n); } diff --git a/protoc_plugin/test/goldens/topLevelEnum.pbenum b/protoc_plugin/test/goldens/topLevelEnum.pbenum index 30d81a24..f09f7390 100644 --- a/protoc_plugin/test/goldens/topLevelEnum.pbenum +++ b/protoc_plugin/test/goldens/topLevelEnum.pbenum @@ -26,8 +26,7 @@ class PhoneType extends $pb.ProtobufEnum { WORK, ]; - static final $core.Map<$core.int, PhoneType> _byValue = $pb.ProtobufEnum.initByValue(values); - static PhoneType? valueOf($core.int value) => _byValue[value]; + static final $core.Map<$core.int, PhoneType> byValue = $pb.ProtobufEnum.initByValue(values); const PhoneType._(super.v, super.n); } diff --git a/protoc_plugin/test/proto3_json_test.dart b/protoc_plugin/test/proto3_json_test.dart index dc9de0ed..9295c229 100644 --- a/protoc_plugin/test/proto3_json_test.dart +++ b/protoc_plugin/test/proto3_json_test.dart @@ -450,7 +450,7 @@ void main() { expect( TestAllTypes()..mergeFromProto3Json({'optionalNestedEnum': 1}), TestAllTypes() - ..optionalNestedEnum = TestAllTypes_NestedEnum.valueOf(1)!); + ..optionalNestedEnum = TestAllTypes_NestedEnum.byValue[1]!); expect(TestAllTypes()..mergeFromProto3Json({'repeatedBool': null}), TestAllTypes()); expect(() => TestAllTypes()..mergeFromProto3Json({'repeatedBool': 100}),