Clearify that ExtensionGenerator gets a message or root class.

PiperOrigin-RevId: 547207538
pull/13267/head
Thomas Van Lenten 1 year ago committed by Copybara-Service
parent b830c62623
commit 3c2af99960
  1. 17
      src/google/protobuf/compiler/objectivec/extension.cc
  2. 4
      src/google/protobuf/compiler/objectivec/extension.h
  3. 1
      src/google/protobuf/compiler/objectivec/message.h

@ -45,11 +45,12 @@ namespace protobuf {
namespace compiler {
namespace objectivec {
ExtensionGenerator::ExtensionGenerator(absl::string_view root_class_name,
const FieldDescriptor* descriptor)
ExtensionGenerator::ExtensionGenerator(
absl::string_view root_or_message_class_name,
const FieldDescriptor* descriptor)
: method_name_(ExtensionMethodName(descriptor)),
root_class_and_method_name_(
absl::StrCat(root_class_name, "_", method_name_)),
full_method_name_(
absl::StrCat(root_or_message_class_name, "_", method_name_)),
descriptor_(descriptor) {
ABSL_CHECK(!descriptor->is_map())
<< "error: Extension is a map<>!"
@ -98,14 +99,14 @@ void ExtensionGenerator::GenerateStaticVariablesInitialization(
absl::StrCat("GPBDataType", GetCapitalizedType(descriptor_))},
{"number", descriptor_->number()},
{"options", BuildFlagsString(FLAGTYPE_EXTENSION, options)},
{"root_class_and_method_name", root_class_and_method_name_},
{"full_method_name", full_method_name_},
{"type", objc_type == OBJECTIVECTYPE_MESSAGE
? ObjCClass(ClassName(descriptor_->message_type()))
: "Nil"}},
R"objc(
{
.defaultValue.$default_name$ = $default$,
.singletonName = GPBStringifySymbol($root_class_and_method_name$),
.singletonName = GPBStringifySymbol($full_method_name$),
.extendedClass.clazz = $extended_type$,
.messageOrGroupClass.clazz = $type$,
.enumDescriptorFunc = $enum_desc_func_name$,
@ -129,9 +130,9 @@ void ExtensionGenerator::DetermineObjectiveCClassDefinitions(
void ExtensionGenerator::GenerateRegistrationSource(
io::Printer* printer) const {
printer->Emit({{"root_class_and_method_name", root_class_and_method_name_}},
printer->Emit({{"full_method_name", full_method_name_}},
R"objc(
[registry addExtension:$root_class_and_method_name$];
[registry addExtension:$full_method_name$];
)objc");
}

@ -44,7 +44,7 @@ namespace objectivec {
class ExtensionGenerator {
public:
ExtensionGenerator(absl::string_view root_class_name,
ExtensionGenerator(absl::string_view root_or_message_class_name,
const FieldDescriptor* descriptor);
~ExtensionGenerator() = default;
@ -59,7 +59,7 @@ class ExtensionGenerator {
private:
std::string method_name_;
std::string root_class_and_method_name_;
std::string full_method_name_;
const FieldDescriptor* descriptor_;
};

@ -72,7 +72,6 @@ class MessageGenerator {
bool IncludesOneOfDefinition() const { return !oneof_generators_.empty(); }
private:
const std::string root_classname_;
const std::string file_description_name_;
const Descriptor* descriptor_;
FieldGeneratorMap field_generators_;

Loading…
Cancel
Save