Skip to content

Commit

Permalink
[ObjC] Better support class renaming for extensions.
Browse files Browse the repository at this point in the history
The symbol renaming support has assumed folks would define a
custom version of the macro, but if a developer does renaming
just by #defining the class, the extension singleton names
required manual handing, by changing to just wrap the class
in the macro and using the compiler string concat support
it becomes easier as just the class name remapping can do
the work for extensions.

PiperOrigin-RevId: 670536928
  • Loading branch information
thomasvl authored and copybara-github committed Sep 3, 2024
1 parent 6ed0b9f commit 5233b80
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/google/protobuf/compiler/objectivec/extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ ExtensionGenerator::ExtensionGenerator(
absl::string_view root_or_message_class_name,
const FieldDescriptor* descriptor,
const GenerationOptions& generation_options)
: method_name_(ExtensionMethodName(descriptor)),
full_method_name_(
absl::StrCat(root_or_message_class_name, "_", method_name_)),
: root_or_message_class_name_(root_or_message_class_name),
method_name_(ExtensionMethodName(descriptor)),
descriptor_(descriptor),
generation_options_(generation_options) {
ABSL_CHECK(!descriptor->is_map())
Expand Down Expand Up @@ -90,16 +89,17 @@ void ExtensionGenerator::GenerateStaticVariablesInitialization(
{"extended_type", ObjCClass(containing_type)},
{"extension_type",
absl::StrCat("GPBDataType", GetCapitalizedType(descriptor_))},
{"method_name", method_name_},
{"number", descriptor_->number()},
{"options", BuildFlagsString(FLAGTYPE_EXTENSION, options)},
{"full_method_name", full_method_name_},
{"root_or_message_class_name", root_or_message_class_name_},
{"type", objc_type == OBJECTIVECTYPE_MESSAGE
? ObjCClass(ClassName(descriptor_->message_type()))
: "Nil"}},
R"objc(
{
.defaultValue.$default_name$ = $default$,
.singletonName = GPBStringifySymbol($full_method_name$),
.singletonName = GPBStringifySymbol($root_or_message_class_name$) "_$method_name$",
.extendedClass.clazz = $extended_type$,
.messageOrGroupClass.clazz = $type$,
.enumDescriptorFunc = $enum_desc_func_name$,
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/objectivec/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class ExtensionGenerator {
absl::flat_hash_set<const FileDescriptor*>* deps) const;

private:
std::string root_or_message_class_name_;
std::string method_name_;
std::string full_method_name_;
const FieldDescriptor* descriptor_;
const GenerationOptions& generation_options_;
};
Expand Down

0 comments on commit 5233b80

Please sign in to comment.