Last active
December 24, 2018 09:02
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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