Skip to content

Commit ad247a4

Browse files
authored
refactor(generator): prepare for upcoming string_view return type change (#14997)
1 parent 7edce95 commit ad247a4

14 files changed

+55
-43
lines changed

generator/internal/client_generator.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ R"""( std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
231231
if (get_iam_policy_extension_ && set_iam_policy_extension_ == &method) {
232232
auto response_type = ProtoNameToCppName(
233233
set_iam_policy_extension_->output_type()->full_name());
234-
auto set_method_name = set_iam_policy_extension_->name();
235-
auto get_method_name = get_iam_policy_extension_->name();
234+
std::string set_method_name{set_iam_policy_extension_->name()};
235+
std::string get_method_name{get_iam_policy_extension_->name()};
236236
HeaderPrint({
237237
PredicatedFragment<void>(""),
238238
{R"""(
@@ -533,8 +533,8 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
533533
if (get_iam_policy_extension_ && set_iam_policy_extension_ == &method) {
534534
auto response_type = ProtoNameToCppName(
535535
set_iam_policy_extension_->output_type()->full_name());
536-
auto set_method_name = set_iam_policy_extension_->name();
537-
auto get_method_name = get_iam_policy_extension_->name();
536+
std::string set_method_name{set_iam_policy_extension_->name()};
537+
std::string get_method_name{get_iam_policy_extension_->name()};
538538
CcPrint({
539539
PredicatedFragment<void>(""),
540540
{"\nStatusOr<" + response_type + ">\n"},

generator/internal/descriptor_utils.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ std::string CppTypeToString(FieldDescriptor const* field) {
572572
GCP_LOG(FATAL) << "FieldDescriptor " << field->cpp_type_name()
573573
<< " not handled";
574574
/*NOTREACHED*/
575-
return field->cpp_type_name();
575+
return std::string{field->cpp_type_name()};
576576
}
577577

578578
std::string FormatMethodCommentsMethodSignature(
@@ -880,13 +880,13 @@ std::map<std::string, VarsDictionary> CreateMethodVars(
880880
if (method.options().HasExtension(google::api::http)) {
881881
http_rule = method.options().GetExtension(google::api::http);
882882
}
883-
service_methods_vars[method.full_name()] =
883+
service_methods_vars[std::string{method.full_name()}] =
884884
GetMethodVars(service, service_config, method, http_rule, "grpc_stub",
885885
idempotency_overrides, omitted_rpcs);
886886
}
887887
for (auto const& mixin_method : mixin_methods) {
888888
auto const& method = mixin_method.method.get();
889-
service_methods_vars[method.full_name()] = GetMethodVars(
889+
service_methods_vars[std::string{method.full_name()}] = GetMethodVars(
890890
service, service_config, method, mixin_method.http_override,
891891
mixin_method.grpc_stub_name, idempotency_overrides, omitted_rpcs);
892892
}

generator/internal/discovery_type_vertex.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,9 @@ StatusOr<int> DiscoveryTypeVertex::GetFieldNumber(
495495

496496
auto qualified_type_name = [](google::protobuf::FieldDescriptor const& f) {
497497
if (f.type() == google::protobuf::FieldDescriptor::TYPE_MESSAGE) {
498-
return f.message_type()->full_name();
498+
return std::string{f.message_type()->full_name()};
499499
}
500-
return std::string(f.type_name());
500+
return std::string{f.type_name()};
501501
};
502502

503503
// Keep the field number the same for existing fields.

generator/internal/doxygen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ std::string FormatDoxygenLink(
2424
google::protobuf::Descriptor const& message_type) {
2525
google::protobuf::SourceLocation loc;
2626
message_type.GetSourceLocation(&loc);
27-
std::string output_type_proto_file_name = message_type.file()->name();
27+
std::string output_type_proto_file_name{message_type.file()->name()};
2828
return absl::StrCat(
2929
"@googleapis_link{", ProtoNameToCppName(message_type.full_name()), ",",
3030
output_type_proto_file_name, "#L", loc.start_line + 1, "}");

generator/internal/format_class_comments_test.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ service Service {
5353
ASSERT_THAT(service, NotNull());
5454

5555
auto const actual = FormatClassCommentsFromServiceComments(
56-
*service, service->name(), absl::nullopt);
56+
*service, std::string{service->name()}, absl::nullopt);
5757

5858
// Verify it has exactly one trailing `///` comment.
5959
EXPECT_THAT(actual, AllOf(EndsWith("\n///"), Not(EndsWith("\n///\n///"))));
@@ -82,7 +82,7 @@ service Service {
8282
ASSERT_THAT(service, NotNull());
8383

8484
auto const actual = FormatClassCommentsFromServiceComments(
85-
*service, service->name(), absl::nullopt);
85+
*service, std::string{service->name()}, absl::nullopt);
8686

8787
auto const lines = std::vector<std::string>{absl::StrSplit(actual, '\n')};
8888
EXPECT_THAT(
@@ -119,7 +119,7 @@ message Resource {
119119
ASSERT_THAT(service, NotNull());
120120

121121
auto const actual = FormatClassCommentsFromServiceComments(
122-
*service, service->name(), absl::nullopt);
122+
*service, std::string{service->name()}, absl::nullopt);
123123

124124
// Verify the first reference is separated by an empty line and that it ends
125125
// with a single `///` comment.
@@ -165,7 +165,7 @@ service Service {
165165
ASSERT_THAT(service, NotNull());
166166

167167
auto const actual = FormatClassCommentsFromServiceComments(
168-
*service, service->name(), absl::nullopt);
168+
*service, std::string{service->name()}, absl::nullopt);
169169
// Verify the relative link is converted to an absolute link.
170170
EXPECT_THAT(actual,
171171
AllOf(HasSubstr("[groups][google.monitoring.v3.Group]"),
@@ -223,7 +223,7 @@ service Service {
223223
ASSERT_THAT(service, NotNull());
224224

225225
auto const actual = FormatClassCommentsFromServiceComments(
226-
*service, service->name(), "New Service comments");
226+
*service, std::string{service->name()}, "New Service comments");
227227
EXPECT_THAT(actual, AllOf(HasSubstr("New Service comments")));
228228
}
229229

generator/internal/format_method_comments.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ auto constexpr kDeprecationComment = R"""( @deprecated This RPC is deprecated.
5454
ProtoDefinitionLocation Location(google::protobuf::Descriptor const& d) {
5555
google::protobuf::SourceLocation loc;
5656
d.GetSourceLocation(&loc);
57-
return ProtoDefinitionLocation{d.file()->name(), loc.start_line + 1};
57+
return ProtoDefinitionLocation{std::string{d.file()->name()},
58+
loc.start_line + 1};
5859
}
5960

6061
std::string ReturnCommentString(

generator/internal/http_option_utils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ absl::optional<QueryParameterInfo> DetermineQueryParameterInfo(
221221
} else {
222222
// But also consider protobuf well known types that wrap simple types.
223223
auto iter = kSupportedWellKnownValueTypes->find(
224-
field.message_type()->full_name());
224+
std::string{field.message_type()->full_name()});
225225
if (iter != kSupportedWellKnownValueTypes->end()) {
226226
param_info = QueryParameterInfo{
227227
iter->second, absl::StrCat("request.", field.name(), "().value()"),

generator/internal/longrunning.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ absl::variant<std::string, Descriptor const*> FullyQualifyMessageType(
4848

4949
struct FullyQualifiedMessageTypeVisitor {
5050
std::string operator()(std::string const& s) const { return s; }
51-
std::string operator()(Descriptor const* d) const { return d->full_name(); }
51+
std::string operator()(Descriptor const* d) const {
52+
return std::string{d->full_name()};
53+
}
5254
};
5355

5456
struct FormatDoxygenLinkVisitor {
@@ -118,7 +120,8 @@ void SetLongrunningOperationMethodVars(
118120
if (IsHttpLongrunningOperation(method)) {
119121
method_vars["longrunning_response_type"] = ProtoNameToCppName(absl::visit(
120122
FullyQualifiedMessageTypeVisitor(),
121-
FullyQualifyMessageType(method, method.output_type()->full_name())));
123+
FullyQualifyMessageType(
124+
method, std::string{method.output_type()->full_name()})));
122125
absl::variant<std::string, google::protobuf::Descriptor const*>
123126
deduced_response_type = method.output_type();
124127
method_vars["longrunning_deduced_response_message_type"] =
@@ -166,10 +169,11 @@ void SetLongrunningOperationServiceVars(
166169
return;
167170
}
168171
if (IsHttpLongrunningOperation(*method)) {
169-
service_vars["longrunning_response_type"] = ProtoNameToCppName(
170-
absl::visit(FullyQualifiedMessageTypeVisitor(),
171-
FullyQualifyMessageType(
172-
*method, method->output_type()->full_name())));
172+
service_vars["longrunning_response_type"] =
173+
ProtoNameToCppName(absl::visit(
174+
FullyQualifiedMessageTypeVisitor(),
175+
FullyQualifyMessageType(
176+
*method, std::string{method->output_type()->full_name()})));
173177
auto operation_service_extension =
174178
method->options().GetExtension(google::cloud::operation_service);
175179

generator/internal/mixin_utils.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ std::unordered_set<std::string> GetMethodNames(
133133
std::unordered_set<std::string> method_names;
134134
for (int i = 0; i < service.method_count(); ++i) {
135135
auto const* method = service.method(i);
136-
method_names.insert(method->name());
136+
method_names.insert(std::string{method->name()});
137137
}
138138
return method_names;
139139
}
@@ -188,14 +188,15 @@ std::vector<MixinMethod> GetMixinMethods(YAML::Node const& service_config,
188188
ServiceDescriptor const* mixin_service = mixin_file->service(i);
189189
for (int j = 0; j < mixin_service->method_count(); ++j) {
190190
MethodDescriptor const* mixin_method = mixin_service->method(j);
191-
auto mixin_method_full_name = mixin_method->full_name();
191+
std::string mixin_method_full_name{mixin_method->full_name()};
192192
// Add the mixin method only if it appears in the http field of YAML
193193
auto const it = mixin_http_overrides.find(mixin_method_full_name);
194194
if (it == mixin_http_overrides.end()) continue;
195195

196196
// If the mixin method name required from YAML appears in the original
197197
// service proto, ignore the mixin.
198-
if (method_names.find(mixin_method->name()) != method_names.end())
198+
if (method_names.find(std::string{mixin_method->name()}) !=
199+
method_names.end())
199200
continue;
200201

201202
mixin_methods.push_back(

generator/internal/pagination.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ google::cloud::optional<PaginationInfo> DetermineAlternatePagination(
133133
if (!items->is_repeated()) return {};
134134

135135
if (items->is_map()) {
136-
return PaginationInfo{items->name(),
136+
return PaginationInfo{std::string{items->name()},
137137
items->message_type()->map_value()->message_type(),
138138
items->message_type()->map_key()};
139139
}
140-
return PaginationInfo{items->name(), items->message_type(), {}};
140+
return PaginationInfo{std::string{items->name()}, items->message_type(), {}};
141141
}
142142

143143
// For the BigQuery v2 proto definitions, the paging conventions
@@ -180,7 +180,8 @@ google::cloud::optional<PaginationInfo> DetermineBigQueryPagination(
180180
FieldDescriptor const* items =
181181
response_message->FindFieldByName(field_name);
182182
if (!items->is_repeated()) return {};
183-
return PaginationInfo{items->name(), items->message_type(), {}};
183+
return PaginationInfo{
184+
std::string{items->name()}, items->message_type(), {}};
184185
}
185186
}
186187

0 commit comments

Comments
 (0)