Skip to content

Commit

Permalink
Workaround for KaFunctionalType.abbreviatedType
Browse files Browse the repository at this point in the history
which is always null.
  • Loading branch information
ting-yuan committed Jun 25, 2024
1 parent 82c69dc commit 8656d5a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.google.devtools.ksp.symbol.KSTypeArgument
import com.google.devtools.ksp.symbol.Nullability
import org.jetbrains.kotlin.analysis.api.KtStarTypeProjection
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList
import org.jetbrains.kotlin.analysis.api.annotations.annotations
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.*

Expand Down Expand Up @@ -62,7 +61,7 @@ class KSTypeImpl private constructor(internal val type: KtType) : KSType {
}

override val declaration: KSDeclaration by lazy {
type.toDeclaration()
(type as? KaFunctionalType)?.abbreviatedSymbol()?.toKSDeclaration()?: type.toDeclaration()
}

override val nullability: Nullability by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.google.devtools.ksp.symbol.KSVisitor
import com.google.devtools.ksp.symbol.Location
import com.google.devtools.ksp.symbol.Modifier
import com.google.devtools.ksp.symbol.Origin
import org.jetbrains.kotlin.analysis.api.annotations.annotations
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.psi.KtDynamicType
import org.jetbrains.kotlin.psi.KtNullableType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.jetbrains.kotlin.analysis.api.components.buildTypeParameterType
import org.jetbrains.kotlin.analysis.api.fir.KaSymbolByFirBuilder
import org.jetbrains.kotlin.analysis.api.fir.evaluate.FirAnnotationValueConverter
import org.jetbrains.kotlin.analysis.api.fir.symbols.KaFirValueParameterSymbol
import org.jetbrains.kotlin.analysis.api.fir.types.KaFirFunctionalType
import org.jetbrains.kotlin.analysis.api.fir.types.KaFirType
import org.jetbrains.kotlin.analysis.api.impl.base.annotations.KaAnnotationImpl
import org.jetbrains.kotlin.analysis.api.platform.lifetime.KotlinAlwaysAccessibleLifetimeToken
Expand All @@ -70,6 +71,8 @@ import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.ConeFlexibleType
import org.jetbrains.kotlin.fir.types.ConeLookupTagBasedType
import org.jetbrains.kotlin.fir.types.abbreviatedType
import org.jetbrains.kotlin.fir.types.classId
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.isAny
import org.jetbrains.kotlin.load.java.structure.JavaAnnotationArgument
Expand Down Expand Up @@ -346,14 +349,20 @@ internal fun ClassId.toKtClassSymbol(): KtClassOrObjectSymbol? {
}
}

internal fun ClassId.toTypeAlias(): KtTypeAliasSymbol? {
return analyze {
getTypeAliasByClassId(this@toTypeAlias)
}
}

internal fun KtType.classifierSymbol(): KtClassifierSymbol? {
return try {
when (this) {
is KtTypeParameterType -> this.symbol
// TODO: upstream is not exposing enough information for captured types.
is KtCapturedType -> TODO("fix in upstream")
is KtClassErrorType, is KtTypeErrorType -> null
is KtFunctionalType -> classSymbol
is KtFunctionalType -> (this as? KaFirFunctionalType)?.abbreviatedSymbol() ?: symbol
is KtUsualClassType -> classSymbol
is KtDefinitelyNotNullType -> original.classifierSymbol()
is KtDynamicType -> null
Expand Down Expand Up @@ -798,3 +807,8 @@ internal fun TypeMappingMode.updateFromAnnotations(
this
}
}

internal fun KaFunctionalType.abbreviatedSymbol(): KtTypeAliasSymbol? {
val classId = (this as? KaFirFunctionalType)?.coneType?.abbreviatedType?.classId ?: return null
return classId.toTypeAlias()
}

0 comments on commit 8656d5a

Please sign in to comment.