Skip to content

Instantly share code, notes, and snippets.

@Morfly
Last active August 12, 2021 05:10
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 Morfly/a1c5349c424d0dde68a2e541b7c883f6 to your computer and use it in GitHub Desktop.
Save Morfly/a1c5349c424d0dde68a2e541b7c883f6 to your computer and use it in GitHub Desktop.
override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Unit) {
...
// Getting the list of member properties of the annotated interface.
val properties: Sequence<KSPropertyDeclaration> = classDeclaration.getAllProperties()
.filter { it.validate() }
// Generating function signature.
file += "\n"
if (properties.iterator().hasNext()) {
file += "fun $functionName(\n"
// Iterating through each property to translate them to function arguments.
properties.forEach { prop ->
visitPropertyDeclaration(prop, Unit)
}
file += ") {\n"
} else {
// Otherwise, generating function with no args.
file += "fun $functionName() {\n"
}
// Generating function body
file += " println(\"Hello from $functionName\")\n"
file += "}\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment