Skip to content

Commit c81fc4f

Browse files
authored
Merge pull request #200 from Kotlin/dataschema-generic-inheritance
Dataschema generic inheritance
2 parents 65687b4 + 4855060 commit c81fc4f

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/MarkersExtractor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import org.jetbrains.kotlinx.dataframe.impl.schema.getPropertiesOrder
88
import org.jetbrains.kotlinx.dataframe.schema.ColumnSchema
99
import kotlin.reflect.KClass
1010
import kotlin.reflect.KType
11-
import kotlin.reflect.full.declaredMemberProperties
1211
import kotlin.reflect.full.findAnnotation
1312
import kotlin.reflect.full.hasAnnotation
13+
import kotlin.reflect.full.memberProperties
1414
import kotlin.reflect.full.superclasses
1515
import kotlin.reflect.full.withNullability
1616
import kotlin.reflect.jvm.jvmErasure
@@ -54,7 +54,7 @@ internal object MarkersExtractor {
5454

5555
private fun getFields(markerClass: KClass<*>, nullableProperties: Boolean): List<GeneratedField> {
5656
val order = getPropertiesOrder(markerClass)
57-
return markerClass.declaredMemberProperties.sortedBy { order[it.name] ?: Int.MAX_VALUE }.mapIndexed { _, it ->
57+
return markerClass.memberProperties.sortedBy { order[it.name] ?: Int.MAX_VALUE }.mapIndexed { _, it ->
5858
val fieldName = ValidFieldName.of(it.name)
5959
val columnName = it.findAnnotation<ColumnName>()?.name ?: fieldName.unquoted
6060
val type = it.returnType

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/convertTo.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.kotest.assertions.throwables.shouldThrow
44
import io.kotest.matchers.shouldBe
55
import org.jetbrains.kotlinx.dataframe.AnyFrame
66
import org.jetbrains.kotlinx.dataframe.DataFrame
7+
import org.jetbrains.kotlinx.dataframe.alsoDebug
78
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
89
import org.jetbrains.kotlinx.dataframe.exceptions.TypeConverterNotFoundException
910
import org.junit.Test
@@ -239,9 +240,21 @@ class ConvertToTests {
239240
.alsoDebug("df5 after second convert:")
240241
}
241242

242-
private fun <T : DataFrame<*>> T.alsoDebug(println: String? = null): T = apply {
243-
println?.let { println(it) }
244-
print(borders = true, title = true, columnTypes = true, valueLimit = -1)
245-
schema().print()
243+
interface KeyValue<T> {
244+
val key: String
245+
val value: T
246+
}
247+
248+
@DataSchema
249+
interface MySchema : KeyValue<Int>
250+
251+
@Test
252+
fun `Convert generic interface to itself`() {
253+
val df = dataFrameOf("key", "value")(
254+
"a", 1,
255+
"b", 2,
256+
).alsoDebug()
257+
val converted = df.convertTo<MySchema>().alsoDebug()
258+
converted shouldBe df
246259
}
247260
}

plugins/symbol-processor/src/main/kotlin/org/jetbrains/dataframe/ksp/ExtensionsGenerator.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.google.devtools.ksp.symbol.KSClassifierReference
1212
import com.google.devtools.ksp.symbol.KSDeclaration
1313
import com.google.devtools.ksp.symbol.KSFile
1414
import com.google.devtools.ksp.symbol.KSName
15-
import com.google.devtools.ksp.symbol.KSPropertyDeclaration
1615
import com.google.devtools.ksp.symbol.KSTypeReference
1716
import com.google.devtools.ksp.symbol.KSValueArgument
1817
import com.google.devtools.ksp.symbol.Modifier
@@ -61,11 +60,10 @@ class ExtensionsGenerator(
6160
return when {
6261
isClassOrInterface() && effectivelyPublicOrInternal() -> {
6362
DataSchemaDeclaration(
64-
this,
65-
declarations
66-
.filterIsInstance<KSPropertyDeclaration>()
63+
origin = this,
64+
properties = getAllProperties()
6765
.map { KSAnnotatedWithType(it, it.simpleName, it.type) }
68-
.toList()
66+
.toList(),
6967
)
7068
}
7169
else -> null

plugins/symbol-processor/src/test/kotlin/org/jetbrains/dataframe/ksp/DataFrameSymbolProcessorTest.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,37 @@ class DataFrameSymbolProcessorTest {
748748
result.successfulCompilation shouldBe true
749749
}
750750

751+
@Test
752+
fun `generic interface as supertype`() {
753+
val result = KspCompilationTestRunner.compile(
754+
TestCompilationParameters(
755+
sources = listOf(
756+
SourceFile.kotlin(
757+
"MySources.kt",
758+
"""
759+
package org.example
760+
761+
$imports
762+
763+
interface KeyValue<T> {
764+
val key: String
765+
val value: T
766+
}
767+
768+
@DataSchema
769+
interface MySchema : KeyValue<Int>
770+
771+
772+
val ColumnsContainer<MySchema>.test1: DataColumn<String> get() = key
773+
val DataRow<MySchema>.test2: Int get() = value
774+
""".trimIndent()
775+
)
776+
)
777+
)
778+
)
779+
result.successfulCompilation shouldBe true
780+
}
781+
751782
@Test
752783
fun `nested interface`() {
753784
val result = KspCompilationTestRunner.compile(

0 commit comments

Comments
 (0)