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

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

@ -316,11 +316,11 @@ void SingleFieldGenerator::GeneratePropertyDeclaration(
{{"comments", [&] { EmitCommentsString(printer, descriptor_); }}},
R"objc(
$comments$
@property(nonatomic, readwrite) $property_type$ $name$$deprecated_attribute$;
@property(nonatomic, readwrite) $property_type$ $name$$ deprecated_attribute$;
)objc");
if (WantsHasProperty()) {
printer->Emit(R"objc(
@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$;
@property(nonatomic, readwrite) BOOL has$capitalized_name$$ deprecated_attribute$;
)objc");
}
printer->Emit("\n");
@ -369,19 +369,19 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration(
{{"comments", [&] { EmitCommentsString(printer, descriptor_); }}},
R"objc(
$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");
if (WantsHasProperty()) {
printer->Emit(R"objc(
/** 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");
}
if (IsInitName(variables_.find("name")->second)) {
// 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
printer->Emit(R"objc(
- ($property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$deprecated_attribute$;
- ($property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$ deprecated_attribute$;
)objc");
}
printer->Emit("\n");
@ -425,15 +425,15 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration(
R"objc(
$comments$
$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. */
@property(nonatomic, readonly) NSUInteger $name$_Count$deprecated_attribute$;
@property(nonatomic, readonly) NSUInteger $name$_Count$ deprecated_attribute$;
)objc");
if (IsInitName(variables_.find("name")->second)) {
// 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
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");
}
printer->Emit("\n");

@ -136,10 +136,8 @@ void EmitCommentsString(io::Printer* printer, const TDescriptor* descriptor,
}
template <class TDescriptor>
std::string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor,
const FileDescriptor* file = nullptr,
bool preSpace = true,
bool postNewline = false) {
std::string GetOptionalDeprecatedAttribute(
const TDescriptor* descriptor, const FileDescriptor* file = nullptr) {
bool isDeprecated = descriptor->options().deprecated();
// 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
@ -159,8 +157,7 @@ std::string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor,
sourceFile->name(), ").");
}
return absl::StrCat(preSpace ? " " : "", "GPB_DEPRECATED_MSG(\"", message,
"\")", postNewline ? "\n" : "");
return absl::StrCat("GPB_DEPRECATED_MSG(\"", message, "\")");
} else {
return "";
}

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

Loading…
Cancel
Save