Skip to content

Commit 8e80822

Browse files
koperagenSpace Team
authored andcommitted
[KDF] Postpone access to @ColumnName argument from too early STATUS phase
generateProperties can happen at Phase.STATUS arguments are available later at ANNOTATION_ARGUMENTS Now value is accessed at backend IR lowering phase
1 parent b8a2fc2 commit 8e80822

File tree

8 files changed

+35
-28
lines changed

8 files changed

+35
-28
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ private class DataFrameFileLowering(val context: IrPluginContext) : FileLowering
109109
val call = IrCallImpl(-1, -1, context.irBuiltIns.anyNType, get, 0).also {
110110
val thisSymbol: IrValueSymbol = getterExtensionReceiver.symbol
111111
it.arguments[0] = IrGetValueImpl(-1, -1, thisSymbol)
112-
val annotation = declaration.annotations.findAnnotation(Names.COLUMN_NAME_ANNOTATION.asSingleFqName())
113-
val columnName = (annotation?.arguments?.get(0) as? IrConst)?.value as? String
114-
val columName = columnName ?: declaration.name.identifier
115-
it.arguments[1] = IrConstImpl.string(-1, -1, context.irBuiltIns.stringType, columName)
112+
val columnName = marker.properties.firstOrNull { it.name == declaration.name }
113+
?.getAnnotationArgumentValue<String>(Names.COLUMN_NAME_ANNOTATION.asSingleFqName(), Names.COLUMN_NAME_ARGUMENT.identifier)
114+
val arg = columnName ?: declaration.name.identifier
115+
it.arguments[1] = IrConstImpl.string(-1, -1, context.irBuiltIns.stringType, arg)
116116
}
117117

118118
val typeOp = IrTypeOperatorCallImpl(-1, -1, returnType, IrTypeOperator.CAST, returnType, call)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ class ImportedSchemasGenerator(
121121
it.owner,
122122
mode,
123123
it.returnType,
124-
null,
125124
callableId.callableName
126125
)
127126
}.orEmpty()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class TokenGenerator(session: FirSession) : FirDeclarationGenerationExtension(se
6565
receiverType = Names.DATA_ROW_CLASS_ID.constructClassLikeType(
6666
typeArguments = arrayOf(schemaProperty.marker)
6767
),
68-
propertyName = propertyName,
68+
propertyName = propertyName.identifier,
6969
returnType = schemaProperty.dataRowReturnType,
7070
symbol = k,
7171
effectiveVisibility = EffectiveVisibility.Local,
@@ -77,7 +77,7 @@ class TokenGenerator(session: FirSession) : FirDeclarationGenerationExtension(se
7777
receiverType = Names.COLUMNS_SCOPE_CLASS_ID.constructClassLikeType(
7878
typeArguments = arrayOf(schemaProperty.marker)
7979
),
80-
propertyName = propertyName,
80+
propertyName = propertyName.identifier,
8181
returnType = schemaProperty.columnContainerReturnType,
8282
symbol = k,
8383
effectiveVisibility = EffectiveVisibility.Local,

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
55
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
66
import org.jetbrains.kotlin.fir.declarations.builder.buildTypeParameter
77
import org.jetbrains.kotlin.fir.declarations.declaredProperties
8-
import org.jetbrains.kotlin.fir.declarations.getAnnotationByClassId
98
import org.jetbrains.kotlin.fir.declarations.hasAnnotation
109
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
11-
import org.jetbrains.kotlin.fir.expressions.FirLiteralExpression
1210
import org.jetbrains.kotlin.fir.extensions.*
1311
import org.jetbrains.kotlin.fir.extensions.predicate.LookupPredicate
1412
import org.jetbrains.kotlin.fir.moduleData
@@ -27,7 +25,6 @@ import org.jetbrains.kotlin.name.packageName
2725
import org.jetbrains.kotlin.types.Variance
2826
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
2927
import org.jetbrains.kotlinx.dataframe.plugin.DataFramePlugin
30-
import org.jetbrains.kotlinx.dataframe.plugin.extensions.impl.PropertyName
3128
import org.jetbrains.kotlinx.dataframe.plugin.utils.CallableIdOrSymbol
3229
import org.jetbrains.kotlinx.dataframe.plugin.utils.Names
3330
import org.jetbrains.kotlinx.dataframe.plugin.utils.generateExtensionProperty
@@ -89,9 +86,6 @@ class TopLevelExtensionsGenerator(session: FirSession) : FirDeclarationGeneratio
8986
owner,
9087
mode,
9188
property.resolvedReturnType,
92-
property.getAnnotationByClassId(Names.COLUMN_NAME_ANNOTATION, this@TopLevelExtensionsGenerator.session)?.let { annotation ->
93-
(annotation.argumentMapping.mapping[Names.COLUMN_NAME_ARGUMENT] as? FirLiteralExpression)?.value as? String?
94-
},
9589
property.name
9690
)
9791
}
@@ -111,12 +105,9 @@ fun FirDeclarationGenerationExtension.buildExtensionPropertiesApi(
111105
owner: FirRegularClassSymbol,
112106
mode: TopLevelExtensionsGenerator.Receiver,
113107
resolvedReturnType: ConeKotlinType,
114-
columnName: String?,
115108
name: Name
116109
): FirPropertySymbol {
117110
var resolvedReturnType = resolvedReturnType
118-
val columnName = columnName
119-
120111
val firPropertySymbol = FirRegularPropertySymbol(callableId)
121112

122113
val typeParameters = owner.typeParameterSymbols.map {
@@ -182,7 +173,7 @@ fun FirDeclarationGenerationExtension.buildExtensionPropertiesApi(
182173
typeArguments = arrayOf(marker),
183174
isMarkedNullable = false
184175
),
185-
propertyName = PropertyName.of(name, columnName?.let { PropertyName.buildAnnotation(it) }),
176+
propertyName = name,
186177
returnType = resolvedReturnType,
187178
source = owner.source,
188179
typeParameters = typeParameters,
@@ -193,7 +184,7 @@ fun FirDeclarationGenerationExtension.buildExtensionPropertiesApi(
193184
typeArguments = arrayOf(marker),
194185
isMarkedNullable = false
195186
),
196-
propertyName = PropertyName.of(name, columnName?.let { PropertyName.buildAnnotation(it) }),
187+
propertyName = name,
197188
returnType = columnReturnType,
198189
source = owner.source,
199190
typeParameters = typeParameters,

plugins/kotlin-dataframe/kotlin-dataframe.k2/src/org/jetbrains/kotlinx/dataframe/plugin/extensions/impl/PropertyName.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,5 @@ data class PropertyName(val identifier: Name, val columnNameAnnotation: FirAnnot
4444
}
4545
}
4646
}
47-
48-
fun of(identifier: Name, columnNameAnnotation: FirAnnotation?): PropertyName {
49-
return PropertyName(identifier, columnNameAnnotation)
50-
}
5147
}
5248
}

plugins/kotlin-dataframe/kotlin-dataframe.k2/src/org/jetbrains/kotlinx/dataframe/plugin/utils/firFactories.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import org.jetbrains.kotlin.fir.types.ConeClassLikeType
2020
import org.jetbrains.kotlin.fir.types.ConeKotlinType
2121
import org.jetbrains.kotlin.fir.types.constructClassType
2222
import org.jetbrains.kotlin.name.CallableId
23+
import org.jetbrains.kotlin.name.Name
2324
import org.jetbrains.kotlinx.dataframe.plugin.DataFramePlugin
24-
import org.jetbrains.kotlinx.dataframe.plugin.extensions.impl.PropertyName
2525

2626
internal fun FirDeclarationGenerationExtension.generateExtensionProperty(
2727
callableIdOrSymbol: CallableIdOrSymbol,
2828
receiverType: ConeClassLikeType,
29-
propertyName: PropertyName,
29+
propertyName: Name,
3030
returnType: ConeKotlinType,
3131
symbol: FirClassSymbol<*>? = null,
3232
effectiveVisibility: EffectiveVisibility = EffectiveVisibility.Public,
@@ -40,9 +40,6 @@ internal fun FirDeclarationGenerationExtension.generateExtensionProperty(
4040

4141
return buildProperty {
4242
this.source = source
43-
propertyName.columnNameAnnotation?.let {
44-
annotations += it
45-
}
4643
moduleData = session.moduleData
4744
resolvePhase = FirResolvePhase.BODY_RESOLVE
4845
origin = FirDeclarationOrigin.Plugin(DataFramePlugin)
@@ -84,7 +81,7 @@ internal fun FirDeclarationGenerationExtension.generateExtensionProperty(
8481
effectiveVisibility
8582
)
8683
}
87-
name = propertyName.identifier
84+
name = propertyName
8885
this.symbol = firPropertySymbol
8986
isVar = false
9087
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import org.jetbrains.kotlinx.dataframe.*
2+
import org.jetbrains.kotlinx.dataframe.annotations.*
3+
import org.jetbrains.kotlinx.dataframe.api.*
4+
import org.jetbrains.kotlinx.dataframe.io.*
5+
6+
@DataSchema
7+
data class MySchema(
8+
@ColumnName("Col")
9+
val col: Int
10+
)
11+
12+
fun box(): String {
13+
dataFrameOf("Col" to listOf(1, 2, 3)).cast<MySchema>().col
14+
return "OK"
15+
}
16+
17+
// triggers property generation before annotation arguments are resolved
18+
private fun DataFrame<MySchema>.convert() = col

plugins/kotlin-dataframe/tests-gen/org/jetbrains/kotlin/fir/dataframe/DataFrameBlackBoxCodegenTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)