[ObjC] Better support class renaming for extensions.

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
pull/18030/head
Thomas Van Lenten 7 months ago committed by Copybara-Service
parent 6ed0b9f28d
commit 5233b80fb7
  1. 10
      src/google/protobuf/compiler/objectivec/extension.cc
  2. 2
      src/google/protobuf/compiler/objectivec/extension.h

@ -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())
@ -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$,

@ -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_;
};

Loading…
Cancel
Save