diff --git a/build.gradle b/build.gradle index a8bb37e..2287e59 100644 --- a/build.gradle +++ b/build.gradle @@ -21,10 +21,9 @@ dependencies { implementation 'com.github.kittinunf.fuel:fuel-coroutines:2.2.3' implementation 'co.nstant.in:cbor:0.9' implementation 'net.i2p.crypto:eddsa:0.3.0' + implementation 'com.github.square:kotlinpoet:1.6.0' implementation 'com.github.h0tk3y.betterParse:better-parse-jvm:0.4.0' - api 'com.github.square:kotlinpoet:1.6.0' - testImplementation( 'org.junit.jupiter:junit-jupiter:5.6.2', 'org.spockframework:spock-core:2.0-M3-groovy-3.0', diff --git a/src/main/kotlin/senior/joinu/candid/CandidCodeGenerator.kt b/src/main/kotlin/senior/joinu/candid/CandidCodeGenerator.kt index c14b309..3c91be7 100644 --- a/src/main/kotlin/senior/joinu/candid/CandidCodeGenerator.kt +++ b/src/main/kotlin/senior/joinu/candid/CandidCodeGenerator.kt @@ -4,6 +4,7 @@ import com.github.h0tk3y.betterParse.grammar.parseToEnd import com.squareup.kotlinpoet.FileSpec import senior.joinu.candid.idl.IDLGrammar import senior.joinu.candid.transpile.KtTranspiler +import java.io.File import java.nio.charset.Charset import java.nio.charset.StandardCharsets import java.nio.file.Path @@ -23,7 +24,33 @@ object CandidCodeGenerator { ) : Source() } - fun generateFor( + fun generate( + input: Source, + file: File, + genPackage: String = "", + ) { + generateFor(input, genPackage).writeTo(file) + } + + fun generate( + input: Source, + file: Path, + genPackage: String = "", + ) { + generateFor(input, genPackage).writeTo(file) + } + + fun generate( + input: Source, + genPackage: String = "", + ): String { + val sb = StringBuilder() + generateFor(input, genPackage).writeTo(sb) + + return sb.toString() + } + + internal fun generateFor( input: Source, genPackage: String = "" ): FileSpec {