aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2020-04-18 20:20:21 +0200
committerRobert Jaros <rjaros@finn.pl>2020-04-18 20:20:21 +0200
commit80f33eae37fff276f538ce43d2b0e18f773a839b (patch)
tree1c788e268e7042656db9cc4a62592d890fe12f53
parent7b994ca5d71f195781ac129f3d3d180fb79c7380 (diff)
downloadkvision-80f33eae37fff276f538ce43d2b0e18f773a839b.tar.gz
kvision-80f33eae37fff276f538ce43d2b0e18f773a839b.tar.bz2
kvision-80f33eae37fff276f538ce43d2b0e18f773a839b.zip
Support for method annotations for compiler plugin (#142)
-rw-r--r--kvision-modules/kvision-common-annotations/src/commonMain/kotlin/pl/treksoft/kvision/annotations/Annotations.kt17
-rw-r--r--kvision-modules/kvision-server-javalin/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt3
-rw-r--r--kvision-modules/kvision-server-javalin/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt7
-rw-r--r--kvision-modules/kvision-server-javalin/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt7
-rw-r--r--kvision-modules/kvision-server-jooby/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt3
-rw-r--r--kvision-modules/kvision-server-jooby/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt7
-rw-r--r--kvision-modules/kvision-server-jooby/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt7
-rw-r--r--kvision-modules/kvision-server-ktor/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt3
-rw-r--r--kvision-modules/kvision-server-ktor/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt7
-rw-r--r--kvision-modules/kvision-server-ktor/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt7
-rw-r--r--kvision-modules/kvision-server-spring-boot/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt3
-rw-r--r--kvision-modules/kvision-server-spring-boot/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt7
-rw-r--r--kvision-modules/kvision-server-spring-boot/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt7
-rw-r--r--kvision-modules/kvision-server-vertx/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt3
-rw-r--r--kvision-modules/kvision-server-vertx/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt7
-rw-r--r--kvision-modules/kvision-server-vertx/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt7
-rw-r--r--kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt32
17 files changed, 97 insertions, 37 deletions
diff --git a/kvision-modules/kvision-common-annotations/src/commonMain/kotlin/pl/treksoft/kvision/annotations/Annotations.kt b/kvision-modules/kvision-common-annotations/src/commonMain/kotlin/pl/treksoft/kvision/annotations/Annotations.kt
index 22cf570b..077606d1 100644
--- a/kvision-modules/kvision-common-annotations/src/commonMain/kotlin/pl/treksoft/kvision/annotations/Annotations.kt
+++ b/kvision-modules/kvision-common-annotations/src/commonMain/kotlin/pl/treksoft/kvision/annotations/Annotations.kt
@@ -21,5 +21,22 @@
*/
package pl.treksoft.kvision.annotations
+enum class Method {
+ GET,
+ POST,
+ PUT,
+ DELETE,
+ OPTIONS
+}
+
@Target(AnnotationTarget.CLASS)
annotation class KVService
+
+@Target(AnnotationTarget.FUNCTION)
+annotation class KVBinding(val method: Method, val route: String)
+
+@Target(AnnotationTarget.FUNCTION)
+annotation class KVBindingMethod(val method: Method)
+
+@Target(AnnotationTarget.FUNCTION)
+annotation class KVBindingRoute(val route: String)
diff --git a/kvision-modules/kvision-server-javalin/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-javalin/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index 3ba4998d..c035e828 100644
--- a/kvision-modules/kvision-server-javalin/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-javalin/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -120,7 +120,8 @@ expect open class KVServiceManager<T : Any>(serviceClass: KClass<T>) {
* @param function a function of the receiver
*/
protected inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String? = null
)
/**
diff --git a/kvision-modules/kvision-server-javalin/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-javalin/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index c7a35150..4927857f 100644
--- a/kvision-modules/kvision-server-javalin/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-javalin/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -150,9 +150,10 @@ actual open class KVServiceManager<T : Any> actual constructor(serviceClass: KCl
* @param function a function of the receiver
*/
protected actual inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", HttpMethod.POST)
}
@@ -165,7 +166,7 @@ actual open class KVServiceManager<T : Any> actual constructor(serviceClass: KCl
noinline function: suspend T.(ReceiveChannel<PAR1>, SendChannel<PAR2>) -> Unit,
route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kvws/$routeDef", HttpMethod.POST)
}
diff --git a/kvision-modules/kvision-server-javalin/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-javalin/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index 9e4bc87f..aabb0752 100644
--- a/kvision-modules/kvision-server-javalin/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-javalin/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -445,7 +445,7 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
noinline function: suspend T.(ReceiveChannel<PAR1>, SendChannel<PAR2>) -> Unit,
route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
webSocketRequests["/kvws/$routeDef"] = { ws ->
ws.onConnect { ctx ->
val incoming = Channel<String>()
@@ -521,9 +521,10 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
*/
@Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
addRoute(HttpMethod.POST, "/kv/$routeDef") { ctx ->
val jsonRpcRequest = ctx.body<JsonRpcRequest>()
@Suppress("MagicNumber")
diff --git a/kvision-modules/kvision-server-jooby/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-jooby/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index 3ba4998d..c035e828 100644
--- a/kvision-modules/kvision-server-jooby/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-jooby/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -120,7 +120,8 @@ expect open class KVServiceManager<T : Any>(serviceClass: KClass<T>) {
* @param function a function of the receiver
*/
protected inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String? = null
)
/**
diff --git a/kvision-modules/kvision-server-jooby/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-jooby/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index c7a35150..4927857f 100644
--- a/kvision-modules/kvision-server-jooby/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-jooby/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -150,9 +150,10 @@ actual open class KVServiceManager<T : Any> actual constructor(serviceClass: KCl
* @param function a function of the receiver
*/
protected actual inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", HttpMethod.POST)
}
@@ -165,7 +166,7 @@ actual open class KVServiceManager<T : Any> actual constructor(serviceClass: KCl
noinline function: suspend T.(ReceiveChannel<PAR1>, SendChannel<PAR2>) -> Unit,
route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kvws/$routeDef", HttpMethod.POST)
}
diff --git a/kvision-modules/kvision-server-jooby/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-jooby/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index 69040e51..2f31a85c 100644
--- a/kvision-modules/kvision-server-jooby/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-jooby/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -410,7 +410,7 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
noinline function: suspend T.(ReceiveChannel<PAR1>, SendChannel<PAR2>) -> Unit,
route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
webSocketRequests["/kvws/$routeDef"] = { ctx, configurer ->
val injector = ctx.require(Injector::class.java).createChildInjector(ContextModule(ctx))
val service = injector.getInstance(serviceClass.java)
@@ -481,9 +481,10 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
*/
@Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
addRoute(HttpMethod.POST, "/kv/$routeDef") {
val jsonRpcRequest = ctx.body<JsonRpcRequest>()
@Suppress("MagicNumber")
diff --git a/kvision-modules/kvision-server-ktor/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-ktor/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index 3ba4998d..c035e828 100644
--- a/kvision-modules/kvision-server-ktor/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-ktor/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -120,7 +120,8 @@ expect open class KVServiceManager<T : Any>(serviceClass: KClass<T>) {
* @param function a function of the receiver
*/
protected inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String? = null
)
/**
diff --git a/kvision-modules/kvision-server-ktor/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-ktor/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index c7a35150..4927857f 100644
--- a/kvision-modules/kvision-server-ktor/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-ktor/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -150,9 +150,10 @@ actual open class KVServiceManager<T : Any> actual constructor(serviceClass: KCl
* @param function a function of the receiver
*/
protected actual inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", HttpMethod.POST)
}
@@ -165,7 +166,7 @@ actual open class KVServiceManager<T : Any> actual constructor(serviceClass: KCl
noinline function: suspend T.(ReceiveChannel<PAR1>, SendChannel<PAR2>) -> Unit,
route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kvws/$routeDef", HttpMethod.POST)
}
diff --git a/kvision-modules/kvision-server-ktor/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-ktor/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index aee92d31..9d0bf3de 100644
--- a/kvision-modules/kvision-server-ktor/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-ktor/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -457,7 +457,7 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
noinline function: suspend T.(ReceiveChannel<PAR1>, SendChannel<PAR2>) -> Unit,
route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
webSocketRequests["/kvws/$routeDef"] = {
val wsInjector = call.injector.createChildInjector(WsSessionModule(this))
val service = wsInjector.getInstance(serviceClass.java)
@@ -507,9 +507,10 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
*/
@Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
addRoute(HttpMethod.POST, "/kv/$routeDef") {
val service = call.injector.createChildInjector(DummyWsSessionModule()).getInstance(serviceClass.java)
val jsonRpcRequest = call.receive<JsonRpcRequest>()
diff --git a/kvision-modules/kvision-server-spring-boot/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-spring-boot/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index 3ba4998d..c035e828 100644
--- a/kvision-modules/kvision-server-spring-boot/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-spring-boot/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -120,7 +120,8 @@ expect open class KVServiceManager<T : Any>(serviceClass: KClass<T>) {
* @param function a function of the receiver
*/
protected inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String? = null
)
/**
diff --git a/kvision-modules/kvision-server-spring-boot/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-spring-boot/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index c7a35150..4927857f 100644
--- a/kvision-modules/kvision-server-spring-boot/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-spring-boot/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -150,9 +150,10 @@ actual open class KVServiceManager<T : Any> actual constructor(serviceClass: KCl
* @param function a function of the receiver
*/
protected actual inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", HttpMethod.POST)
}
@@ -165,7 +166,7 @@ actual open class KVServiceManager<T : Any> actual constructor(serviceClass: KCl
noinline function: suspend T.(ReceiveChannel<PAR1>, SendChannel<PAR2>) -> Unit,
route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kvws/$routeDef", HttpMethod.POST)
}
diff --git a/kvision-modules/kvision-server-spring-boot/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-spring-boot/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index eb602aa1..3a73003b 100644
--- a/kvision-modules/kvision-server-spring-boot/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-spring-boot/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -530,7 +530,7 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
noinline function: suspend T.(ReceiveChannel<PAR1>, SendChannel<PAR2>) -> Unit,
route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
webSocketsRequests[routeDef] = { webSocketSession, tlWsSession, ctx, incoming, outgoing ->
tlWsSession.set(webSocketSession)
val service = ctx.getBean(serviceClass.java)
@@ -583,9 +583,10 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
*/
@Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
addRoute(HttpMethod.POST, "/kv/$routeDef") { req, tlReq, ctx ->
tlReq.set(req)
val service = ctx.getBean(serviceClass.java)
diff --git a/kvision-modules/kvision-server-vertx/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-vertx/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index 3ba4998d..c035e828 100644
--- a/kvision-modules/kvision-server-vertx/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-vertx/src/commonMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -120,7 +120,8 @@ expect open class KVServiceManager<T : Any>(serviceClass: KClass<T>) {
* @param function a function of the receiver
*/
protected inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String? = null
)
/**
diff --git a/kvision-modules/kvision-server-vertx/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-vertx/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index c7a35150..4927857f 100644
--- a/kvision-modules/kvision-server-vertx/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-vertx/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -150,9 +150,10 @@ actual open class KVServiceManager<T : Any> actual constructor(serviceClass: KCl
* @param function a function of the receiver
*/
protected actual inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", HttpMethod.POST)
}
@@ -165,7 +166,7 @@ actual open class KVServiceManager<T : Any> actual constructor(serviceClass: KCl
noinline function: suspend T.(ReceiveChannel<PAR1>, SendChannel<PAR2>) -> Unit,
route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kvws/$routeDef", HttpMethod.POST)
}
diff --git a/kvision-modules/kvision-server-vertx/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-vertx/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index c64689b1..ae8b857c 100644
--- a/kvision-modules/kvision-server-vertx/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-vertx/src/jvmMain/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -417,7 +417,7 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
noinline function: suspend T.(ReceiveChannel<PAR1>, SendChannel<PAR2>) -> Unit,
route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
webSocketRequests["/kvws/$routeDef"] = { injector, ws ->
val incoming = Channel<String>()
val outgoing = Channel<String>()
@@ -491,9 +491,10 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
*/
@Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified RET> bindTabulatorRemote(
- noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>
+ noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET>,
+ route: String?
) {
- val routeDef = "route${this::class.simpleName}${counter++}"
+ val routeDef = route ?: "route${this::class.simpleName}${counter++}"
addRoute(HttpMethod.POST, "/kv/$routeDef") { ctx ->
val jsonRpcRequest = ctx.bodyAsJson.mapTo(JsonRpcRequest::class.java)
@Suppress("MagicNumber")
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(" }")