Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/IProject.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object IProject {
const val VERSION = "0.0.6"
const val VERSION = "0.1.0"
const val GROUP = "love.forte.plugin.suspend-transform"
const val DESCRIPTION = "Generate platform-compatible functions for Kotlin suspend functions"

Expand Down
20 changes: 11 additions & 9 deletions compiler/suspend-transform-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,35 @@ plugins {
id("com.bennyhuo.kotlin.plugin.embeddable.test") version "1.7.10.0"
}

//testWithEmbedded0()

dependencies {
compileOnly(kotlin("stdlib"))
compileOnly(kotlin("compiler"))
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")

// compileOnly(kotlin("compiler-embeddable"))

kapt("com.google.auto.service:auto-service:1.0.1")
compileOnly("com.google.auto.service:auto-service-annotations:1.0.1")

testImplementation(kotlin("stdlib"))
testImplementation(kotlin("test-junit"))
// testImplementation(kotlin("compiler-embeddable"))
testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable")
testImplementation(kotlin("compiler-embeddable"))
testImplementation(kotlin("reflect"))
// testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable")

testImplementation(project(":runtime:suspend-transform-annotation"))
testImplementation(project(":runtime:suspend-transform-runtime"))

// testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.9")
testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.9")
// testImplementation("org.bitbucket.mstrobel:procyon-compilertools:0.6.0")
testImplementation("com.bennyhuo.kotlin:kotlin-compile-testing-extensions:1.7.10.2-SNAPSHOT")
// testImplementation("com.bennyhuo.kotlin:kotlin-compile-testing-extensions:1.7.10.2-SNAPSHOT")

testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
// testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.6.4")
}

val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions.freeCompilerArgs += listOf("-Xjvm-default=enable", "-opt-in=kotlin.RequiresOptIn")

Expand All @@ -55,8 +62,3 @@ buildConfig {
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

kotlin {
// explicitApi()
}

Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,27 @@ open class SuspendTransformConfiguration @JvmOverloads constructor(var enabled:
var jvmAsyncMarkAnnotation = MarkAnnotation(TO_JVM_ASYNC_ANNOTATION_NAME)

/**
* 格式必须为
* 格式必须为:
*
* ```kotlin
* fun <T> <fun-name>(block: suspend () -> T): CompletableFuture<T> {
* fun <T> <fun-name>(block: suspend () -> T[, scope: CoroutineScope = ...]): CompletableFuture<T> {
* // ...
* }
* ```
*
* 其中,此异步函数可以有第二个参数,此参数格式必须为 [kotlinx.coroutines.CoroutineScope]。
* 如果存在此参数,当转化函数所处类型自身实现了 [kotlinx.coroutines.CoroutineScope] 时,将会将其自身作为参数填入,类似于:
*
* ```kotlin
* class Bar : CoroutineScope {
* @JvmAsync
* suspend fun foo(): Foo
*
* @Api4J fun fooAsync(): CompletableFuture<Foo> = runInAsync(block = { foo() }, scope = this)
* }
* ```
* 当前类型不属于 [kotlinx.coroutines.CoroutineScope] 类型时不会使用此参数。
*
*/
var jvmAsyncFunctionName: String = JVM_RUN_IN_ASYNC_FUNCTION_NAME

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.builders.irReturn
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.isSubtypeOfClass
import org.jetbrains.kotlin.ir.types.typeWith
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.name.FqName
Expand Down Expand Up @@ -212,14 +213,15 @@ private fun generateTransformBodyForFunction(

if (owner.valueParameters.size > 1) {
val secondType = owner.valueParameters[1].type
KOTLIN_SUSPEND_BUILT_IN_FUNCTION_FQ_NAME
val coroutineScopeTypeName = COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier("CoroutineScope"))
val coroutineScopeTypeName = "kotlinx.coroutines.CoroutineScope".fqn
val coroutineScopeTypeNameUnsafe = coroutineScopeTypeName.toUnsafe()
if (secondType.isClassType(coroutineScopeTypeNameUnsafe)) {
originFunction.dispatchReceiverParameter?.also { dispatchReceiverParameter ->
if (dispatchReceiverParameter.type.isClassType(coroutineScopeTypeNameUnsafe)) {
// put 'this' to second arg
putValueArgument(1, irGet(dispatchReceiverParameter))
function.dispatchReceiverParameter?.also { dispatchReceiverParameter ->
context.referenceClass(coroutineScopeTypeName)?.also { coroutineScopeRef ->
if (dispatchReceiverParameter.type.isSubtypeOfClass(coroutineScopeRef)) {
// put 'this' to second arg
putValueArgument(1, irGet(dispatchReceiverParameter))
}
}
}
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading