Skip to content

Instantly share code, notes, and snippets.

@drawers
Last active Jan 29, 2023
Embed
What would you like to do?
// continued from above
if (summables.isEmpty()) {
return
}
val fileSpec = FileSpec.builder(
packageName = packageName,
fileName = classDeclaration.simpleName.asString() + "Ext"
).apply {
addFunction(
FunSpec.builder("sumInts")
.receiver(ksType.toTypeName(TypeParameterResolver.EMPTY))
.returns(Int::class)
.addStatement("val sum = %L", summables.joinToString(" + "))
.addStatement("return sum")
.build()
)
}.build()
fileSpec.writeTo(codeGenerator = codeGenerator, aggregating = false)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment