From ec0df812808059c16d2a64fd40e8e60227d63f54 Mon Sep 17 00:00:00 2001 From: Stefan Haustein Date: Thu, 10 Apr 2025 02:18:08 -0700 Subject: [PATCH] In kotlin/native compatibility methods, include the name of the first parameter in the method name to match k/n @ObjCName mapping. PiperOrigin-RevId: 745934253 --- .../google/protobuf/compiler/j2objc/j2objc_field.cc | 12 ++++++------ .../src/com/google/protobuf/GeneratedMessage.mm | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/protobuf/compiler/src/google/protobuf/compiler/j2objc/j2objc_field.cc b/protobuf/compiler/src/google/protobuf/compiler/j2objc/j2objc_field.cc index eb9c6570d2..72e68e7489 100644 --- a/protobuf/compiler/src/google/protobuf/compiler/j2objc/j2objc_field.cc +++ b/protobuf/compiler/src/google/protobuf/compiler/j2objc/j2objc_field.cc @@ -330,7 +330,7 @@ void SingleFieldGenerator::GenerateFieldBuilderHeader(io::Printer* printer) "- (nonnull $classname$_Builder *)set$capitalized_name$With$parameter_type$:\n" " ($nonnull_type$)value;\n" "- (nonnull $classname$_Builder *)clear$capitalized_name$;\n"); - + if (CanGenerateProperty(descriptor_)) { printer->Print(GetStorageType(descriptor_) == GetNonNullType(descriptor_) ? "@property (" : "@property (nonnull, retain, "); @@ -340,7 +340,7 @@ void SingleFieldGenerator::GenerateFieldBuilderHeader(io::Printer* printer) "setter=Set$capitalized_name$With$parameter_type$:) " "$storage_type$ $camelcase_name$;\n"); } - + if (GetJavaType(descriptor_) == JAVATYPE_MESSAGE) { printer->Print(variables_, "- (nonnull $classname$_Builder*)\n" @@ -417,7 +417,7 @@ void RepeatedFieldGenerator::GenerateFieldBuilderHeader(io::Printer* printer) if (IsGenerateProperties(descriptor_->file())) { printer->Print( variables_, - "- (nonnull $classname$_Builder *)add$capitalized_name$:\n" + "- (nonnull $classname$_Builder *)add$capitalized_name$Value:\n" " ($nonnull_type$)value;\n"); } if (GetJavaType(descriptor_) == JAVATYPE_MESSAGE) { @@ -523,11 +523,11 @@ void MapFieldGenerator::GenerateFieldBuilderHeader(io::Printer* printer) const { "*)put$capitalized_name$With$key_parameter_type$:" "($key_storage_type$)key with$value_parameter_type$:" "($value_nonnull_type$)value;\n"); - + if (IsGenerateProperties(descriptor_->file())) { printer->Print( variables_, - "- (nonnull $classname$_Builder *)put$capitalized_name$:" + "- (nonnull $classname$_Builder *)put$capitalized_name$Key:" "($key_nonnull_type$)key value:($value_nonnull_type$)value;\n"); } } @@ -565,7 +565,7 @@ void MapFieldGenerator::GenerateMessageOrBuilderProtocol( "with$value_parameter_type$:($value_nonnull_type$)defaultValue;\n" "- ($value_nonnull_type$)get$capitalized_name$OrThrowWith" "$key_parameter_type$:($key_storage_type$)key;\n"); - + if (IsGenerateProperties(descriptor_->file())) { printer->Print( variables_, diff --git a/protobuf/runtime/src/com/google/protobuf/GeneratedMessage.mm b/protobuf/runtime/src/com/google/protobuf/GeneratedMessage.mm index 3064999743..e660a10b85 100644 --- a/protobuf/runtime/src/com/google/protobuf/GeneratedMessage.mm +++ b/protobuf/runtime/src/com/google/protobuf/GeneratedMessage.mm @@ -1179,7 +1179,7 @@ static BOOL ResolveAddAccessor(Class cls, CGPDescriptor *descriptor, SEL sel, co ComGoogleProtobufDescriptors_FieldDescriptor *field = fieldsBuf[i]; const char *tail = selName; if (MatchesName(&tail, field) && - (Matches(&tail, "With", 4) ? MatchesKeyword(&tail, field) : true)) { + (Matches(&tail, "With", 4) ? MatchesKeyword(&tail, field) : Matches(&tail, "Value", 5))) { if (MatchesEnd(tail, ":")) { return AddAdderMethod(cls, sel, field); } else if (MatchesEnd(tail, "_Builder:")) { @@ -1234,7 +1234,7 @@ static BOOL ResolvePutAccessor(Class cls, CGPDescriptor *descriptor, SEL sel, co MatchesEnd(tail, ":")) { return AddPutMethod(cls, sel, field); } - if (Matches(&tail, ":value", 6) && MatchesEnd(tail, ":")) { + if (Matches(&tail, "Key", 3) && Matches(&tail, ":value", 6) && MatchesEnd(tail, ":")) { return AddPutMethod(cls, sel, field); } }