Skip to content

Commit a61f4a7

Browse files
committed
[Compiler plugin] Reorder more important declarations higher
1 parent 6b628f8 commit a61f4a7

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

plugins/kotlin-dataframe/src/org/jetbrains/kotlinx/dataframe/plugin/extensions/FunctionCallTransformer.kt

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ class FunctionCallTransformer(
9595
const val DEFAULT_NAME = "DataFrameType"
9696
}
9797

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())
99104

100105
override fun intercept(callInfo: CallInfo, symbol: FirNamedFunctionSymbol): CallReturnType? {
101106
val callSiteAnnotations = (callInfo.callSite as? FirAnnotationContainer)?.annotations ?: emptyList()
@@ -121,54 +126,9 @@ class FunctionCallTransformer(
121126
hashToTwoCharString(abs(hash))
122127
}
123128

124-
return typeTransformers.firstNotNullOfOrNull { it.interceptOrNull(callInfo, symbol, hash) }
129+
return transformers.firstNotNullOfOrNull { it.interceptOrNull(callInfo, symbol, hash) }
125130
}
126131

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-
172132
private fun exposesLocalType(callInfo: CallInfo): Boolean {
173133
val property = callInfo.containingDeclarations.lastOrNull()?.symbol as? FirPropertySymbol
174134
return (property != null && !property.resolvedStatus.effectiveVisibility.privateApi)
@@ -184,19 +144,12 @@ class FunctionCallTransformer(
184144
return "$char1$char2"
185145
}
186146

187-
private fun nextName(s: String) = ClassId(CallableId.PACKAGE_FQ_NAME_FOR_LOCAL, FqName(s), true)
188-
189147
override fun transform(call: FirFunctionCall, originalSymbol: FirNamedFunctionSymbol): FirFunctionCall {
190-
return typeTransformers
148+
return transformers
191149
.firstNotNullOfOrNull { it.transformOrNull(call, originalSymbol) }
192150
?: call
193151
}
194152

195-
interface CallTransformer {
196-
fun interceptOrNull(callInfo: CallInfo, symbol: FirNamedFunctionSymbol, hash: String): CallReturnType?
197-
fun transformOrNull(call: FirFunctionCall, originalSymbol: FirNamedFunctionSymbol): FirFunctionCall?
198-
}
199-
200153
inner class DataFrameCallTransformer : CallTransformer {
201154
override fun interceptOrNull(callInfo: CallInfo, symbol: FirNamedFunctionSymbol, hash: String): CallReturnType? {
202155
if (symbol.resolvedReturnType.fullyExpandedClassId(session) != Names.DF_CLASS_ID) return null
@@ -294,6 +247,53 @@ class FunctionCallTransformer(
294247
}
295248
}
296249

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+
297297
@OptIn(SymbolInternals::class)
298298
private fun buildLetCall(
299299
call: FirFunctionCall,

0 commit comments

Comments
 (0)