cpp: handle generic type-parameters before @nullable
CppNameOf() should handle type-parameters first before applying
@nullable.
Bug: 188237977
Test: aidl_unittests
Change-Id: Ia5e2c7d6f8935646049110559cb46620dad0cd95
diff --git a/aidl_to_cpp.cpp b/aidl_to_cpp.cpp
index 40552c8..e7125f9 100644
--- a/aidl_to_cpp.cpp
+++ b/aidl_to_cpp.cpp
@@ -186,8 +186,15 @@
if (definedType != nullptr && definedType->AsInterface() != nullptr) {
return "::android::sp<" + GetRawCppName(type) + ">";
}
-
- return WrapIfNullable(GetRawCppName(type), raw_type, typenames);
+ auto cpp_name = GetRawCppName(type);
+ if (type.IsGeneric()) {
+ std::vector<std::string> type_params;
+ for (const auto& parameter : type.GetTypeParameters()) {
+ type_params.push_back(CppNameOf(*parameter, typenames));
+ }
+ cpp_name += "<" + base::Join(type_params, ", ") + ">";
+ }
+ return WrapIfNullable(cpp_name, raw_type, typenames);
}
} // namespace
std::string ConstantValueDecorator(const AidlTypeSpecifier& type, const std::string& raw_value) {
@@ -223,13 +230,6 @@
return "::std::optional<::std::vector<" + cpp_name + ">>";
}
return "::std::vector<" + cpp_name + ">";
- } else if (type.IsGeneric()) {
- std::vector<std::string> type_params;
- for (const auto& parameter : type.GetTypeParameters()) {
- type_params.push_back(CppNameOf(*parameter, typenames));
- }
- return StringPrintf("%s<%s>", GetCppName(type, typenames).c_str(),
- base::Join(type_params, ", ").c_str());
}
return GetCppName(type, typenames);
}