Replace Maybe with std::optional
With c++17, std::optional provides the functionality that Maybe
provided.
Bug: 183215655
Test: aapt2_tests
Change-Id: I62bb9c2fa4985dc5217a6ed153df92b85ad9a034
diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp
index de6524d..3b3c6e1 100644
--- a/tools/aapt2/java/JavaClassGenerator.cpp
+++ b/tools/aapt2/java/JavaClassGenerator.cpp
@@ -204,7 +204,7 @@
}
// Whether or not to skip writing this symbol.
-bool JavaClassGenerator::SkipSymbol(const Maybe<SymbolTable::Symbol>& symbol) {
+bool JavaClassGenerator::SkipSymbol(const std::optional<SymbolTable::Symbol>& symbol) {
return !symbol || (options_.types == JavaClassGeneratorOptions::SymbolTypes::kPublic &&
!symbol.value().is_public);
}
@@ -212,12 +212,12 @@
struct StyleableAttr {
const Reference* attr_ref = nullptr;
std::string field_name;
- Maybe<SymbolTable::Symbol> symbol;
+ std::optional<SymbolTable::Symbol> symbol;
};
static bool operator<(const StyleableAttr& lhs, const StyleableAttr& rhs) {
- const ResourceId lhs_id = lhs.attr_ref->id.value_or_default(ResourceId(0));
- const ResourceId rhs_id = rhs.attr_ref->id.value_or_default(ResourceId(0));
+ const ResourceId lhs_id = lhs.attr_ref->id.value_or(ResourceId(0));
+ const ResourceId rhs_id = rhs.attr_ref->id.value_or(ResourceId(0));
if (lhs_id == rhs_id) {
return lhs.attr_ref->name.value() < rhs.attr_ref->name.value();
}
@@ -362,7 +362,7 @@
array_def->AddElement(field_name);
r_txt_contents = field_name.ref;
} else {
- const ResourceId attr_id = attr.attr_ref->id.value_or_default(ResourceId(0));
+ const ResourceId attr_id = attr.attr_ref->id.value_or(ResourceId(0));
array_def->AddElement(attr_id);
r_txt_contents = to_string(attr_id);
}
@@ -504,9 +504,9 @@
}
}
-Maybe<std::string> JavaClassGenerator::UnmangleResource(const StringPiece& package_name,
- const StringPiece& package_name_to_generate,
- const ResourceEntry& entry) {
+std::optional<std::string> JavaClassGenerator::UnmangleResource(
+ const StringPiece& package_name, const StringPiece& package_name_to_generate,
+ const ResourceEntry& entry) {
if (SkipSymbol(entry.visibility.level)) {
return {};
}
@@ -535,7 +535,7 @@
MethodDefinition* out_rewrite_method_def,
Printer* r_txt_printer) {
for (const auto& entry : type.entries) {
- const Maybe<std::string> unmangled_name =
+ const std::optional<std::string> unmangled_name =
UnmangleResource(package.name, package_name_to_generate, *entry);
if (!unmangled_name) {
continue;