Skip to content
Permalink
Browse files

support generic function arguments

  • Loading branch information
jonasbark committed Sep 22, 2019
1 parent 28e2c6e commit 627de81c1458fc53a033170df5b8d7d957bcc772
@@ -78,14 +78,14 @@ repositories {
}
plugins {
id("native-suspend-function") version "1.0.15"
// or as dependency: "de.ffuf.kotlin.multiplatform.processor:nativesuspendfunction:1.0.15"
id("native-suspend-function") version "1.0.18"
// or as dependency: "de.ffuf.kotlin.multiplatform.processor:nativesuspendfunction:1.0.18"
}
// also add the annotations as dependency:
dependencies {
// multiplatform binaries are ready - please have a look at the example project
implementation("de.ffuf.kotlin.multiplatform.annotations:annotations:1.0.17")
implementation("de.ffuf.kotlin.multiplatform.annotations:annotations:1.0.18")
}
```
@@ -186,6 +186,7 @@ publishing {
}
repositories {
maven {
//url "${System.getProperty('user.home')}/.m2/repository"
url 'https://api.bintray.com/maven/jonasbark/ffuf/kotlin-native-suspend-function-callback-annotations'
credentials {
username = bintray_user
@@ -32,7 +32,7 @@ apply plugin: "maven"

group = "de.ffuf.kotlin.multiplatform.processor"
archivesBaseName = "nativesuspendfunction"
version = "1.0.15"
version = "1.0.18"


install {
@@ -42,6 +42,6 @@ class NativeSuspendFunctionsGradleSubplugin : KotlinGradleSubplugin<AbstractComp
override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact(
groupId = "de.ffuf.kotlin.multiplatform.processor",
artifactId = "nativesuspendfunction-compiler",
version = "1.0.15" // remember to bump this version before any release!
version = "1.0.18" // remember to bump this version before any release!
)
}
@@ -67,7 +67,7 @@ kotlin {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
implementation "de.ffuf.kotlin.multiplatform.annotations:annotations-jvm:$plugin_version"
implementation "de.ffuf.kotlin.multiplatform.annotations:annotations:$plugin_version"

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.0"
}
@@ -83,8 +83,6 @@ kotlin {
jsMain {
dependencies {
implementation kotlin('stdlib-js')
implementation "de.ffuf.kotlin.multiplatform.annotations:annotations-js:$plugin_version"

}
}
jsTest {
@@ -96,7 +94,6 @@ kotlin {
jvmMain {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "de.ffuf.kotlin.multiplatform.annotations:annotations-jvm:$plugin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0"
}
}
@@ -108,7 +105,6 @@ kotlin {
}
iosX64Main {
dependencies {
implementation "de.ffuf.kotlin.multiplatform.annotations:annotations-iosx64:$plugin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.3.0"
}
}
@@ -23,6 +23,10 @@ class CommonAnnotated {
suspend fun goToDockingStation(commandHandler: Regex?) =
Regex("")

@NativeSuspendedFunction
suspend fun testList(list: List<Regex>) =
Regex("")

@ExperimentalCoroutinesApi
@NativeFlowFunction
fun testFlowFunction(test: Int): Flow<CoroutineScope> {
@@ -8,4 +8,4 @@ org.gradle.jvmargs=-Xmx6g -XX:MaxPermSize=1024m
//kotlin.native.jvmArgs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006
gnsp.disableApplyOnlyOnRootProjectEnforcement

plugin_version = 1.0.17
plugin_version = 1.0.18
@@ -133,17 +133,17 @@ kapt {
uploadArchives {
repositories {
mavenDeployer {
repository(url: uri("${System.getProperty('user.home')}/.m2/repository"))
//repository(url: uri("${System.getProperty('user.home')}/.m2/repository"))

pom.withXml(configureMavenCentralMetadata)
/*repository (
repository (
url: 'https://api.bintray.com/maven/jonasbark/ffuf/nativesuspendfunction-compiler'
) {
authentication(
userName: bintray_user,
password: bintray_api_key
)
}*/
}
}

}
@@ -144,7 +144,14 @@ class NativeSuspendedFunctionProcessor : AbstractProcessor() {
ClassName(
param.packagee.packagename,
param.packagee.classname
).copy(nullable = param.nullable)
).let {
if (param.genericPackage != null) {
ClassName(
param.genericPackage!!.packagename,
param.genericPackage!!.classname
).parameterizedBy(it)
} else it
}.copy(nullable = param.nullable)
).build()
})
.addParameter(
@@ -23,16 +23,25 @@ fun FunctionDescriptor.getFunctionParameters(): List<FunctionParameter> {
// normal:
//value-parameter id: kotlin.Int defined in de.jensklingenberg.mpapt.CommonAnnotated.firstFunction2[ValueParameterDescriptorImpl@725a91a6]
// Typedefs:
//value-parameter id: de.jensklingenberg.mpapt.Datum /* = kotlin.ranges.CharProgression */ defined in de.jensklingenberg.mpapt.CommonAnnotated.firstFunction2[ValueParameterDescriptorImpl@692444bb]
//value-parameter id: de.jensklingenberg.mpapt.Datum /* = kotlin.ranges.CharProgression */ defined in de.jensklingenberg.mpapt.CommonAnnotated.firstFunction2[ValueParameterDescriptorImpl@692444bb
// Arrays:
//value-parameter list: kotlin.collections.List<kotlin.text.Regex> defined in de.jensklingenberg.mpapt.CommonAnnotated.testList[ValueParameterDescriptorImpl@f9c2310]
val fullPackage = parameter.toString().substringAfter(": ")
.substringBefore(" defined")
.substringBefore(" /* =")
val realValue = fullPackage.substringAfter("<").substringBefore(">")
val isGeneric = fullPackage.contains("<")
val genericValue = fullPackage.substringBefore("<")
FunctionParameter(
parameter.name.asString(),
parameter.type.toString().endsWith("?"),
Package(
fullPackage.split(".").last().replace("?", ""),
fullPackage.split(".").dropLast(1).joinToString(".")
realValue.split(".").last().replace("?", ""),
realValue.split(".").dropLast(1).joinToString(".")
),
genericPackage = if (!isGeneric) null else Package(
genericValue.split(".").last().replace("?", ""),
genericValue.split(".").dropLast(1).joinToString(".")
)
)
}.toList()
@@ -3,7 +3,8 @@ package de.jensklingenberg.mpapt.model
data class FunctionParameter(
val parameterName: String,
val nullable: Boolean,
val packagee: Package
val packagee: Package,
val genericPackage: Package? = null
)

data class Package(val classname: String, val packagename: String)

0 comments on commit 627de81

Please sign in to comment.
You can’t perform that action at this time.