[Dart] Fix namespace alias from union type (#9088)

* Fix namespace alias from union type

* Fix namespace alias from union type
This commit is contained in:
Jakob Kordež
2026-05-25 03:13:42 +02:00
committed by GitHub
parent 1f438bd40f
commit 38df29380a

View File

@@ -654,34 +654,15 @@ class DartGenerator : public BaseGenerator {
std::string NamespaceAliasFromUnionType(Namespace* root_namespace, std::string NamespaceAliasFromUnionType(Namespace* root_namespace,
const Type& type) { const Type& type) {
const std::vector<std::string> qualified_name_parts = const Namespace& type_namespace = *type.struct_def->defined_namespace;
type.struct_def->defined_namespace->components; if (root_namespace->components == type_namespace.components) {
if (std::equal(root_namespace->components.begin(),
root_namespace->components.end(),
qualified_name_parts.begin())) {
return namer_.Type(*type.struct_def); return namer_.Type(*type.struct_def);
} }
std::string ns; const std::string ns = namer_.Namespace(type_namespace);
return ns.empty()
for (auto it = qualified_name_parts.begin(); ? namer_.Type(*type.struct_def)
it != qualified_name_parts.end(); ++it) { : ImportAliasName(ns) + "." + namer_.Type(*type.struct_def);
auto& part = *it;
for (size_t i = 0; i < part.length(); i++) {
if (i && !isdigit(part[i]) && part[i] == CharToUpper(part[i])) {
ns += "_";
ns += CharToLower(part[i]);
} else {
ns += CharToLower(part[i]);
}
}
if (it != qualified_name_parts.end() - 1) {
ns += "_";
}
}
return ns + "." + namer_.Type(*type.struct_def);
} }
void GenImplementationGetters( void GenImplementationGetters(