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

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

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

Loading…
Cancel
Save