From 54fcd475e663be88e727141d9a843c491bc7962d Mon Sep 17 00:00:00 2001 From: Nikita Klimenko Date: Fri, 10 May 2024 14:06:17 +0300 Subject: [PATCH] Generate fields in REPL for data schemas Compiler plugin and IDE plugin need this information --- .../impl/codeGen/ReplCodeGeneratorImpl.kt | 2 +- .../dataframe/codeGen/CodeGenerationTests.kt | 25 ++++++++++++++++--- .../dataframe/codeGen/ReplCodeGenTests.kt | 20 ++++++++++++--- .../impl/codeGen/ReplCodeGeneratorImpl.kt | 2 +- .../dataframe/codeGen/CodeGenerationTests.kt | 25 ++++++++++++++++--- .../dataframe/codeGen/ReplCodeGenTests.kt | 20 ++++++++++++--- 6 files changed, 76 insertions(+), 18 deletions(-) diff --git a/core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/ReplCodeGeneratorImpl.kt b/core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/ReplCodeGeneratorImpl.kt index ee32c8e231..763ac1c871 100644 --- a/core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/ReplCodeGeneratorImpl.kt +++ b/core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/ReplCodeGeneratorImpl.kt @@ -86,7 +86,7 @@ internal class ReplCodeGeneratorImpl : ReplCodeGenerator { val result = generator.generate( schema = schema, name = name, - fields = false, + fields = true, extensionProperties = true, isOpen = isOpen, visibility = MarkerVisibility.IMPLICIT_PUBLIC, diff --git a/core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt b/core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt index affb54991c..8486cc1b49 100644 --- a/core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt +++ b/core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt @@ -69,7 +69,12 @@ class CodeGenerationTests : BaseTest() { val typeName = ReplCodeGeneratorImpl.markerInterfacePrefix val expectedDeclaration = """ @DataSchema - interface $typeName { } + interface $typeName { + val age: Int + val city: String? + val name: String + val weight: Int? + } """.trimIndent() + "\n" + expectedProperties(typeName, typeName) @@ -94,7 +99,12 @@ class CodeGenerationTests : BaseTest() { val typeName = ReplCodeGeneratorImpl.markerInterfacePrefix val expectedDeclaration = """ @DataSchema - interface $typeName { } + interface $typeName { + val age: Int + val city: String? + val name: String + val weight: Int? + } """.trimIndent() + "\n" + expectedProperties(typeName, typeName) @@ -113,7 +123,10 @@ class CodeGenerationTests : BaseTest() { val type2 = ReplCodeGeneratorImpl.markerInterfacePrefix val declaration1 = """ @DataSchema(isOpen = false) - interface $type1 { } + interface $type1 { + val city: String? + val name: String + } val $dfName<$type1>.city: $dataCol<$stringName?> @JvmName("${type1}_city") get() = this["city"] as $dataCol<$stringName?> val $dfRowName<$type1>.city: $stringName? @JvmName("${type1}_city") get() = this["city"] as $stringName? @@ -124,7 +137,11 @@ class CodeGenerationTests : BaseTest() { val declaration2 = """ @DataSchema - interface $type2 { } + interface $type2 { + val age: Int + val nameAndCity: _DataFrameType1 + val weight: Int? + } val $dfName<$type2>.age: $dataCol<$intName> @JvmName("${type2}_age") get() = this["age"] as $dataCol<$intName> val $dfRowName<$type2>.age: $intName @JvmName("${type2}_age") get() = this["age"] as $intName diff --git a/core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt b/core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt index a63363935e..c8871a606b 100644 --- a/core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt +++ b/core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt @@ -75,7 +75,12 @@ class ReplCodeGenTests : BaseTest() { val expected = """ @DataSchema - interface $marker { } + interface $marker { + val age: Int + val city: String? + val name: String + val weight: Int? + } val $dfName<$marker>.age: $dataCol<$intName> @JvmName("${marker}_age") get() = this["age"] as $dataCol<$intName> val $dfRowName<$marker>.age: $intName @JvmName("${marker}_age") get() = this["age"] as $intName @@ -96,7 +101,9 @@ class ReplCodeGenTests : BaseTest() { val marker3 = marker + "1" val expected3 = """ @DataSchema - interface $marker3 : $markerFull { } + interface $marker3 : $markerFull { + override val city: String + } val $dfName<$marker3>.city: $dataCol<$stringName> @JvmName("${marker3}_city") get() = this["city"] as $dataCol<$stringName> val $dfRowName<$marker3>.city: $stringName @JvmName("${marker3}_city") get() = this["city"] as $stringName @@ -112,7 +119,9 @@ class ReplCodeGenTests : BaseTest() { val marker5 = marker + "2" val expected5 = """ @DataSchema - interface $marker5 : $markerFull { } + interface $marker5 : $markerFull { + override val weight: Int + } val $dfName<$marker5>.weight: $dataCol<$intName> @JvmName("${marker5}_weight") get() = this["weight"] as $dataCol<$intName> val $dfRowName<$marker5>.weight: $intName @JvmName("${marker5}_weight") get() = this["weight"] as $intName @@ -152,7 +161,10 @@ class ReplCodeGenTests : BaseTest() { val marker = Test2._DataFrameType2::class.simpleName!! val expected = """ @DataSchema - interface $marker : ${Test2._DataFrameType::class.qualifiedName} { } + interface $marker : ${Test2._DataFrameType::class.qualifiedName} { + val city: String? + val weight: Int? + } val $dfName<$marker>.city: $dataCol<$stringName?> @JvmName("${marker}_city") get() = this["city"] as $dataCol<$stringName?> val $dfRowName<$marker>.city: $stringName? @JvmName("${marker}_city") get() = this["city"] as $stringName? diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/ReplCodeGeneratorImpl.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/ReplCodeGeneratorImpl.kt index ee32c8e231..763ac1c871 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/ReplCodeGeneratorImpl.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/ReplCodeGeneratorImpl.kt @@ -86,7 +86,7 @@ internal class ReplCodeGeneratorImpl : ReplCodeGenerator { val result = generator.generate( schema = schema, name = name, - fields = false, + fields = true, extensionProperties = true, isOpen = isOpen, visibility = MarkerVisibility.IMPLICIT_PUBLIC, diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt index affb54991c..8486cc1b49 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt @@ -69,7 +69,12 @@ class CodeGenerationTests : BaseTest() { val typeName = ReplCodeGeneratorImpl.markerInterfacePrefix val expectedDeclaration = """ @DataSchema - interface $typeName { } + interface $typeName { + val age: Int + val city: String? + val name: String + val weight: Int? + } """.trimIndent() + "\n" + expectedProperties(typeName, typeName) @@ -94,7 +99,12 @@ class CodeGenerationTests : BaseTest() { val typeName = ReplCodeGeneratorImpl.markerInterfacePrefix val expectedDeclaration = """ @DataSchema - interface $typeName { } + interface $typeName { + val age: Int + val city: String? + val name: String + val weight: Int? + } """.trimIndent() + "\n" + expectedProperties(typeName, typeName) @@ -113,7 +123,10 @@ class CodeGenerationTests : BaseTest() { val type2 = ReplCodeGeneratorImpl.markerInterfacePrefix val declaration1 = """ @DataSchema(isOpen = false) - interface $type1 { } + interface $type1 { + val city: String? + val name: String + } val $dfName<$type1>.city: $dataCol<$stringName?> @JvmName("${type1}_city") get() = this["city"] as $dataCol<$stringName?> val $dfRowName<$type1>.city: $stringName? @JvmName("${type1}_city") get() = this["city"] as $stringName? @@ -124,7 +137,11 @@ class CodeGenerationTests : BaseTest() { val declaration2 = """ @DataSchema - interface $type2 { } + interface $type2 { + val age: Int + val nameAndCity: _DataFrameType1 + val weight: Int? + } val $dfName<$type2>.age: $dataCol<$intName> @JvmName("${type2}_age") get() = this["age"] as $dataCol<$intName> val $dfRowName<$type2>.age: $intName @JvmName("${type2}_age") get() = this["age"] as $intName diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt index a63363935e..c8871a606b 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt @@ -75,7 +75,12 @@ class ReplCodeGenTests : BaseTest() { val expected = """ @DataSchema - interface $marker { } + interface $marker { + val age: Int + val city: String? + val name: String + val weight: Int? + } val $dfName<$marker>.age: $dataCol<$intName> @JvmName("${marker}_age") get() = this["age"] as $dataCol<$intName> val $dfRowName<$marker>.age: $intName @JvmName("${marker}_age") get() = this["age"] as $intName @@ -96,7 +101,9 @@ class ReplCodeGenTests : BaseTest() { val marker3 = marker + "1" val expected3 = """ @DataSchema - interface $marker3 : $markerFull { } + interface $marker3 : $markerFull { + override val city: String + } val $dfName<$marker3>.city: $dataCol<$stringName> @JvmName("${marker3}_city") get() = this["city"] as $dataCol<$stringName> val $dfRowName<$marker3>.city: $stringName @JvmName("${marker3}_city") get() = this["city"] as $stringName @@ -112,7 +119,9 @@ class ReplCodeGenTests : BaseTest() { val marker5 = marker + "2" val expected5 = """ @DataSchema - interface $marker5 : $markerFull { } + interface $marker5 : $markerFull { + override val weight: Int + } val $dfName<$marker5>.weight: $dataCol<$intName> @JvmName("${marker5}_weight") get() = this["weight"] as $dataCol<$intName> val $dfRowName<$marker5>.weight: $intName @JvmName("${marker5}_weight") get() = this["weight"] as $intName @@ -152,7 +161,10 @@ class ReplCodeGenTests : BaseTest() { val marker = Test2._DataFrameType2::class.simpleName!! val expected = """ @DataSchema - interface $marker : ${Test2._DataFrameType::class.qualifiedName} { } + interface $marker : ${Test2._DataFrameType::class.qualifiedName} { + val city: String? + val weight: Int? + } val $dfName<$marker>.city: $dataCol<$stringName?> @JvmName("${marker}_city") get() = this["city"] as $dataCol<$stringName?> val $dfRowName<$marker>.city: $stringName? @JvmName("${marker}_city") get() = this["city"] as $stringName?