Incremental migration of message.cc to Emit

PiperOrigin-RevId: 530457337
pull/12733/head
Matt Kulukundis 2 years ago committed by Copybara-Service
parent a4614a9002
commit 11388e85fa
  1. 26
      src/google/protobuf/compiler/cpp/message.cc

@ -1858,19 +1858,19 @@ void MessageGenerator::GenerateInlineMethods(io::Printer* p) {
// Generate oneof_case() functions.
for (auto oneof : OneOfRange(descriptor_)) {
Formatter format(p);
auto v = p->WithVars({
{"camel_oneof_name", UnderscoresToCamelCase(oneof->name(), true)},
{"oneof_name", oneof->name()},
{"oneof_index", oneof->index()},
});
format(
"inline $classname$::$camel_oneof_name$Case $classname$::"
"${1$$oneof_name$_case$}$() const {\n"
" return $classname$::$camel_oneof_name$Case("
"$oneof_case$[$oneof_index$]);\n"
"}\n",
oneof);
p->Emit(
{
Sub{"oneof_name", absl::StrCat(oneof->name(), "_case")}.AnnotatedAs(
oneof),
{"OneofName",
absl::StrCat(UnderscoresToCamelCase(oneof->name(), true), "Case")},
{"oneof_index", oneof->index()},
},
R"cc(
inline $classname$::$OneofName$ $classname$::$oneof_name$() const {
return $classname$::$OneofName$($oneof_case$[$oneof_index$]);
}
)cc");
}
}

Loading…
Cancel
Save