Skip to content

Instantly share code, notes, and snippets.

@navi25
Last active December 24, 2018 09:02
Show Gist options
  • Save navi25/ebf5ab162aff1a500da94025d370f3bb to your computer and use it in GitHub Desktop.
Save navi25/ebf5ab162aff1a500da94025d370f3bb to your computer and use it in GitHub Desktop.
A custom Kotlin code generator that generates a basic class with basic greeting method.
package io.navendra.codegen.simplePoet
/**
* Custom Kotlin Class Builder which returns file content string
* This is for learning purpose only.
* Use KotlinPoet for production app
* KotlinPoet can be found at https://github.com/square/kotlinpoet
*/
class KotlinClassBuilder(className: String,
packageName:String,
greeting:String = "Merry Christmas!!"){
private val contentTemplate = """
package $packageName
class $className {
fun greeting() = "$greeting"
}
""".trimIndent()
fun getContent() : String{
return contentTemplate
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment