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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.descriptorUtil.platform
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension
import org.jetbrains.kotlin.synthetic.isVisibleOutside
import org.jetbrains.kotlin.types.KotlinTypeFactory
import org.jetbrains.kotlin.types.TypeAttributes
import org.jetbrains.kotlin.types.Variance
Expand Down Expand Up @@ -96,7 +97,7 @@ open class SuspendTransformSyntheticResolveExtension(open val configuration: Sus
) {
if (annotationData == null) return

if (annotationData.asProperty == true) {
if (annotationData.asProperty == true && descriptors.valueParameters.isEmpty()) {
syntheticProperties.addSyntheticDescriptors(
thisDescriptor,
descriptors.transformToProperty(annotationData)
Expand All @@ -109,7 +110,9 @@ open class SuspendTransformSyntheticResolveExtension(open val configuration: Sus
// check and add synthetic functions.
// find all annotated
result
.asSequence()
.filter { f -> f.isSuspend }
.filter { f -> f.visibility.isVisibleOutside() }
.forEach { originFunction ->
val resolvedAnnotations =
originFunction.resolveToTransformAnnotations(thisDescriptor, configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,15 @@ private operator fun FunctionTransformAnnotations.plus(other: FunctionTransformA
* 后者优先。
*/
private operator fun TransformAnnotationData?.plus(other: TransformAnnotationData?): TransformAnnotationData? {
println("class annotation data: $this")
println("function annotation data: $other")
if (this == null && other == null) return null
if (other == null) return this
if (this == null) return other

val baseName = other.baseName ?: this.baseName
val suffix = other.suffix ?: this.suffix
val asProperty = other.asProperty?.takeIf { it } ?: this.asProperty

val functionName = if (baseName == null) other.functionName else buildString {
append(baseName)
Expand All @@ -123,14 +126,14 @@ private operator fun TransformAnnotationData?.plus(other: TransformAnnotationDat
annotationDescriptor = other.annotationDescriptor,
baseName = baseName,
suffix = suffix,
asProperty = other.asProperty ?: this.asProperty,
asProperty = asProperty,
functionName = functionName
)

}


fun Annotations.resolveToTransformAnnotations(
private fun Annotations.resolveToTransformAnnotations(
configuration: SuspendTransformConfiguration,
functionBaseName: String
): FunctionTransformAnnotations {
Expand Down
40 changes: 5 additions & 35 deletions compiler/suspend-transform-plugin/testData/justTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,22 @@ annotation class Hi
@JvmBlocking
suspend fun hello(): String = "hello"

@JvmBlocking
@JvmAsync
class JustTest : ITest { // : ITest

@Hi
@JvmBlocking(asProperty = true)
@JvmAsync(asProperty = true)
suspend fun value(): Int = value("111")

@JvmBlocking
@JvmAsync
suspend fun value(value: String): Int = value.toInt()

@JvmBlocking
@JvmAsync
//@kotlin.jvm.JvmOverload
override suspend fun run99(name: String): Int = 1
suspend fun value(): Int = 111

@JvmBlocking(asProperty = true)
@JvmAsync(asProperty = true)
override suspend fun run2(): Int = 1


@JvmBlocking
@JvmAsync
override suspend fun self(): JustTest = this

@JvmBlocking(asProperty = true)
@JvmAsync(asProperty = true)
override suspend fun self2(): JustTest = this
}

@JvmBlocking(asProperty = true)
@JvmAsync(asProperty = true)
interface ITest {
@JvmBlocking
@JvmAsync
suspend fun run99(name: String = "forte"): Int

@JvmBlocking(asProperty = true)
@JvmAsync(asProperty = true)
suspend fun run2(): Int

@JvmBlocking
@JvmAsync
suspend fun self(): ITest

@JvmBlocking(asProperty = true)
@JvmAsync(asProperty = true)
suspend fun self2(): ITest
}

fun main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public expect annotation class Api4Js()
*
*/
@OptIn(ExperimentalMultiplatform::class)
@Target(AnnotationTarget.FUNCTION)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
@OptionalExpectation
public expect annotation class JvmBlocking(
Expand Down Expand Up @@ -81,7 +81,7 @@ public expect annotation class JvmBlocking(
*
*/
@OptIn(ExperimentalMultiplatform::class)
@Target(AnnotationTarget.FUNCTION)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
@OptionalExpectation
public expect annotation class JvmAsync(
Expand All @@ -105,7 +105,7 @@ public expect annotation class JvmAsync(


@OptIn(ExperimentalMultiplatform::class)
@Target(AnnotationTarget.FUNCTION)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
@OptionalExpectation
public expect annotation class JsPromise()
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public actual annotation class Api4Js
@Retention(AnnotationRetention.BINARY)
public annotation class ExperimentalJsApi

@Target(AnnotationTarget.FUNCTION)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
public actual annotation class JsPromise
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public annotation class ExperimentalJvmApi
* ```
*
*/
@Target(AnnotationTarget.FUNCTION)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
public actual annotation class JvmBlocking(
/**
Expand Down Expand Up @@ -74,7 +74,7 @@ public actual annotation class JvmBlocking(
* ```
*
*/
@Target(AnnotationTarget.FUNCTION)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
public actual annotation class JvmAsync(
actual val baseName: String,
Expand Down