[ObjC] Clean up enum fields when not using fwd decls.

Honor the generation option to create the minimal property for enum fields.

PiperOrigin-RevId: 568239992
pull/14182/head
Thomas Van Lenten 1 year ago committed by Copybara-Service
parent f4b102316e
commit 6b30163526
  1. 4
      objectivec/GPBApi.pbobjc.h
  2. 15
      src/google/protobuf/compiler/objectivec/enum_field.cc

@ -120,7 +120,7 @@ GPB_FINAL @interface GPBApi : GPBMessage
@property(nonatomic, readonly) NSUInteger mixinsArray_Count;
/** The source syntax of the service. */
@property(nonatomic, readwrite) enum GPBSyntax syntax;
@property(nonatomic, readwrite) GPBSyntax syntax;
@end
@ -174,7 +174,7 @@ GPB_FINAL @interface GPBMethod : GPBMessage
@property(nonatomic, readonly) NSUInteger optionsArray_Count;
/** The source syntax of this method. */
@property(nonatomic, readwrite) enum GPBSyntax syntax;
@property(nonatomic, readwrite) GPBSyntax syntax;
@end

@ -29,14 +29,17 @@ namespace {
void SetEnumVariables(
const FieldDescriptor* descriptor,
const GenerationOptions& generation_options,
absl::flat_hash_map<absl::string_view, std::string>* variables) {
const std::string type = EnumName(descriptor->enum_type());
const std::string enum_desc_func = absl::StrCat(type, "_EnumDescriptor");
(*variables)["enum_name"] = type;
// For non repeated fields, if it was defined in a different file, the
// property decls need to use "enum NAME" rather than just "NAME" to support
// the forward declaration of the enums.
if (!descriptor->is_repeated() &&
// When using fwd decls, for non repeated fields, if it was defined in a
// different file, the property decls need to use "enum NAME" rather than just
// "NAME" to support the forward declaration of the enums.
if (generation_options.headers_use_forward_declarations &&
!descriptor->is_repeated() &&
!IsProtobufLibraryBundledProtoFile(descriptor->enum_type()->file()) &&
(descriptor->file() != descriptor->enum_type()->file())) {
(*variables)["property_type"] = absl::StrCat("enum ", type, " ");
}
@ -55,7 +58,7 @@ EnumFieldGenerator::EnumFieldGenerator(
const FieldDescriptor* descriptor,
const GenerationOptions& generation_options)
: SingleFieldGenerator(descriptor, generation_options) {
SetEnumVariables(descriptor, &variables_);
SetEnumVariables(descriptor, generation_options, &variables_);
}
void EnumFieldGenerator::GenerateCFunctionDeclarations(
@ -131,7 +134,7 @@ RepeatedEnumFieldGenerator::RepeatedEnumFieldGenerator(
const FieldDescriptor* descriptor,
const GenerationOptions& generation_options)
: RepeatedFieldGenerator(descriptor, generation_options) {
SetEnumVariables(descriptor, &variables_);
SetEnumVariables(descriptor, generation_options, &variables_);
}
void RepeatedEnumFieldGenerator::EmitArrayComment(io::Printer* printer) const {

Loading…
Cancel
Save