in thrifty-kotlin-codegen/src/main/kotlin/com/microsoft/thrifty/kgen/KotlinCodeGenerator.kt [161:218]
override fun load(key: UserElement?): NameAllocator {
val elem = requireNotNull(key) { "Can't get a name allocator for null" }
return NameAllocator().apply {
when (elem) {
is StructType -> {
newName("ADAPTER", Tags.ADAPTER)
if (elem.isException) {
newName("message", Tags.MESSAGE)
newName("cause", Tags.CAUSE)
}
if (elem.isUnion && elem.fields.any { it.defaultValue != null }) {
newName("DEFAULT", Tags.DEFAULT)
}
for (field in elem.fields) {
val conformingName = fieldNamingPolicy.apply(field.name)
newName(conformingName, field)
}
newName("result", Tags.RESULT)
}
is EnumType -> {
newName("findByValue", Tags.FIND_BY_VALUE)
newName("value", Tags.VALUE)
for (member in elem.members) {
newName(member.name, member)
}
}
is ServiceType -> {
for (method in elem.methods) {
newName(method.name, method)
}
}
is ServiceMethod -> {
newName("callback", Tags.CALLBACK)
newName("send", Tags.SEND)
newName("receive", Tags.RECEIVE)
newName("resultValue", Tags.RESULT)
newName("fieldMeta", Tags.FIELD)
for (param in elem.parameters) {
newName(param.name, param)
}
for (ex in elem.exceptions) {
newName(ex.name, ex)
}
}
else -> error("Unexpected UserElement: $key")
}
}
}