From 57bb7357284851f03e00bcca0f42753e864b5218 Mon Sep 17 00:00:00 2001 From: Jiaxiang Chen Date: Thu, 18 Jan 2024 01:12:12 -0800 Subject: [PATCH] restore annotations on type alias (cherry picked from commit 024b17a2fc4fa8a197b1db388a2791db86555ac1) --- .../google/devtools/ksp/symbol/impl/kotlin/KSTypeImpl.kt | 4 +--- .../devtools/ksp/processor/TypeAnnotationProcessor.kt | 8 +++++++- test-utils/testData/api/typeAnnotation.kt | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeImpl.kt index 20ed2c7fa2..396a112dfd 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeImpl.kt @@ -35,7 +35,6 @@ import org.jetbrains.kotlin.builtins.isKFunctionType import org.jetbrains.kotlin.builtins.isKSuspendFunctionType import org.jetbrains.kotlin.builtins.isSuspendFunctionType import org.jetbrains.kotlin.descriptors.NotFoundClasses -import org.jetbrains.kotlin.descriptors.SourceElement import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.TypeNullability import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf @@ -145,8 +144,7 @@ fun getKSTypeCached( KSTypeImpl.getCached( kotlinType, ksTypeArguments, - annotations + kotlinType.annotations - .filter { it.source == SourceElement.NO_SOURCE } + kotlinType.annotations .map { KSAnnotationDescriptorImpl.getCached(it, null) } .asSequence() ) diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/TypeAnnotationProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/TypeAnnotationProcessor.kt index fa974f7d57..7b1d180504 100644 --- a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/TypeAnnotationProcessor.kt +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/TypeAnnotationProcessor.kt @@ -13,9 +13,15 @@ class TypeAnnotationProcessor : AbstractTestProcessor() { } override fun process(resolver: Resolver): List { - val myList = resolver.getClassDeclarationByName("MyClass")!!.getDeclaredProperties().single() + val myList = resolver.getClassDeclarationByName("MyClass")!!.getDeclaredProperties().single { + it.simpleName.asString() == "myList" + } + val myAlias = resolver.getClassDeclarationByName("MyClass")!!.getDeclaredProperties().single { + it.simpleName.asString() == "myAlias" + } val myStringClass = resolver.getClassDeclarationByName("MyStringClass")!!.asStarProjectedType() result.add(myList.type.resolve().annotations.joinToString()) + result.add(myAlias.type.resolve().annotations.joinToString()) result.add(myList.asMemberOf(myStringClass).annotations.joinToString()) result.add(myList.type.resolve().let { it.replace(it.arguments) }.annotations.joinToString()) result.add(myList.type.resolve().starProjection().annotations.joinToString()) diff --git a/test-utils/testData/api/typeAnnotation.kt b/test-utils/testData/api/typeAnnotation.kt index 1bd76e40d0..1b61f228a0 100644 --- a/test-utils/testData/api/typeAnnotation.kt +++ b/test-utils/testData/api/typeAnnotation.kt @@ -20,13 +20,16 @@ // TEST PROCESSOR: TypeAnnotationProcessor // EXPECTED: // @JvmSuppressWildcards +// @JvmWildcard // @JvmSuppressWildcards // @JvmSuppressWildcards // @JvmSuppressWildcards // END - +interface MyType +typealias MyAlias = @JvmWildcard MyType class MyClass { var myList: @JvmSuppressWildcards List = TODO() + var myAlias: MyAlias = TODO() } class MyStringClass: MyClass {}