@@ -8,8 +8,10 @@ package org.jetbrains.kotlinx.dataframe.plugin
8
8
import org.jetbrains.kotlin.fir.FirSession
9
9
import org.jetbrains.kotlin.fir.analysis.checkers.toClassLikeSymbol
10
10
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
11
+ import org.jetbrains.kotlin.fir.declarations.declaredProperties
11
12
import org.jetbrains.kotlin.fir.declarations.findArgumentByName
12
13
import org.jetbrains.kotlin.fir.declarations.getAnnotationByClassId
14
+ import org.jetbrains.kotlin.fir.declarations.getAnnotationWithResolvedArgumentsByClassId
13
15
import org.jetbrains.kotlin.fir.declarations.hasAnnotation
14
16
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
15
17
import org.jetbrains.kotlin.fir.expressions.*
@@ -105,7 +107,9 @@ fun <T> KotlinTypeFacade.interpret(
105
107
val expectedReturnType = expectedArgument.klass
106
108
val value: Interpreter .Success <Any ?>? = when (expectedArgument.lens) {
107
109
is Interpreter .Value -> {
108
- extractValue(it.expression, reporter)
110
+ context(session) {
111
+ extractValue(it.expression, reporter)
112
+ }
109
113
}
110
114
111
115
is Interpreter .ReturnType -> {
@@ -188,6 +192,7 @@ fun <T> KotlinTypeFacade.interpret(
188
192
}
189
193
}
190
194
195
+ context(session: FirSession )
191
196
private fun KotlinTypeFacade.extractValue (
192
197
expression : FirExpression ? ,
193
198
reporter : InterpretationErrorReporter ,
@@ -353,20 +358,21 @@ private fun List<FirPropertySymbol>.sortPropertiesByOrderAnnotation(sessionConte
353
358
return result
354
359
}
355
360
356
- private fun KotlinTypeFacade.columnWithPathApproximations (result : FirPropertyAccessExpression ): ColumnsResolver {
357
- return result.resolvedType.let {
361
+ context(session: FirSession )
362
+ private fun KotlinTypeFacade.columnWithPathApproximations (propertyAccess : FirPropertyAccessExpression ): ColumnsResolver {
363
+ return propertyAccess.resolvedType.let {
358
364
val column = when (it.classId) {
359
365
Names .DATA_COLUMN_CLASS_ID -> {
360
366
val type = when (val arg = it.typeArguments.single()) {
361
367
is ConeStarProjection -> session.builtinTypes.nullableAnyType.coneType
362
368
else -> arg as ConeClassLikeType
363
369
}
364
- simpleColumnOf(f(result ), type)
370
+ simpleColumnOf(propertyAccess.columnName( ), type)
365
371
}
366
372
Names .COLUM_GROUP_CLASS_ID -> {
367
373
val arg = it.typeArguments.single()
368
- val path = f(result )
369
- SimpleColumnGroup (path , pluginDataFrameSchema(arg).columns())
374
+ val name = propertyAccess.columnName( )
375
+ SimpleColumnGroup (name , pluginDataFrameSchema(arg).columns())
370
376
}
371
377
else -> return object : ColumnsResolver {
372
378
override fun resolve (df : PluginDataFrameSchema ): List <ColumnWithPathApproximation > {
@@ -376,7 +382,7 @@ private fun KotlinTypeFacade.columnWithPathApproximations(result: FirPropertyAcc
376
382
}
377
383
SingleColumnApproximation (
378
384
ColumnWithPathApproximation (
379
- path = ColumnPathApproximation (path(result )),
385
+ path = ColumnPathApproximation (path(propertyAccess )),
380
386
column
381
387
)
382
388
)
@@ -450,8 +456,9 @@ private fun SessionContext.shouldBeConvertedToFrameColumn(it: FirPropertySymbol)
450
456
private fun isDataFrame (it : FirPropertySymbol ) =
451
457
it.resolvedReturnType.classId == Names .DF_CLASS_ID
452
458
459
+ context(session: FirSession )
453
460
fun path (propertyAccessExpression : FirPropertyAccessExpression ): List <String > {
454
- val colName = f( propertyAccessExpression)
461
+ val colName = propertyAccessExpression.columnName( )
455
462
val typeRef = propertyAccessExpression.dispatchReceiver?.resolvedType
456
463
val joinDsl = ClassId (FqName (" org.jetbrains.kotlinx.dataframe.api" ), Name .identifier(" JoinDsl" ))
457
464
if (typeRef?.classId?.equals(joinDsl) == true && colName == " right" ) {
@@ -470,8 +477,19 @@ fun path(propertyAccessExpression: FirPropertyAccessExpression): List<String> {
470
477
}
471
478
}
472
479
473
- fun f (propertyAccessExpression : FirPropertyAccessExpression ): String {
474
- return propertyAccessExpression.calleeReference.resolved!! .name.identifier
480
+ context(session: FirSession )
481
+ fun FirPropertyAccessExpression.columnName (): String {
482
+ val name = toResolvedCallableSymbol()?.name
483
+ val columnName =
484
+ extensionReceiver?.resolvedType?.typeArguments?.getOrNull(0 )?.type?.toRegularClassSymbol(session)
485
+ ?.declaredProperties(session)
486
+ ?.firstOrNull { it.name == name }
487
+ ?.let {
488
+ val expression = it.getAnnotationWithResolvedArgumentsByClassId(Names .COLUMN_NAME_ANNOTATION , session)
489
+ ?.argumentMapping?.mapping[Names .COLUMN_NAME_ARGUMENT ] as ? FirLiteralExpression
490
+ expression?.value as ? String
491
+ }
492
+ return columnName ? : calleeReference.resolved!! .name.identifier
475
493
}
476
494
477
495
internal fun FirFunctionCall.collectArgumentExpressions (): RefinedArguments {
0 commit comments