Skip to content

Commit

Permalink
fix classifier reference toString
Browse files Browse the repository at this point in the history
(cherry picked from commit bc16a18)
  • Loading branch information
neetopia authored and KSP Auto Pick committed Nov 1, 2023
1 parent 10910a3 commit b30f578
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Expand Up @@ -22,19 +22,18 @@ import com.google.devtools.ksp.symbol.KSClassifierReference
import com.google.devtools.ksp.symbol.KSNode
import com.google.devtools.ksp.symbol.KSTypeArgument
import com.google.devtools.ksp.symbol.Location
import com.google.devtools.ksp.symbol.Origin
import org.jetbrains.kotlin.psi.KtUserType

class KSClassifierReferenceImpl private constructor(
val ktUserType: KtUserType,
override val parent: KSNode?
override val parent: KSNode
) : KSClassifierReference {
companion object : KSObjectCache<IdKeyPair<KtUserType, KSNode?>, KSClassifierReferenceImpl>() {
fun getCached(ktUserType: KtUserType, parent: KSNode? = null) =
fun getCached(ktUserType: KtUserType, parent: KSNode) =
cache.getOrPut(IdKeyPair(ktUserType, parent)) { KSClassifierReferenceImpl(ktUserType, parent) }
}

override val origin = Origin.KOTLIN
override val origin = parent.origin

override val location: Location by lazy {
ktUserType.toLocation()
Expand All @@ -53,9 +52,13 @@ class KSClassifierReferenceImpl private constructor(
if (ktUserType.qualifier == null) {
null
} else {
KSClassifierReferenceImpl.getCached(ktUserType.qualifier!!, parent)
getCached(ktUserType.qualifier!!, parent)
}
}

override fun toString() = referencedName()
override fun toString(): String {
return ktUserType.referencedName + if (typeArguments.isNotEmpty()) "<${
typeArguments.map { it.toString() }.joinToString(", ")
}>" else ""
}
}
Expand Up @@ -71,7 +71,7 @@ class KSTypeReferenceImpl(
ktType.annotations.map { KSAnnotationImpl.getCached(it) }.asSequence()
}

override val origin: Origin = Origin.KOTLIN
override val origin: Origin = parent?.origin ?: Origin.SYNTHETIC

override val location: Location by lazy {
ktTypeReference.toLocation()
Expand Down
16 changes: 8 additions & 8 deletions kotlin-analysis-api/testData/parent.kt
Expand Up @@ -72,16 +72,17 @@
// parent of File: a.kt: null
// parent of Int: Int
// parent of Int: INVARIANT Int
// parent of INVARIANT Int: List
// parent of List: List<Int>?
// parent of List<Int>?: topProp
// parent of List<Int>?: topProp.getter()
// parent of INVARIANT Int: List<INVARIANT Int>
// parent of List<INVARIANT Int>: List<INVARIANT Int>
// parent of List<INVARIANT Int>: topProp
// parent of List<INVARIANT Int>: List<INVARIANT Int>
// parent of List<INVARIANT Int>: topProp.getter()
// parent of topProp.getter(): topProp
// parent of Anno: null
// parent of @Anno: topProp
// parent of topProp: File: a.kt
// parent of T: T?
// parent of T?: topFun
// parent of T: T
// parent of T: topFun
// parent of Any?: T
// parent of T: topFun
// parent of Anno: null
Expand All @@ -103,7 +104,6 @@
// parent of Any?: T
// parent of T: File: a.kt
// parent of Alias: File: a.kt
// parent of Any: Any
// parent of Any: ITF
// parent of ITF: File: a.kt
// parent of ITF: ITF
Expand All @@ -119,6 +119,7 @@
// parent of memberFun: topClass
// parent of Int: Int
// parent of Int: a
// parent of Int: Int
// parent of Int: a.getter()
// parent of a.getter(): a
// parent of a: topClass
Expand All @@ -131,7 +132,6 @@
// parent of <set-?>: b.setter()
// parent of b.setter(): b
// parent of b: topClass
// parent of Any: Any
// parent of Any: InnerClass
// parent of Any?: P
// parent of P: InnerClass
Expand Down

0 comments on commit b30f578

Please sign in to comment.