Skip to content

Commit

Permalink
Point plugin-generated properties to their origin
Browse files Browse the repository at this point in the history
  • Loading branch information
koperagen committed Jan 29, 2025
1 parent 5210863 commit 48dab7a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.kotlinx.dataframe.plugin.extensions

import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlinx.dataframe.plugin.extensions.impl.SchemaProperty
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirDeclarationDataKey
Expand All @@ -9,7 +10,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
sealed interface CallShapeData {
class Schema(val columns: List<SchemaProperty>) : CallShapeData

class Scope(val columns: List<SchemaProperty>) : CallShapeData
class Scope(val columns: List<SchemaProperty>, val source: KtSourceElement?) : CallShapeData

class RefinedType(val scopes: List<FirRegularClassSymbol>) : CallShapeData
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ class FunctionCallTransformer(
}
}
schema.callShapeData = CallShapeData.Schema(properties)
scope.callShapeData = CallShapeData.Scope(properties)
scope.callShapeData = CallShapeData.Scope(properties, call.calleeReference.source)
val schemaApi = DataSchemaApi(schema, scope)
dataSchemaApis.add(schemaApi)
return schemaApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ class TokenGenerator(session: FirSession) : FirDeclarationGenerationExtension(se
val callableId = CallableId(k.classId, propertyName.identifier)
val dataRowExtension = generateExtensionProperty(
callableId = callableId,
symbol = k,
receiverType = ConeClassLikeTypeImpl(
ConeClassLikeLookupTagImpl(Names.DATA_ROW_CLASS_ID),
typeArguments = arrayOf(schemaProperty.marker),
isNullable = false
),
propertyName = propertyName,
returnTypeRef = schemaProperty.dataRowReturnType.toFirResolvedTypeRef(),
effectiveVisibility = EffectiveVisibility.Local
symbol = k,
effectiveVisibility = EffectiveVisibility.Local,
source = callShapeData.source
)

val columnContainerExtension = generateExtensionProperty(
Expand All @@ -80,7 +81,8 @@ class TokenGenerator(session: FirSession) : FirDeclarationGenerationExtension(se
propertyName = propertyName,
returnTypeRef = schemaProperty.columnContainerReturnType.toFirResolvedTypeRef(),
symbol = k,
effectiveVisibility = EffectiveVisibility.Local
effectiveVisibility = EffectiveVisibility.Local,
source = callShapeData.source
)
propertyName.identifier to listOf(dataRowExtension, columnContainerExtension)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class TopLevelExtensionsGenerator(session: FirSession) : FirDeclarationGeneratio
isNullable = false
),
propertyName = PropertyName.of(name, columnName?.let { PropertyName.buildAnnotation(it) }),
returnTypeRef = resolvedReturnTypeRef
returnTypeRef = resolvedReturnTypeRef,
source = owner.source
)

val columnReturnType = when {
Expand All @@ -142,7 +143,8 @@ class TopLevelExtensionsGenerator(session: FirSession) : FirDeclarationGeneratio
isNullable = false
),
propertyName = PropertyName.of(name, columnName?.let { PropertyName.buildAnnotation(it) }),
returnTypeRef = columnReturnType
returnTypeRef = columnReturnType,
source = owner.source
)
listOf(rowExtension.symbol, columnsContainerExtension.symbol)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.kotlinx.dataframe.plugin.utils

import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.descriptors.EffectiveVisibility
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibilities
Expand Down Expand Up @@ -30,10 +31,12 @@ internal fun FirDeclarationGenerationExtension.generateExtensionProperty(
propertyName: PropertyName,
returnTypeRef: FirResolvedTypeRef,
symbol: FirClassSymbol<*>? = null,
effectiveVisibility: EffectiveVisibility = EffectiveVisibility.Public
effectiveVisibility: EffectiveVisibility = EffectiveVisibility.Public,
source: KtSourceElement?
): FirProperty {
val firPropertySymbol = FirPropertySymbol(callableId)
return buildProperty {
this.source = source
propertyName.columnNameAnnotation?.let {
annotations += it
}
Expand Down

0 comments on commit 48dab7a

Please sign in to comment.