Skip to content

Commit 54fcd47

Browse files
committed
Generate fields in REPL for data schemas
Compiler plugin and IDE plugin need this information
1 parent 8990376 commit 54fcd47

File tree

6 files changed

+76
-18
lines changed

6 files changed

+76
-18
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/ReplCodeGeneratorImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ internal class ReplCodeGeneratorImpl : ReplCodeGenerator {
8686
val result = generator.generate(
8787
schema = schema,
8888
name = name,
89-
fields = false,
89+
fields = true,
9090
extensionProperties = true,
9191
isOpen = isOpen,
9292
visibility = MarkerVisibility.IMPLICIT_PUBLIC,

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ class CodeGenerationTests : BaseTest() {
6969
val typeName = ReplCodeGeneratorImpl.markerInterfacePrefix
7070
val expectedDeclaration = """
7171
@DataSchema
72-
interface $typeName { }
72+
interface $typeName {
73+
val age: Int
74+
val city: String?
75+
val name: String
76+
val weight: Int?
77+
}
7378
7479
""".trimIndent() + "\n" + expectedProperties(typeName, typeName)
7580

@@ -94,7 +99,12 @@ class CodeGenerationTests : BaseTest() {
9499
val typeName = ReplCodeGeneratorImpl.markerInterfacePrefix
95100
val expectedDeclaration = """
96101
@DataSchema
97-
interface $typeName { }
102+
interface $typeName {
103+
val age: Int
104+
val city: String?
105+
val name: String
106+
val weight: Int?
107+
}
98108
99109
""".trimIndent() + "\n" + expectedProperties(typeName, typeName)
100110

@@ -113,7 +123,10 @@ class CodeGenerationTests : BaseTest() {
113123
val type2 = ReplCodeGeneratorImpl.markerInterfacePrefix
114124
val declaration1 = """
115125
@DataSchema(isOpen = false)
116-
interface $type1 { }
126+
interface $type1 {
127+
val city: String?
128+
val name: String
129+
}
117130
118131
val $dfName<$type1>.city: $dataCol<$stringName?> @JvmName("${type1}_city") get() = this["city"] as $dataCol<$stringName?>
119132
val $dfRowName<$type1>.city: $stringName? @JvmName("${type1}_city") get() = this["city"] as $stringName?
@@ -124,7 +137,11 @@ class CodeGenerationTests : BaseTest() {
124137

125138
val declaration2 = """
126139
@DataSchema
127-
interface $type2 { }
140+
interface $type2 {
141+
val age: Int
142+
val nameAndCity: _DataFrameType1
143+
val weight: Int?
144+
}
128145
129146
val $dfName<$type2>.age: $dataCol<$intName> @JvmName("${type2}_age") get() = this["age"] as $dataCol<$intName>
130147
val $dfRowName<$type2>.age: $intName @JvmName("${type2}_age") get() = this["age"] as $intName

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ class ReplCodeGenTests : BaseTest() {
7575

7676
val expected = """
7777
@DataSchema
78-
interface $marker { }
78+
interface $marker {
79+
val age: Int
80+
val city: String?
81+
val name: String
82+
val weight: Int?
83+
}
7984
8085
val $dfName<$marker>.age: $dataCol<$intName> @JvmName("${marker}_age") get() = this["age"] as $dataCol<$intName>
8186
val $dfRowName<$marker>.age: $intName @JvmName("${marker}_age") get() = this["age"] as $intName
@@ -96,7 +101,9 @@ class ReplCodeGenTests : BaseTest() {
96101
val marker3 = marker + "1"
97102
val expected3 = """
98103
@DataSchema
99-
interface $marker3 : $markerFull { }
104+
interface $marker3 : $markerFull {
105+
override val city: String
106+
}
100107
101108
val $dfName<$marker3>.city: $dataCol<$stringName> @JvmName("${marker3}_city") get() = this["city"] as $dataCol<$stringName>
102109
val $dfRowName<$marker3>.city: $stringName @JvmName("${marker3}_city") get() = this["city"] as $stringName
@@ -112,7 +119,9 @@ class ReplCodeGenTests : BaseTest() {
112119
val marker5 = marker + "2"
113120
val expected5 = """
114121
@DataSchema
115-
interface $marker5 : $markerFull { }
122+
interface $marker5 : $markerFull {
123+
override val weight: Int
124+
}
116125
117126
val $dfName<$marker5>.weight: $dataCol<$intName> @JvmName("${marker5}_weight") get() = this["weight"] as $dataCol<$intName>
118127
val $dfRowName<$marker5>.weight: $intName @JvmName("${marker5}_weight") get() = this["weight"] as $intName
@@ -152,7 +161,10 @@ class ReplCodeGenTests : BaseTest() {
152161
val marker = Test2._DataFrameType2::class.simpleName!!
153162
val expected = """
154163
@DataSchema
155-
interface $marker : ${Test2._DataFrameType::class.qualifiedName} { }
164+
interface $marker : ${Test2._DataFrameType::class.qualifiedName} {
165+
val city: String?
166+
val weight: Int?
167+
}
156168
157169
val $dfName<$marker>.city: $dataCol<$stringName?> @JvmName("${marker}_city") get() = this["city"] as $dataCol<$stringName?>
158170
val $dfRowName<$marker>.city: $stringName? @JvmName("${marker}_city") get() = this["city"] as $stringName?

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ internal class ReplCodeGeneratorImpl : ReplCodeGenerator {
8686
val result = generator.generate(
8787
schema = schema,
8888
name = name,
89-
fields = false,
89+
fields = true,
9090
extensionProperties = true,
9191
isOpen = isOpen,
9292
visibility = MarkerVisibility.IMPLICIT_PUBLIC,

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ class CodeGenerationTests : BaseTest() {
6969
val typeName = ReplCodeGeneratorImpl.markerInterfacePrefix
7070
val expectedDeclaration = """
7171
@DataSchema
72-
interface $typeName { }
72+
interface $typeName {
73+
val age: Int
74+
val city: String?
75+
val name: String
76+
val weight: Int?
77+
}
7378
7479
""".trimIndent() + "\n" + expectedProperties(typeName, typeName)
7580

@@ -94,7 +99,12 @@ class CodeGenerationTests : BaseTest() {
9499
val typeName = ReplCodeGeneratorImpl.markerInterfacePrefix
95100
val expectedDeclaration = """
96101
@DataSchema
97-
interface $typeName { }
102+
interface $typeName {
103+
val age: Int
104+
val city: String?
105+
val name: String
106+
val weight: Int?
107+
}
98108
99109
""".trimIndent() + "\n" + expectedProperties(typeName, typeName)
100110

@@ -113,7 +123,10 @@ class CodeGenerationTests : BaseTest() {
113123
val type2 = ReplCodeGeneratorImpl.markerInterfacePrefix
114124
val declaration1 = """
115125
@DataSchema(isOpen = false)
116-
interface $type1 { }
126+
interface $type1 {
127+
val city: String?
128+
val name: String
129+
}
117130
118131
val $dfName<$type1>.city: $dataCol<$stringName?> @JvmName("${type1}_city") get() = this["city"] as $dataCol<$stringName?>
119132
val $dfRowName<$type1>.city: $stringName? @JvmName("${type1}_city") get() = this["city"] as $stringName?
@@ -124,7 +137,11 @@ class CodeGenerationTests : BaseTest() {
124137

125138
val declaration2 = """
126139
@DataSchema
127-
interface $type2 { }
140+
interface $type2 {
141+
val age: Int
142+
val nameAndCity: _DataFrameType1
143+
val weight: Int?
144+
}
128145
129146
val $dfName<$type2>.age: $dataCol<$intName> @JvmName("${type2}_age") get() = this["age"] as $dataCol<$intName>
130147
val $dfRowName<$type2>.age: $intName @JvmName("${type2}_age") get() = this["age"] as $intName

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ class ReplCodeGenTests : BaseTest() {
7575

7676
val expected = """
7777
@DataSchema
78-
interface $marker { }
78+
interface $marker {
79+
val age: Int
80+
val city: String?
81+
val name: String
82+
val weight: Int?
83+
}
7984
8085
val $dfName<$marker>.age: $dataCol<$intName> @JvmName("${marker}_age") get() = this["age"] as $dataCol<$intName>
8186
val $dfRowName<$marker>.age: $intName @JvmName("${marker}_age") get() = this["age"] as $intName
@@ -96,7 +101,9 @@ class ReplCodeGenTests : BaseTest() {
96101
val marker3 = marker + "1"
97102
val expected3 = """
98103
@DataSchema
99-
interface $marker3 : $markerFull { }
104+
interface $marker3 : $markerFull {
105+
override val city: String
106+
}
100107
101108
val $dfName<$marker3>.city: $dataCol<$stringName> @JvmName("${marker3}_city") get() = this["city"] as $dataCol<$stringName>
102109
val $dfRowName<$marker3>.city: $stringName @JvmName("${marker3}_city") get() = this["city"] as $stringName
@@ -112,7 +119,9 @@ class ReplCodeGenTests : BaseTest() {
112119
val marker5 = marker + "2"
113120
val expected5 = """
114121
@DataSchema
115-
interface $marker5 : $markerFull { }
122+
interface $marker5 : $markerFull {
123+
override val weight: Int
124+
}
116125
117126
val $dfName<$marker5>.weight: $dataCol<$intName> @JvmName("${marker5}_weight") get() = this["weight"] as $dataCol<$intName>
118127
val $dfRowName<$marker5>.weight: $intName @JvmName("${marker5}_weight") get() = this["weight"] as $intName
@@ -152,7 +161,10 @@ class ReplCodeGenTests : BaseTest() {
152161
val marker = Test2._DataFrameType2::class.simpleName!!
153162
val expected = """
154163
@DataSchema
155-
interface $marker : ${Test2._DataFrameType::class.qualifiedName} { }
164+
interface $marker : ${Test2._DataFrameType::class.qualifiedName} {
165+
val city: String?
166+
val weight: Int?
167+
}
156168
157169
val $dfName<$marker>.city: $dataCol<$stringName?> @JvmName("${marker}_city") get() = this["city"] as $dataCol<$stringName?>
158170
val $dfRowName<$marker>.city: $stringName? @JvmName("${marker}_city") get() = this["city"] as $stringName?

0 commit comments

Comments
 (0)