1 package com.google.devtools.ksp.symbol.impl.java 2 3 import com.google.devtools.ksp.ExceptionMessage 4 import com.google.devtools.ksp.KSObjectCache 5 import com.google.devtools.ksp.symbol.KSClassifierReference 6 import com.google.devtools.ksp.symbol.KSTypeArgument 7 import com.google.devtools.ksp.symbol.Location 8 import com.google.devtools.ksp.symbol.NonExistLocation 9 import com.google.devtools.ksp.symbol.Origin 10 import com.intellij.psi.PsiAnnotation 11 import com.intellij.psi.PsiMethod 12 13 class KSClassifierReferenceLiteImplForJava( 14 override val parent: KSTypeReferenceLiteJavaImpl, 15 private val name: String? 16 ) : KSClassifierReference { 17 companion object : KSObjectCache<Pair<KSTypeReferenceLiteJavaImpl, String?>, KSClassifierReference>() { getCachednull18 fun getCached(parent: KSTypeReferenceLiteJavaImpl, name: String? = null) = 19 KSClassifierReferenceLiteImplForJava.cache 20 .getOrPut(Pair(parent, name)) { KSClassifierReferenceLiteImplForJava(parent, name) } 21 } <lambda>null22 override val qualifier: KSClassifierReference? by lazy { 23 val referencedName = referencedName() 24 if (referencedName.lastIndexOf('.') == -1) { 25 null 26 } else { 27 getCached(parent, referencedName.substringBeforeLast('.')) 28 } 29 } 30 referencedNamenull31 override fun referencedName(): String { 32 return name ?: when (parent.psiElement) { 33 is PsiAnnotation -> parent.psiElement.nameReferenceElement?.text ?: "<ERROR>" 34 is PsiMethod -> parent.psiElement.name 35 else -> throw IllegalStateException( 36 "Unexpected psi type in KSTypeReferenceLiteJavaImpl: ${parent.psiElement.javaClass}, $ExceptionMessage" 37 ) 38 } 39 } 40 41 override val typeArguments: List<KSTypeArgument> = emptyList() 42 43 override val origin: Origin = Origin.JAVA 44 45 override val location: Location = NonExistLocation 46 toStringnull47 override fun toString(): String { 48 return referencedName() 49 } 50 } 51