Skip to content

Commit

Permalink
Generate fields in REPL for data schemas
Browse files Browse the repository at this point in the history
Compiler plugin and IDE plugin need this information
  • Loading branch information
koperagen committed May 10, 2024
1 parent 8990376 commit 54fcd47
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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?
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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?
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit 54fcd47

Please sign in to comment.