Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ GoldenKitchenSinkMetadata::ExplicitRouting1(
{[](google::test::admin::database::v1::ExplicitRoutingRequest const& request) -> std::string const& {
return request.app_profile_id();
},
absl::nullopt},
std::nullopt},
{[](google::test::admin::database::v1::ExplicitRoutingRequest const& request) -> std::string const& {
return request.table_name();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ GoldenKitchenSinkRestMetadata::ExplicitRouting1(
{[](google::test::admin::database::v1::ExplicitRoutingRequest const& request) -> std::string const& {
return request.app_profile_id();
},
absl::nullopt},
std::nullopt},
{[](google::test::admin::database::v1::ExplicitRoutingRequest const& request) -> std::string const& {
return request.table_name();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ TEST(GoldenKitchenSinkClientTest, AsyncStreamingReadWrite) {
.WillOnce([] {
Response response;
response.set_response("test-only-response");
return make_ready_future(absl::make_optional(response));
return make_ready_future(std::make_optional(response));
})
.WillOnce([] { return make_ready_future(absl::optional<Response>()); });
.WillOnce([] { return make_ready_future(std::optional<Response>()); });
EXPECT_CALL(*stream, Finish).WillOnce([] {
return make_ready_future(Status(StatusCode::kUnavailable, "try-again"));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using ::google::cloud::golden_v1::GoldenKitchenSinkRetryPolicyOption;
using ::google::cloud::testing_util::ScopedEnvironment;

TEST(GoldenKitchenSinkDefaultOptions, DefaultEndpoint) {
auto env = ScopedEnvironment("GOLDEN_KITCHEN_SINK_ENDPOINT", absl::nullopt);
auto env = ScopedEnvironment("GOLDEN_KITCHEN_SINK_ENDPOINT", std::nullopt);
Options options;
auto updated_options = GoldenKitchenSinkDefaultOptions(options);
EXPECT_EQ("goldenkitchensink.googleapis.com",
Expand All @@ -57,7 +57,7 @@ TEST(GoldenKitchenSinkDefaultOptions, OptionEndpoint) {
}

TEST(GoldenKitchenSinkDefaultOptions, UserProjectDefault) {
auto env = ScopedEnvironment("GOOGLE_CLOUD_CPP_USER_PROJECT", absl::nullopt);
auto env = ScopedEnvironment("GOOGLE_CLOUD_CPP_USER_PROJECT", std::nullopt);
auto options = Options{};
auto updated_options = GoldenKitchenSinkDefaultOptions(options);
EXPECT_FALSE(updated_options.has<UserProjectOption>());
Expand All @@ -72,7 +72,7 @@ TEST(GoldenKitchenSinkDefaultOptions, UserProjectEnvVar) {
}

TEST(GoldenKitchenSinkDefaultOptions, UserProjectOptions) {
auto env = ScopedEnvironment("GOOGLE_CLOUD_CPP_USER_PROJECT", absl::nullopt);
auto env = ScopedEnvironment("GOOGLE_CLOUD_CPP_USER_PROJECT", std::nullopt);
auto options = Options{}.set<UserProjectOption>("another-project");
auto updated_options = GoldenKitchenSinkDefaultOptions(options);
EXPECT_EQ("another-project", updated_options.get<UserProjectOption>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ TEST(GoldenThingAdminClientTest, SetIamPolicyUpdaterCancelled) {
auto response = client.SetIamPolicy(
expected_database, [etag_old](::google::iam::v1::Policy const& policy) {
EXPECT_EQ(etag_old, policy.etag());
return absl::nullopt;
return std::nullopt;
});
ASSERT_THAT(response, Not(IsOk()));
EXPECT_THAT(response, StatusIs(StatusCode::kCancelled));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class MockStreamingReadRpc
::google::test::admin::database::v1::Response> {
public:
MOCK_METHOD(void, Cancel, (), (override));
MOCK_METHOD((absl::optional<Status>), Read,
MOCK_METHOD((std::optional<Status>), Read,
(::google::test::admin::database::v1::Response*), (override));
MOCK_METHOD(RpcMetadata, GetRequestMetadata, (), (const, override));
};
Expand Down
14 changes: 7 additions & 7 deletions generator/internal/descriptor_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ bool IsKnownIdempotentMethod(google::protobuf::MethodDescriptor const& m) {

std::string DefaultIdempotencyFromHttpOperation(
google::protobuf::MethodDescriptor const& method,
absl::optional<google::api::HttpRule> http_rule) {
std::optional<google::api::HttpRule> http_rule) {
if (IsKnownIdempotentMethod(method)) return "kIdempotent";
if (http_rule) {
switch (http_rule->pattern_case()) {
Expand Down Expand Up @@ -495,26 +495,26 @@ std::string GetEffectiveServiceName(VarsDictionary const& vars,
// If it does not exist, return a null optional.
// Parses a command line argument in the form:
// {"service_name_to_comments": "service_a=comment_a,service_b=comment_b"}.
absl::optional<std::string> GetReplacementComment(VarsDictionary const& vars,
absl::string_view name) {
std::optional<std::string> GetReplacementComment(VarsDictionary const& vars,
absl::string_view name) {
auto service_name_to_comments = vars.find("service_name_to_comments");
if (service_name_to_comments == vars.end()) {
return absl::nullopt;
return std::nullopt;
}
for (absl::string_view arg :
absl::StrSplit(service_name_to_comments->second, ',')) {
std::pair<absl::string_view, absl::string_view> p =
absl::StrSplit(arg, absl::MaxSplits('=', 1));
if (p.first == name) return std::string(p.second.data(), p.second.size());
}
return absl::nullopt;
return std::nullopt;
}

VarsDictionary GetMethodVars(
google::protobuf::ServiceDescriptor const& service,
YAML::Node const& service_config,
google::protobuf::MethodDescriptor const& method,
absl::optional<google::api::HttpRule> const& http_rule,
std::optional<google::api::HttpRule> const& http_rule,
std::string const& grpc_stub_name,
VarsDictionary const& idempotency_overrides,
std::set<std::string> const& omitted_rpcs) {
Expand Down Expand Up @@ -892,7 +892,7 @@ std::map<std::string, VarsDictionary> CreateMethodVars(
std::map<std::string, VarsDictionary> service_methods_vars;
for (int i = 0; i < service.method_count(); i++) {
auto const& method = *service.method(i);
absl::optional<google::api::HttpRule> http_rule;
std::optional<google::api::HttpRule> http_rule;
if (method.options().HasExtension(google::api::http)) {
http_rule = method.options().GetExtension(google::api::http);
}
Expand Down
4 changes: 2 additions & 2 deletions generator/internal/discovery_resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace {
// that we need to introduce additional in the future if we come across other
// LRO defining conventions.
// https://cloud.google.com/compute/docs/regions-zones/global-regional-zonal-resources
absl::optional<std::string> DetermineLongRunningOperationService(
std::optional<std::string> DetermineLongRunningOperationService(
nlohmann::json const& method_json, std::vector<std::string> const& params,
std::set<std::string> const& operation_services,
std::string const& resource_name) {
Expand All @@ -56,7 +56,7 @@ absl::optional<std::string> DetermineLongRunningOperationService(
}
return "GlobalOrganizationOperations";
}
return absl::nullopt;
return std::nullopt;
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion generator/internal/discovery_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class DiscoveryResource {
nlohmann::json json_;
std::map<std::string, DiscoveryTypeVertex*> request_types_;
std::map<std::string, DiscoveryTypeVertex*> response_types_;
absl::optional<StatusOr<std::string>> service_api_version_;
std::optional<StatusOr<std::string>> service_api_version_;
};

} // namespace generator_internal
Expand Down
6 changes: 3 additions & 3 deletions generator/internal/discovery_type_vertex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include "absl/strings/str_join.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "absl/types/optional.h"
#include "google/protobuf/descriptor.pb.h"
#include <cassert>
#include <optional>
#include <set>

namespace google {
Expand All @@ -33,13 +33,13 @@ namespace {

auto constexpr kInitialFieldNumber = 1;

absl::optional<std::string> CheckForScalarType(nlohmann::json const& j) {
std::optional<std::string> CheckForScalarType(nlohmann::json const& j) {
std::string type = j.value("type", "");
if (type == "string") return "string";
if (type == "boolean") return "bool";
if (type == "integer") return j.value("format", "int32");
if (type == "number") return j.value("format", "float");
return absl::nullopt;
return std::nullopt;
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion generator/internal/format_class_comments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ auto constexpr kFixedClientComment = R"""(
std::string FormatClassCommentsFromServiceComments(
google::protobuf::ServiceDescriptor const& service,
std::string const& service_name,
absl::optional<std::string> const& replacement_comment) {
std::optional<std::string> const& replacement_comment) {
google::protobuf::SourceLocation service_source_location;
std::string formatted_comments;
// Use the service descriptor to populate the service_source_location.
Expand Down
2 changes: 1 addition & 1 deletion generator/internal/format_class_comments.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace generator_internal {
std::string FormatClassCommentsFromServiceComments(
google::protobuf::ServiceDescriptor const& service,
std::string const& service_name,
absl::optional<std::string> const& replacement_comment);
std::optional<std::string> const& replacement_comment);

} // namespace generator_internal
} // namespace cloud
Expand Down
10 changes: 5 additions & 5 deletions generator/internal/format_class_comments_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ service Service {
ASSERT_THAT(service, NotNull());

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

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

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

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

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

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

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

auto const actual = FormatClassCommentsFromServiceComments(
*service, "NewService", absl::nullopt);
*service, "NewService", std::nullopt);
EXPECT_THAT(actual, AllOf(HasSubstr("NewService")));
}

Expand Down
18 changes: 9 additions & 9 deletions generator/internal/http_option_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#include "absl/strings/str_join.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "absl/types/optional.h"
#include "google/api/annotations.pb.h"
#include <google/protobuf/compiler/cpp/names.h>
#include <google/protobuf/descriptor.h>
#include <optional>
#include <regex>
#include <vector>

Expand All @@ -54,12 +54,12 @@ std::string FormatFieldAccessorCall(
return absl::StrJoin(chunks, "().");
}

void RestPathVisitorHelper(absl::optional<std::string> api_version,
void RestPathVisitorHelper(std::optional<std::string> api_version,
PathTemplate::Segment const& s,
std::vector<HttpExtensionInfo::RestPathPiece>& path);

struct RestPathVisitor {
explicit RestPathVisitor(absl::optional<std::string> api_version,
explicit RestPathVisitor(std::optional<std::string> api_version,
std::vector<HttpExtensionInfo::RestPathPiece>& path)
: api_version(std::move(api_version)), path(path) {}
void operator()(PathTemplate::Match const&) {}
Expand Down Expand Up @@ -89,12 +89,12 @@ struct RestPathVisitor {
RestPathVisitorHelper(api_version, s, path);
}

absl::optional<std::string> api_version;
std::optional<std::string> api_version;
std::vector<HttpExtensionInfo::RestPathPiece>& path;
};

void RestPathVisitorHelper(
absl::optional<std::string> api_version, PathTemplate::Segment const& s,
std::optional<std::string> api_version, PathTemplate::Segment const& s,
std::vector<HttpExtensionInfo::RestPathPiece>& path) {
absl::visit(RestPathVisitor{std::move(api_version), path}, s.value);
}
Expand Down Expand Up @@ -187,7 +187,7 @@ void SetHttpDerivedMethodVars(HttpExtensionInfo const& info,
absl::StrCat(R"""(absl::StrCat("/")""", path_expression(true), trailer());
}

absl::optional<QueryParameterInfo> DetermineQueryParameterInfo(
std::optional<QueryParameterInfo> DetermineQueryParameterInfo(
google::protobuf::FieldDescriptor const& field) {
static auto* const kSupportedWellKnownValueTypes = [] {
auto foo = std::make_unique<
Expand All @@ -211,7 +211,7 @@ absl::optional<QueryParameterInfo> DetermineQueryParameterInfo(
return foo.release();
}();

absl::optional<QueryParameterInfo> param_info;
std::optional<QueryParameterInfo> param_info;
// Only attempt to make non-repeated, simple fields query parameters.
if (!field.is_repeated() && !field.options().deprecated()) {
// TODO(#15707): Most services will error if this is set at all. Skip it
Expand Down Expand Up @@ -384,7 +384,7 @@ std::string FormatRequestResource(google::protobuf::Descriptor const& request,

// Generate api version by extracting the version from the url pattern.
// In some cases(i.e. location), there is no version in the package name.
absl::optional<std::string> FormatApiVersionFromUrlPattern(
std::optional<std::string> FormatApiVersionFromUrlPattern(
std::string const& url_pattern) {
std::vector<std::string> const parts = absl::StrSplit(url_pattern, '/');
static auto const* const kVersion = new std::regex{R"(v\d+)"};
Expand All @@ -393,7 +393,7 @@ absl::optional<std::string> FormatApiVersionFromUrlPattern(
return part;
}
}
return absl::nullopt;
return std::nullopt;
}

} // namespace generator_internal
Expand Down
6 changes: 3 additions & 3 deletions generator/internal/http_option_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include "generator/internal/http_annotation_parser.h"
#include "generator/internal/mixin_utils.h"
#include "generator/internal/printer.h"
#include "absl/types/optional.h"
#include "google/api/http.pb.h"
#include <google/protobuf/descriptor.h>
#include <optional>
#include <string>

namespace google {
Expand Down Expand Up @@ -74,7 +74,7 @@ struct QueryParameterInfo {
* bool, and string native protobuf data types, as well as, protobuf "Well Known
* Types" that wrap those data types.
*/
absl::optional<QueryParameterInfo> DetermineQueryParameterInfo(
std::optional<QueryParameterInfo> DetermineQueryParameterInfo(
google::protobuf::FieldDescriptor const& field);

/**
Expand Down Expand Up @@ -111,7 +111,7 @@ std::string FormatRequestResource(google::protobuf::Descriptor const& request,
/**
* Parses the url pattern of the method and returns its API version.
*/
absl::optional<std::string> FormatApiVersionFromUrlPattern(
std::optional<std::string> FormatApiVersionFromUrlPattern(
std::string const& url_pattern);

} // namespace generator_internal
Expand Down
2 changes: 1 addition & 1 deletion generator/internal/http_option_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ TEST_F(HttpOptionUtilsTest, FormatApiVersionFromUrlPattern) {

TEST_F(HttpOptionUtilsTest, FormatApiVersionFromUrlPatternNonExist) {
std::string url_pattern = "/foo/bar";
EXPECT_THAT(FormatApiVersionFromUrlPattern(url_pattern), Eq(absl::nullopt));
EXPECT_THAT(FormatApiVersionFromUrlPattern(url_pattern), Eq(std::nullopt));
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion generator/internal/mixin_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include "absl/base/no_destructor.h"
#include "absl/strings/ascii.h"
#include "absl/strings/str_join.h"
#include "absl/types/optional.h"
#include <google/protobuf/compiler/code_generator.h>
#include <yaml-cpp/yaml.h>
#include <iostream>
#include <optional>
#include <string>
#include <unordered_map>
#include <unordered_set>
Expand Down
2 changes: 1 addition & 1 deletion generator/internal/mixin_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#ifndef GOOGLE_CLOUD_CPP_GENERATOR_INTERNAL_MIXIN_UTILS_H
#define GOOGLE_CLOUD_CPP_GENERATOR_INTERNAL_MIXIN_UTILS_H

#include "absl/types/optional.h"
#include "google/api/http.pb.h"
#include <google/protobuf/compiler/code_generator.h>
#include <yaml-cpp/yaml.h>
#include <optional>
#include <string>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion generator/internal/pagination.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool IsPaginated(google::protobuf::MethodDescriptor const& method);
struct PaginationInfo {
std::string range_output_field_name;
google::protobuf::Descriptor const* range_output_type;
absl::optional<google::protobuf::FieldDescriptor const*>
std::optional<google::protobuf::FieldDescriptor const*>
range_output_map_key_type;
};

Expand Down
Loading
Loading