Skip to content

Instantly share code, notes, and snippets.

@drawers
Last active January 29, 2023 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drawers/a86cd64fd8123acc8e50e556229e81d9 to your computer and use it in GitHub Desktop.
Save drawers/a86cd64fd8123acc8e50e556229e81d9 to your computer and use it in GitHub Desktop.
// 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