fix type reference construction logic for type parameter
diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processor/TypeParameterReferenceProcessor.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processor/TypeParameterReferenceProcessor.kt
index 5685005..cd3c959 100644
--- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processor/TypeParameterReferenceProcessor.kt
+++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processor/TypeParameterReferenceProcessor.kt
@@ -18,6 +18,7 @@
package com.google.devtools.ksp.processor
+import com.google.devtools.ksp.getClassDeclarationByName
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.symbol.*
@@ -39,6 +40,10 @@
val r = i.resolve()
results.add("${r.declaration.qualifiedName?.asString()}: ${r.isMarkedNullable}")
}
+ val libFoo = resolver.getClassDeclarationByName("LibFoo")!!
+ libFoo.declarations.filterIsInstance<KSPropertyDeclaration>().forEach { results.add(it.type.toString()) }
+ val javaLib = resolver.getClassDeclarationByName("JavaLib")!!
+ javaLib.declarations.filterIsInstance<KSFunctionDeclaration>().forEach { results.add(it.returnType.toString()) }
return emptyList()
}
diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeReferenceDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeReferenceDescriptorImpl.kt
index 2d931be..cea60a7 100644
--- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeReferenceDescriptorImpl.kt
+++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeReferenceDescriptorImpl.kt
@@ -39,18 +39,7 @@
override val location: Location = NonExistLocation
override val element: KSReferenceElement by lazy {
- when {
- kotlinType.constructor.declarationDescriptor is ClassDescriptor -> KSClassifierReferenceDescriptorImpl.getCached(kotlinType)
- kotlinType.constructor.declarationDescriptor is TypeParameterDescriptor -> {
- val upperBound = TypeUtils.getTypeParameterDescriptorOrNull(kotlinType)!!.upperBounds.first()
- when (upperBound) {
- is FlexibleType -> KSClassifierReferenceDescriptorImpl.getCached(upperBound.upperBound)
- is SimpleType -> KSClassifierReferenceDescriptorImpl.getCached(upperBound)
- else -> throw IllegalStateException("Unexpected upperbound type ${upperBound.javaClass}, $ExceptionMessage")
- }
- }
- else -> throw IllegalStateException("Unexpected type: ${kotlinType.constructor.declarationDescriptor?.javaClass}, $ExceptionMessage")
- }
+ KSClassifierReferenceDescriptorImpl.getCached(kotlinType)
}
override val annotations: List<KSAnnotation> by lazy {
@@ -76,4 +65,4 @@
override fun toString(): String {
return element.toString()
}
-}
\ No newline at end of file
+}
diff --git a/compiler-plugin/testData/api/typeParameterReference.kt b/compiler-plugin/testData/api/typeParameterReference.kt
index e18bd78..c0b9a3b 100644
--- a/compiler-plugin/testData/api/typeParameterReference.kt
+++ b/compiler-plugin/testData/api/typeParameterReference.kt
@@ -18,17 +18,42 @@
// WITH_RUNTIME
// TEST PROCESSOR: TypeParameterReferenceProcessor
// EXPECTED:
+// LibFoo: false
+// kotlin.String: false
// Foo.T1: true
// Foo.bar.T2: false
// foo.T3: false
+// T
+// List<T>
+// T
+// MutableList<(T..T?)>
// END
+// MODULE: lib
+// FILE: lib.kt
+interface LibFoo<T> {
+ val v: T
+ val w: List<T>
+}
+
+// FILE: JavaLib.java
+import java.util.List;
+
+interface JavaLib<T> {
+ public T genericFun();
+ public List<T> list();
+}
+
+// MODULE: main(lib)
+// FILE: main.kt
class Foo<T1> {
inner class Bar {
val v: T1?
}
fun <T2> bar(p: T2) = 1
+
+ val libFoo: LibFoo<String>
}
fun <T3> foo(p: T3) = 1