diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-10-24 19:54:16 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-10-24 19:54:16 +0200 |
commit | 33215e5c31b55617edf0d95e47e9e720fe4b9dd6 (patch) | |
tree | 11e90cbfaacf37dbe1ce4fd8ce3eb28d02dd4867 /kvision-tools/kvision-compiler-plugin/src/main | |
parent | 69958b1a08f46aecd6ceda54780f362019150052 (diff) | |
download | kvision-33215e5c31b55617edf0d95e47e9e720fe4b9dd6.tar.gz kvision-33215e5c31b55617edf0d95e47e9e720fe4b9dd6.tar.bz2 kvision-33215e5c31b55617edf0d95e47e9e720fe4b9dd6.zip |
Allow suspending functions for SelectRemote and TabulatorRemote components.
Diffstat (limited to 'kvision-tools/kvision-compiler-plugin/src/main')
-rw-r--r-- | kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt | 41 |
1 files changed, 24 insertions, 17 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 0e62b959..bf01b463 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 @@ -28,7 +28,6 @@ import de.jensklingenberg.mpapt.model.Element import de.jensklingenberg.mpapt.model.RoundEnvironment import de.jensklingenberg.mpapt.utils.KotlinPlatformValues import org.jetbrains.kotlin.backend.common.descriptors.allParameters -import org.jetbrains.kotlin.backend.common.descriptors.isSuspend import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.ParameterDescriptor @@ -85,7 +84,11 @@ class KVProcessor : AbstractProcessor() { appendln(" init {") appendln(" GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) {") cl.methods().forEach { - appendln(" bind($iName::${it.name})") + when { + it.returnType.toString().startsWith("RemoteData") -> appendln(" bindTabulatorRemote($iName::${it.name})") + it.returnType.toString() == "List<RemoteOption>" -> appendln(" bindSelectRemote($iName::${it.name})") + else -> appendln(" bind($iName::${it.name})") + } } appendln(" }") appendln(" }") @@ -125,29 +128,33 @@ class KVProcessor : AbstractProcessor() { if (params.size == 2) params.first().type.toString().startsWith("ReceiveChannel") else false - if (it.isSuspend) { - if (!wsMethod) { - if (params.isNotEmpty()) { - appendln( + if (!wsMethod) { + if (params.isNotEmpty()) { + when { + it.returnType.toString().startsWith("RemoteData") -> appendln( + " override suspend fun $name(${getParameterList( + params + )}) = ${it.returnType.toString()}()" + ) + it.returnType.toString() == "List<RemoteOption>" -> appendln( + " override suspend fun $name(${getParameterList( + params + )}) = emptyList<RemoteOption>()" + ) + else -> appendln( " override suspend fun $name(${getParameterList(params)}) = call($iName::$name, ${getParameterNames( params )})" ) - } else { - appendln(" override suspend fun $name() = call($iName::$name)") } } else { - appendln(" override suspend fun $name(${getParameterList(params)}) {}") - val type1 = params[0].type.toString().replace("ReceiveChannel", "SendChannel") - val type2 = params[1].type.toString().replace("SendChannel", "ReceiveChannel") - appendln(" suspend fun $name(handler: suspend ($type1, $type2) -> Unit) = webSocket($iName::$name, handler)") + appendln(" override suspend fun $name() = call($iName::$name)") } } else { - if (it.returnType.toString().startsWith("RemoteData")) { - appendln(" override fun $name(${getParameterList(params)}) = ${it.returnType.toString()}()") - } else { - appendln(" override fun $name(${getParameterList(params)}) = emptyList<RemoteOption>()") - } + appendln(" override suspend fun $name(${getParameterList(params)}) {}") + val type1 = params[0].type.toString().replace("ReceiveChannel", "SendChannel") + val type2 = params[1].type.toString().replace("SendChannel", "ReceiveChannel") + appendln(" suspend fun $name(handler: suspend ($type1, $type2) -> Unit) = webSocket($iName::$name, handler)") } } appendln("}") |