@@ -95,7 +95,12 @@ class FunctionCallTransformer(
95
95
const val DEFAULT_NAME = " DataFrameType"
96
96
}
97
97
98
- private val typeTransformers = listOf (GroupByCallTransformer (), DataFrameCallTransformer ())
98
+ private interface CallTransformer {
99
+ fun interceptOrNull (callInfo : CallInfo , symbol : FirNamedFunctionSymbol , hash : String ): CallReturnType ?
100
+ fun transformOrNull (call : FirFunctionCall , originalSymbol : FirNamedFunctionSymbol ): FirFunctionCall ?
101
+ }
102
+
103
+ private val transformers = listOf (GroupByCallTransformer (), DataFrameCallTransformer ())
99
104
100
105
override fun intercept (callInfo : CallInfo , symbol : FirNamedFunctionSymbol ): CallReturnType ? {
101
106
val callSiteAnnotations = (callInfo.callSite as ? FirAnnotationContainer )?.annotations ? : emptyList()
@@ -121,54 +126,9 @@ class FunctionCallTransformer(
121
126
hashToTwoCharString(abs(hash))
122
127
}
123
128
124
- return typeTransformers .firstNotNullOfOrNull { it.interceptOrNull(callInfo, symbol, hash) }
129
+ return transformers .firstNotNullOfOrNull { it.interceptOrNull(callInfo, symbol, hash) }
125
130
}
126
131
127
- private fun buildNewTypeArgument (argument : ConeTypeProjection ? , name : Name , hash : String ): FirRegularClass {
128
- val suggestedName = if (argument == null ) {
129
- " ${name.asTokenName()} _$hash "
130
- } else {
131
- when (argument) {
132
- is ConeStarProjection -> {
133
- " ${name.asTokenName()} _$hash "
134
- }
135
- is ConeKotlinTypeProjection -> {
136
- val titleCase = argument.type.classId?.shortClassName
137
- ?.identifierOrNullIfSpecial?.titleCase()
138
- ?.substringBeforeLast(" _" )
139
- ? : DEFAULT_NAME
140
- " ${titleCase} _$hash "
141
- }
142
- }
143
- }
144
- val tokenId = nextName(" ${suggestedName} I" )
145
- val token = buildSchema(tokenId)
146
-
147
- val dataFrameTypeId = nextName(suggestedName)
148
- val dataFrameType = buildRegularClass {
149
- moduleData = session.moduleData
150
- resolvePhase = FirResolvePhase .BODY_RESOLVE
151
- origin = FirDeclarationOrigin .Source
152
- status = FirResolvedDeclarationStatusImpl (Visibilities .Local , Modality .ABSTRACT , EffectiveVisibility .Local )
153
- deprecationsProvider = EmptyDeprecationsProvider
154
- classKind = ClassKind .CLASS
155
- scopeProvider = FirKotlinScopeProvider ()
156
- superTypeRefs + = buildResolvedTypeRef {
157
- type = ConeClassLikeTypeImpl (
158
- ConeClassLookupTagWithFixedSymbol (tokenId, token.symbol),
159
- emptyArray(),
160
- isNullable = false
161
- )
162
- }
163
-
164
- this .name = dataFrameTypeId.shortClassName
165
- this .symbol = FirRegularClassSymbol (dataFrameTypeId)
166
- }
167
- return dataFrameType
168
- }
169
-
170
- private fun Name.asTokenName () = identifierOrNullIfSpecial?.titleCase() ? : DEFAULT_NAME
171
-
172
132
private fun exposesLocalType (callInfo : CallInfo ): Boolean {
173
133
val property = callInfo.containingDeclarations.lastOrNull()?.symbol as ? FirPropertySymbol
174
134
return (property != null && ! property.resolvedStatus.effectiveVisibility.privateApi)
@@ -184,19 +144,12 @@ class FunctionCallTransformer(
184
144
return " $char1$char2 "
185
145
}
186
146
187
- private fun nextName (s : String ) = ClassId (CallableId .PACKAGE_FQ_NAME_FOR_LOCAL , FqName (s), true )
188
-
189
147
override fun transform (call : FirFunctionCall , originalSymbol : FirNamedFunctionSymbol ): FirFunctionCall {
190
- return typeTransformers
148
+ return transformers
191
149
.firstNotNullOfOrNull { it.transformOrNull(call, originalSymbol) }
192
150
? : call
193
151
}
194
152
195
- interface CallTransformer {
196
- fun interceptOrNull (callInfo : CallInfo , symbol : FirNamedFunctionSymbol , hash : String ): CallReturnType ?
197
- fun transformOrNull (call : FirFunctionCall , originalSymbol : FirNamedFunctionSymbol ): FirFunctionCall ?
198
- }
199
-
200
153
inner class DataFrameCallTransformer : CallTransformer {
201
154
override fun interceptOrNull (callInfo : CallInfo , symbol : FirNamedFunctionSymbol , hash : String ): CallReturnType ? {
202
155
if (symbol.resolvedReturnType.fullyExpandedClassId(session) != Names .DF_CLASS_ID ) return null
@@ -294,6 +247,53 @@ class FunctionCallTransformer(
294
247
}
295
248
}
296
249
250
+ private fun buildNewTypeArgument (argument : ConeTypeProjection ? , name : Name , hash : String ): FirRegularClass {
251
+ val suggestedName = if (argument == null ) {
252
+ " ${name.asTokenName()} _$hash "
253
+ } else {
254
+ when (argument) {
255
+ is ConeStarProjection -> {
256
+ " ${name.asTokenName()} _$hash "
257
+ }
258
+ is ConeKotlinTypeProjection -> {
259
+ val titleCase = argument.type.classId?.shortClassName
260
+ ?.identifierOrNullIfSpecial?.titleCase()
261
+ ?.substringBeforeLast(" _" )
262
+ ? : DEFAULT_NAME
263
+ " ${titleCase} _$hash "
264
+ }
265
+ }
266
+ }
267
+ val tokenId = nextName(" ${suggestedName} I" )
268
+ val token = buildSchema(tokenId)
269
+
270
+ val dataFrameTypeId = nextName(suggestedName)
271
+ val dataFrameType = buildRegularClass {
272
+ moduleData = session.moduleData
273
+ resolvePhase = FirResolvePhase .BODY_RESOLVE
274
+ origin = FirDeclarationOrigin .Source
275
+ status = FirResolvedDeclarationStatusImpl (Visibilities .Local , Modality .ABSTRACT , EffectiveVisibility .Local )
276
+ deprecationsProvider = EmptyDeprecationsProvider
277
+ classKind = ClassKind .CLASS
278
+ scopeProvider = FirKotlinScopeProvider ()
279
+ superTypeRefs + = buildResolvedTypeRef {
280
+ type = ConeClassLikeTypeImpl (
281
+ ConeClassLookupTagWithFixedSymbol (tokenId, token.symbol),
282
+ emptyArray(),
283
+ isNullable = false
284
+ )
285
+ }
286
+
287
+ this .name = dataFrameTypeId.shortClassName
288
+ this .symbol = FirRegularClassSymbol (dataFrameTypeId)
289
+ }
290
+ return dataFrameType
291
+ }
292
+
293
+ private fun nextName (s : String ) = ClassId (CallableId .PACKAGE_FQ_NAME_FOR_LOCAL , FqName (s), true )
294
+
295
+ private fun Name.asTokenName () = identifierOrNullIfSpecial?.titleCase() ? : DEFAULT_NAME
296
+
297
297
@OptIn(SymbolInternals ::class )
298
298
private fun buildLetCall (
299
299
call : FirFunctionCall ,
0 commit comments