@@ -2,17 +2,25 @@ package love.forte.plugin.suspendtrans
22
33import org.jetbrains.kotlin.descriptors.CallableDescriptor
44import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
5+ import org.jetbrains.kotlin.fir.FirSession
6+ import org.jetbrains.kotlin.fir.analysis.checkers.toClassLikeSymbol
7+ import org.jetbrains.kotlin.fir.declarations.ExpectForActualMatchingData
58import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
69import org.jetbrains.kotlin.fir.declarations.FirValueParameter
10+ import org.jetbrains.kotlin.fir.declarations.expectForActual
11+ import org.jetbrains.kotlin.fir.scopes.impl.toConeType
12+ import org.jetbrains.kotlin.fir.symbols.SymbolInternals
713import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
14+ import org.jetbrains.kotlin.fir.types.ConeKotlinType
15+ import org.jetbrains.kotlin.fir.types.ConeTypeParameterType
816import org.jetbrains.kotlin.fir.types.classId
917import org.jetbrains.kotlin.fir.types.coneTypeOrNull
1018import org.jetbrains.kotlin.ir.declarations.IrFunction
1119import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
1220import org.jetbrains.kotlin.ir.declarations.IrValueParameter
21+ import org.jetbrains.kotlin.ir.expressions.IrConst
1322import org.jetbrains.kotlin.ir.types.classFqName
14- import org.jetbrains.kotlin.ir.util.callableId
15- import org.jetbrains.kotlin.ir.util.hasEqualFqName
23+ import org.jetbrains.kotlin.ir.util.*
1624import org.jetbrains.kotlin.js.descriptorUtils.getKotlinTypeFqName
1725import org.jetbrains.kotlin.name.CallableId
1826import org.jetbrains.kotlin.name.ClassId
@@ -134,48 +142,147 @@ data class OriginValueParameter(
134142
135143data class SuspendTransformUserDataFir (
136144 val originSymbol : OriginSymbol ,
145+ val markerId : String ,
137146 val asProperty : Boolean ,
138147 val transformer : Transformer
139148)
140149
141150fun FirNamedFunctionSymbol.asOriginSymbol (
151+ targetMarker : ClassId ? ,
142152 typeParameters : List <FirTypeParameter >,
143153 valueParameters : List <FirValueParameter >,
144- returnType : ClassId ?
154+ returnType : ClassId ? ,
155+ session : FirSession ,
145156): OriginSymbol {
146157 return OriginSymbol (
158+ targetMarker,
159+ symbol = this ,
147160 callableId = this .callableId,
148161 typeParameters = typeParameters.map { it.toTypeParameter() },
149- valueParameters = valueParameters.map { it .toValueParameter() },
162+ valueParameters = valueParameters.mapIndexed { index, p -> p .toValueParameter(session, index ) },
150163 returnType
151164 )
152165}
153166
154167data class OriginSymbol (
168+ val targetMarker : ClassId ? ,
169+ val symbol : FirNamedFunctionSymbol ,
155170 val callableId : CallableId ,
156171 val typeParameters : List <TypeParameter >,
157172 val valueParameters : List <ValueParameter >,
158173 val returnType : ClassId ?
159174)
160175
161- data class TypeParameter (val name : Name , val varianceOrdinal : Int , val isReified : Boolean , val bounds : List <ClassId ?>)
176+ data class TypeParameter (
177+ val name : Name ,
178+ val varianceOrdinal : Int ,
179+ val isReified : Boolean ,
180+ val bounds : List <ClassId ?>,
181+ val type : ConeTypeParameterType ,
182+ )
162183
163- private fun FirTypeParameter.toTypeParameter (): TypeParameter =
164- TypeParameter (
184+ private fun FirTypeParameter.toTypeParameter (): TypeParameter {
185+ return TypeParameter (
165186 name,
166187 variance.ordinal,
167188 isReified,
168- bounds.map { it.coneTypeOrNull?.classId }
189+ bounds.map { it.coneTypeOrNull?.classId },
190+ toConeType(),
169191 )
192+ }
193+
194+
195+ data class ValueParameter (
196+ val fir : FirValueParameter ,
197+ val name : Name ,
198+ val index : Int ,
199+ val coneType : ConeKotlinType ? ,
200+ val type : ClassId ? ,
201+ val expectForActual : ExpectForActualMatchingData ?
202+ )
170203
204+ @OptIn(SymbolInternals ::class )
205+ private fun FirValueParameter.toValueParameter (session : FirSession , index : Int ): ValueParameter {
206+ // LocalLoggerHelper.println("returnTypeRef = $returnTypeRef")
207+ // LocalLoggerHelper.println("symbol.resolvedReturnTypeRef = ${symbol.resolvedReturnTypeRef}")
208+ // LocalLoggerHelper.println("symbol.resolvedReturnTypeRef.coneType = ${symbol.resolvedReturnTypeRef.coneType}")
209+ // LocalLoggerHelper.println("symbol.resolvedReturnTypeRef.coneType.isTypealiasExpansion = ${symbol.resolvedReturnTypeRef.coneType.isTypealiasExpansion}")
210+ // LocalLoggerHelper.println(
211+ // "symbol.resolvedReturnTypeRef.coneType.fullyExpandedType(session) = ${
212+ // symbol.resolvedReturnTypeRef.coneType.fullyExpandedType(
213+ // session
214+ // )
215+ // }"
216+ // )
217+ //
218+ // LocalLoggerHelper.println(
219+ // "returnTypeRef.coneType.toClassLikeSymbol(session)?.isActual: ${
220+ // returnTypeRef.coneType.toClassLikeSymbol(
221+ // session
222+ // )?.isActual
223+ // }"
224+ // )
225+ // LocalLoggerHelper.println(
226+ // "returnTypeRef.coneType.toClassLikeSymbol(session)?.isExpect: ${
227+ // returnTypeRef.coneType.toClassLikeSymbol(
228+ // session
229+ // )?.isExpect
230+ // }"
231+ // )
232+ //
233+ // LocalLoggerHelper.println(
234+ // "returnTypeRef.coneType.toRegularClassSymbol(session): ${
235+ // returnTypeRef.coneType.toRegularClassSymbol(
236+ // session
237+ // )
238+ // }"
239+ // )
240+ // LocalLoggerHelper.println(
241+ // "returnTypeRef.coneType.toClassLikeSymbol(session): ${
242+ // returnTypeRef.coneType.toClassLikeSymbol(
243+ // session
244+ // )
245+ // }"
246+ // )
247+ //
248+ // LocalLoggerHelper.println(
249+ // "returnTypeRef.coneType.toRegularClassSymbol(session)?.fir?.expectForActual: " +
250+ // "${returnTypeRef.coneType.toRegularClassSymbol(session)?.fir?.expectForActual}"
251+ // )
252+ //
253+ // LocalLoggerHelper.println(
254+ // "returnTypeRef.coneType.toRegularClassSymbol(session)?.fir?.memberExpectForActual: " +
255+ // "${returnTypeRef.coneType.toRegularClassSymbol(session)?.fir?.memberExpectForActual}"
256+ // )
257+ //
258+ // LocalLoggerHelper.println(
259+ // "returnTypeRef.coneType.toRegularClassSymbol(session)?.fir?.fullyExpandedClass.defaultType: " +
260+ // "${
261+ // returnTypeRef.coneType.toRegularClassSymbol(session)?.fir?.fullyExpandedClass(session)
262+ // ?.defaultType()
263+ // }"
264+ // )
265+
266+ return ValueParameter (
267+ this ,
268+ name,
269+ index,
270+ returnTypeRef.coneTypeOrNull,
271+ returnTypeRef.coneTypeOrNull?.classId,
272+ returnTypeRef.toClassLikeSymbol(session)?.expectForActual
273+ )
274+ }
171275
172- data class ValueParameter (val name : Name , val type : ClassId ? )
173276
174- private fun FirValueParameter.toValueParameter (): ValueParameter =
175- ValueParameter (name, returnTypeRef.coneTypeOrNull?.classId)
277+ fun OriginSymbol.checkSame (markerId : String , declaration : IrFunction ): Boolean {
278+ if (targetMarker != null ) {
279+ val anno = declaration.annotations.firstOrNull { it.symbol.owner.parentAsClass.classId == targetMarker }
280+ if (anno == null ) return false
176281
282+ val valueArgument = anno.getValueArgument(Name .identifier(" value" )) as ? IrConst ? : return false
283+ return markerId == valueArgument.value
284+ }
177285
178- fun OriginSymbol.checkSame (declaration : IrFunction ): Boolean {
179286 // callableId
180287 if (callableId != declaration.callableId) return false
181288 // return type
@@ -215,6 +322,6 @@ private infix fun IrTypeParameter.isSameAs(typeParameter: TypeParameter): Boolea
215322}
216323
217324private infix fun IrValueParameter.isSameAs (valueParameter : ValueParameter ): Boolean {
218- if (name != valueParameter.name ) return false
325+ if (index != valueParameter.index ) return false
219326 return type.classFqName == valueParameter.type?.asSingleFqName()
220327}
0 commit comments