@@ -27,14 +27,20 @@ import org.jetbrains.kotlin.fir.declarations.utils.isInterface
27
27
import org.jetbrains.kotlin.fir.declarations.utils.isSuspend
28
28
import org.jetbrains.kotlin.fir.pipeline.FirResult
29
29
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
30
+ import org.jetbrains.kotlin.fir.resolve.toSymbol
31
+ import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
30
32
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
31
33
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
34
+ import org.jetbrains.kotlin.fir.types.ConeKotlinType
35
+ import org.jetbrains.kotlin.fir.types.ConeLookupTagBasedType
32
36
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
33
37
import org.jetbrains.kotlin.fir.types.FirStarProjection
34
38
import org.jetbrains.kotlin.fir.types.FirTypeProjection
35
39
import org.jetbrains.kotlin.fir.types.FirTypeProjectionWithVariance
36
40
import org.jetbrains.kotlin.fir.types.FirTypeRef
37
41
import org.jetbrains.kotlin.fir.types.FirUserTypeRef
42
+ import org.jetbrains.kotlin.fir.types.abbreviatedTypeOrSelf
43
+ import org.jetbrains.kotlin.fir.types.coneType
38
44
import org.jetbrains.kotlin.name.ClassId
39
45
import org.jetbrains.kotlin.name.FqName
40
46
import org.jetbrains.kotlin.name.Name
@@ -131,24 +137,33 @@ internal class FirZiplineApiReader(
131
137
val signature = buildString {
132
138
if (isSuspend) append(" suspend " )
133
139
append(" fun ${symbol.name.identifier} (" )
134
- append( valueParameters.joinToString { it.returnTypeRef.asString() })
140
+ valueParameters.joinTo( this ) { it.returnTypeRef.asString() }
135
141
append(" ): ${returnTypeRef.asString()} " )
136
142
}
137
143
138
144
return FirZiplineFunction (signature)
139
145
}
140
146
141
147
private fun FirProperty.asDeclaredZiplineFunction (): FirZiplineFunction {
142
- val signature = when {
143
- isVar -> " var ${symbol.name.identifier} : ${returnTypeRef.asString()} "
144
- else -> " val ${symbol.name.identifier} : ${returnTypeRef.asString()} "
145
- }
148
+ val valOrVar = if (isVar) " var" else " val"
149
+ val signature = " $valOrVar ${symbol.name.identifier} : ${returnTypeRef.asString()} "
146
150
return FirZiplineFunction (signature)
147
151
}
148
152
153
+ // TODO This available natively in Kotlin 2.1.0 or newer and can be deleted after upgrading.
154
+ val ConeKotlinType .lookupTagIfAny: ConeClassifierLookupTag ?
155
+ get() = (this as ? ConeLookupTagBasedType )?.lookupTag
156
+
157
+ // TODO This available natively in Kotlin 2.1.0 or newer and can be deleted after upgrading.
158
+ fun ConeClassifierLookupTag.toClassLikeSymbol (useSiteSession : FirSession ): FirClassLikeSymbol <* >? {
159
+ return toSymbol(useSiteSession) as ? FirClassLikeSymbol <* >
160
+ }
161
+
149
162
/* * See [app.cash.zipline.kotlin.asString]. */
150
163
private fun FirTypeRef.asString (): String {
151
- val classLikeSymbol = toClassLikeSymbol(session) ? : error(" unexpected class: $this " )
164
+ // Abbreviated type gets us the name of typealiases rather than what they expand to.
165
+ val classLikeSymbol = coneType.abbreviatedTypeOrSelf.lookupTagIfAny
166
+ ?.toClassLikeSymbol(session) ? : error(" unexpected class: $this " )
152
167
153
168
val typeRef = when (this ) {
154
169
is FirResolvedTypeRef -> delegatedTypeRef ? : this
0 commit comments