Use Printer::Emit formatting to remove optional args from GetOptionalDeprecatedAttribute.

PiperOrigin-RevId: 547303540
pull/13270/head
Thomas Van Lenten 2 years ago committed by Copybara-Service
parent 0196d1e138
commit d8b1a626dd
  1. 4
      src/google/protobuf/compiler/objectivec/enum.cc
  2. 2
      src/google/protobuf/compiler/objectivec/extension.cc
  3. 16
      src/google/protobuf/compiler/objectivec/field.cc
  4. 9
      src/google/protobuf/compiler/objectivec/helpers.h
  5. 10
      src/google/protobuf/compiler/objectivec/message.cc

@ -139,7 +139,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) const {
}, },
R"objc( R"objc(
$comments$ $comments$
$name$$deprecated_attribute$ = $value$, $name$$ deprecated_attribute$ = $value$,
)objc"); )objc");
comment_flags = CommentStringFlags::kAddLeadingNewline; comment_flags = CommentStringFlags::kAddLeadingNewline;
} }
@ -149,7 +149,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) const {
#pragma mark - Enum $enum_name$ #pragma mark - Enum $enum_name$
$enum_comments$ $enum_comments$
typedef$enum_deprecated_attribute$ GPB_ENUM($enum_name$) { typedef$ enum_deprecated_attribute$ GPB_ENUM($enum_name$) {
$maybe_unknown_value$ $maybe_unknown_value$
$enum_values$ $enum_values$
}; };

@ -69,7 +69,7 @@ void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) const {
GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file())}}, GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file())}},
R"objc( R"objc(
$comments$ $comments$
+ (GPBExtensionDescriptor *)$method_name$$ storage_attribute$$deprecated_attribute$; + (GPBExtensionDescriptor *)$method_name$$ storage_attribute$$ deprecated_attribute$;
)objc"); )objc");
} }

@ -316,11 +316,11 @@ void SingleFieldGenerator::GeneratePropertyDeclaration(
{{"comments", [&] { EmitCommentsString(printer, descriptor_); }}}, {{"comments", [&] { EmitCommentsString(printer, descriptor_); }}},
R"objc( R"objc(
$comments$ $comments$
@property(nonatomic, readwrite) $property_type$ $name$$deprecated_attribute$; @property(nonatomic, readwrite) $property_type$ $name$$ deprecated_attribute$;
)objc"); )objc");
if (WantsHasProperty()) { if (WantsHasProperty()) {
printer->Emit(R"objc( printer->Emit(R"objc(
@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$; @property(nonatomic, readwrite) BOOL has$capitalized_name$$ deprecated_attribute$;
)objc"); )objc");
} }
printer->Emit("\n"); printer->Emit("\n");
@ -369,19 +369,19 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration(
{{"comments", [&] { EmitCommentsString(printer, descriptor_); }}}, {{"comments", [&] { EmitCommentsString(printer, descriptor_); }}},
R"objc( R"objc(
$comments$ $comments$
@property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$ *$name$$storage_attribute$$deprecated_attribute$; @property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$ *$name$$storage_attribute$$ deprecated_attribute$;
)objc"); )objc");
if (WantsHasProperty()) { if (WantsHasProperty()) {
printer->Emit(R"objc( printer->Emit(R"objc(
/** Test to see if @c $name$ has been set. */ /** Test to see if @c $name$ has been set. */
@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$; @property(nonatomic, readwrite) BOOL has$capitalized_name$$ deprecated_attribute$;
)objc"); )objc");
} }
if (IsInitName(variables_.find("name")->second)) { if (IsInitName(variables_.find("name")->second)) {
// If property name starts with init we need to annotate it to get past ARC. // If property name starts with init we need to annotate it to get past ARC.
// http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227 // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
printer->Emit(R"objc( printer->Emit(R"objc(
- ($property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$deprecated_attribute$; - ($property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$ deprecated_attribute$;
)objc"); )objc");
} }
printer->Emit("\n"); printer->Emit("\n");
@ -425,15 +425,15 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration(
R"objc( R"objc(
$comments$ $comments$
$array_comment$ $array_comment$
@property(nonatomic, readwrite, strong, null_resettable) $array_property_type$ *$name$$storage_attribute$$deprecated_attribute$; @property(nonatomic, readwrite, strong, null_resettable) $array_property_type$ *$name$$storage_attribute$$ deprecated_attribute$;
/** The number of items in @c $name$ without causing the container to be created. */ /** The number of items in @c $name$ without causing the container to be created. */
@property(nonatomic, readonly) NSUInteger $name$_Count$deprecated_attribute$; @property(nonatomic, readonly) NSUInteger $name$_Count$ deprecated_attribute$;
)objc"); )objc");
if (IsInitName(variables_.find("name")->second)) { if (IsInitName(variables_.find("name")->second)) {
// If property name starts with init we need to annotate it to get past ARC. // If property name starts with init we need to annotate it to get past ARC.
// http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227 // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
printer->Emit(R"objc( printer->Emit(R"objc(
- ($array_property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$deprecated_attribute$; - ($array_property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$ deprecated_attribute$;
)objc"); )objc");
} }
printer->Emit("\n"); printer->Emit("\n");

@ -136,10 +136,8 @@ void EmitCommentsString(io::Printer* printer, const TDescriptor* descriptor,
} }
template <class TDescriptor> template <class TDescriptor>
std::string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor, std::string GetOptionalDeprecatedAttribute(
const FileDescriptor* file = nullptr, const TDescriptor* descriptor, const FileDescriptor* file = nullptr) {
bool preSpace = true,
bool postNewline = false) {
bool isDeprecated = descriptor->options().deprecated(); bool isDeprecated = descriptor->options().deprecated();
// The file is only passed when checking Messages & Enums, so those types // The file is only passed when checking Messages & Enums, so those types
// get tagged. At the moment, it doesn't seem to make sense to tag every // get tagged. At the moment, it doesn't seem to make sense to tag every
@ -159,8 +157,7 @@ std::string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor,
sourceFile->name(), ")."); sourceFile->name(), ").");
} }
return absl::StrCat(preSpace ? " " : "", "GPB_DEPRECATED_MSG(\"", message, return absl::StrCat("GPB_DEPRECATED_MSG(\"", message, "\")");
"\")", postNewline ? "\n" : "");
} else { } else {
return ""; return "";
} }

@ -219,8 +219,8 @@ MessageGenerator::MessageGenerator(const std::string& file_description_name,
descriptor_(descriptor), descriptor_(descriptor),
field_generators_(descriptor), field_generators_(descriptor),
class_name_(ClassName(descriptor_)), class_name_(ClassName(descriptor_)),
deprecated_attribute_(GetOptionalDeprecatedAttribute( deprecated_attribute_(
descriptor, descriptor->file(), false, true)) { GetOptionalDeprecatedAttribute(descriptor, descriptor->file())) {
for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) { for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) {
oneof_generators_.push_back( oneof_generators_.push_back(
std::make_unique<OneofGenerator>(descriptor_->oneof_decl(i))); std::make_unique<OneofGenerator>(descriptor_->oneof_decl(i)));
@ -304,7 +304,8 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) const {
auto vars = printer->WithVars({{"classname", class_name_}}); auto vars = printer->WithVars({{"classname", class_name_}});
printer->Emit( printer->Emit(
{{"deprecated_attribute", deprecated_attribute_}, {io::Printer::Sub("deprecated_attribute", deprecated_attribute_)
.WithSuffix(";"),
{"message_comments", {"message_comments",
[&] { [&] {
EmitCommentsString(printer, descriptor_, EmitCommentsString(printer, descriptor_,
@ -358,7 +359,8 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) const {
$message_fieldnum_enum$ $message_fieldnum_enum$
$oneof_enums$ $oneof_enums$
$message_comments$ $message_comments$
$deprecated_attribute$GPB_FINAL @interface $classname$ : GPBMessage $deprecated_attribute$;
GPB_FINAL @interface $classname$ : GPBMessage
$message_properties$ $message_properties$
@end @end

Loading…
Cancel
Save