diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-04-18 20:20:21 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-04-18 20:20:21 +0200 |
commit | 80f33eae37fff276f538ce43d2b0e18f773a839b (patch) | |
tree | 1c788e268e7042656db9cc4a62592d890fe12f53 /kvision-tools/kvision-compiler-plugin | |
parent | 7b994ca5d71f195781ac129f3d3d180fb79c7380 (diff) | |
download | kvision-80f33eae37fff276f538ce43d2b0e18f773a839b.tar.gz kvision-80f33eae37fff276f538ce43d2b0e18f773a839b.tar.bz2 kvision-80f33eae37fff276f538ce43d2b0e18f773a839b.zip |
Support for method annotations for compiler plugin (#142)
Diffstat (limited to 'kvision-tools/kvision-compiler-plugin')
-rw-r--r-- | kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt b/kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt index 31ed4ffd..d456ceb7 100644 --- a/kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt +++ b/kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt @@ -32,6 +32,8 @@ import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.ParameterDescriptor import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.platform.TargetPlatform import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.types.KotlinType @@ -87,6 +89,7 @@ class KVProcessor : AbstractProcessor() { appendln("import kotlinx.coroutines.CoroutineStart") appendln("import kotlinx.coroutines.GlobalScope") appendln("import kotlinx.coroutines.launch") + appendln("import pl.treksoft.kvision.remote.HttpMethod") appendln("import pl.treksoft.kvision.remote.KVServiceManager") appendln() appendln("expect class $baseName : $iName") @@ -95,10 +98,35 @@ class KVProcessor : AbstractProcessor() { appendln(" init {") appendln(" GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) {") cl.methods().forEach { + val params = it.allParameters.drop(1) + val wsMethod = + if (params.size == 2) + params.first().type.toString().startsWith("ReceiveChannel") + else false + val kvBinding = + it.annotations.findAnnotation(FqName("pl.treksoft.kvision.annotations.KVBinding")) + val kvBindingMethod = + it.annotations.findAnnotation(FqName("pl.treksoft.kvision.annotations.KVBindingMethod")) + val kvBindingRoute = + it.annotations.findAnnotation(FqName("pl.treksoft.kvision.annotations.KVBindingRoute")) + val (method, route) = if (kvBinding != null) { + val method = kvBinding.allValueArguments[Name.identifier("method")].toString() + val route = kvBinding.allValueArguments[Name.identifier("route")].toString() + "Http$method" to route + } else if (kvBindingMethod != null) { + val method = kvBindingMethod.allValueArguments[Name.identifier("method")].toString() + "Http$method" to null + } else if (kvBindingRoute != null) { + val route = kvBindingRoute.allValueArguments[Name.identifier("route")].toString() + "HttpMethod.POST" to route + } else { + "HttpMethod.POST" to null + } when { it.returnType.toString().startsWith("RemoteData") -> - appendln(" bindTabulatorRemote($iName::${it.name})") - else -> appendln(" bind($iName::${it.name})") + appendln(" bindTabulatorRemote($iName::${it.name}, $route)") + wsMethod -> appendln(" bind($iName::${it.name}, $route)") + else -> appendln(" bind($iName::${it.name}, $method, $route)") } } appendln(" }") |