Skip to content

fix compilation for markers with empty bodies in Jupyter #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ internal open class ExtensionsCodeGeneratorImpl(

private fun String.removeQuotes() = this.removeSurrounding("`")

private fun generateExtensionProperties(markers: List<Marker>) = markers.map { generateExtensionProperties(it) }

private fun generatePropertyCode(
marker: IsolatedMarker,
shortMarkerName: String,
Expand Down Expand Up @@ -430,11 +428,6 @@ internal class CodeGeneratorImpl(typeRendering: TypeRenderingStrategy = FullyQua
return CodeGenResult(code, context.generatedMarkers)
}

private fun generateInterfaces(
schemas: List<Marker>,
fields: Boolean,
) = schemas.map { generateInterface(it, fields) }

private fun generateInterface(
marker: Marker,
fields: Boolean,
Expand Down Expand Up @@ -483,7 +476,7 @@ internal class CodeGeneratorImpl(typeRendering: TypeRenderingStrategy = FullyQua
append("\n}")
}
} else {
""
" { }"
}
resultDeclarations.add(header + baseInterfacesDeclaration + body)
return resultDeclarations.join()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CodeGenerationTests : BaseTest() {
val typeName = ReplCodeGeneratorImpl.markerInterfacePrefix
val expectedDeclaration = """
@DataSchema
interface $typeName
interface $typeName { }

""".trimIndent() + "\n" + expectedProperties(typeName, typeName)

Expand All @@ -85,7 +85,7 @@ class CodeGenerationTests : BaseTest() {
val typeName = ReplCodeGeneratorImpl.markerInterfacePrefix
val expectedDeclaration = """
@DataSchema
interface $typeName
interface $typeName { }

""".trimIndent() + "\n" + expectedProperties(typeName, typeName)

Expand All @@ -104,7 +104,7 @@ class CodeGenerationTests : BaseTest() {
val type2 = ReplCodeGeneratorImpl.markerInterfacePrefix
val declaration1 = """
@DataSchema(isOpen = false)
interface $type1
interface $type1 { }

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 @@ -119,7 +119,7 @@ class CodeGenerationTests : BaseTest() {

val declaration2 = """
@DataSchema
interface $type2
interface $type2 { }

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 All @@ -146,7 +146,7 @@ class CodeGenerationTests : BaseTest() {
val personClass = (Person::class).qualifiedName!!
val expected = """
@DataSchema
interface $personClass
interface $personClass { }
""".trimIndent() + "\n" + expectedProperties(personClassName, personShortName)

val code = CodeGenerator.create(useFqNames = false)
Expand Down Expand Up @@ -203,7 +203,7 @@ class CodeGenerationTests : BaseTest() {
val code = codeGen.generate(df.schema(), "Person", false, true, true).code.declarations
val expected = """
@DataSchema
interface Person
interface Person { }

""".trimIndent() + "\n" + expectedProperties("Person", "Person")
code shouldBe expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ReplCodeGenTests : BaseTest() {

val expected = """
@DataSchema
interface $marker
interface $marker { }

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 Down Expand Up @@ -104,7 +104,7 @@ class ReplCodeGenTests : BaseTest() {
val marker3 = marker + "1"
val expected3 = """
@DataSchema
interface $marker3 : $markerFull
interface $marker3 : $markerFull { }

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 @@ -122,7 +122,7 @@ class ReplCodeGenTests : BaseTest() {
val marker5 = marker + "2"
val expected5 = """
@DataSchema
interface $marker5 : $markerFull
interface $marker5 : $markerFull { }

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 All @@ -145,7 +145,7 @@ class ReplCodeGenTests : BaseTest() {

val expected = """
@DataSchema
interface ${Test2._DataFrameType2::class.simpleName!!} : ${Test2._DataFrameType::class.qualifiedName}, ${Test2._DataFrameType1::class.qualifiedName}
interface ${Test2._DataFrameType2::class.simpleName!!} : ${Test2._DataFrameType::class.qualifiedName}, ${Test2._DataFrameType1::class.qualifiedName} { }

""".trimIndent()

Expand All @@ -164,7 +164,7 @@ 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 $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 @@ -51,4 +51,14 @@ class CodeGenerationTests : DataFrameJupyterTest() {
row.a
""".checkCompilation()
}

@Test
fun `interface without body compiled correctly`() {
"""
val a = dataFrameOf("a")(1, 2, 3)
val b = dataFrameOf("b")(1, 2, 3)
val ab = dataFrameOf("a", "b")(1, 2)
ab.a
""".checkCompilation()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ internal open class ExtensionsCodeGeneratorImpl(

private fun String.removeQuotes() = this.removeSurrounding("`")

private fun generateExtensionProperties(markers: List<Marker>) = markers.map { generateExtensionProperties(it) }

private fun generatePropertyCode(
marker: IsolatedMarker,
shortMarkerName: String,
Expand Down Expand Up @@ -430,11 +428,6 @@ internal class CodeGeneratorImpl(typeRendering: TypeRenderingStrategy = FullyQua
return CodeGenResult(code, context.generatedMarkers)
}

private fun generateInterfaces(
schemas: List<Marker>,
fields: Boolean,
) = schemas.map { generateInterface(it, fields) }

private fun generateInterface(
marker: Marker,
fields: Boolean,
Expand Down Expand Up @@ -483,7 +476,7 @@ internal class CodeGeneratorImpl(typeRendering: TypeRenderingStrategy = FullyQua
append("\n}")
}
} else {
""
" { }"
}
resultDeclarations.add(header + baseInterfacesDeclaration + body)
return resultDeclarations.join()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CodeGenerationTests : BaseTest() {
val typeName = ReplCodeGeneratorImpl.markerInterfacePrefix
val expectedDeclaration = """
@DataSchema
interface $typeName
interface $typeName { }

""".trimIndent() + "\n" + expectedProperties(typeName, typeName)

Expand All @@ -85,7 +85,7 @@ class CodeGenerationTests : BaseTest() {
val typeName = ReplCodeGeneratorImpl.markerInterfacePrefix
val expectedDeclaration = """
@DataSchema
interface $typeName
interface $typeName { }

""".trimIndent() + "\n" + expectedProperties(typeName, typeName)

Expand All @@ -104,7 +104,7 @@ class CodeGenerationTests : BaseTest() {
val type2 = ReplCodeGeneratorImpl.markerInterfacePrefix
val declaration1 = """
@DataSchema(isOpen = false)
interface $type1
interface $type1 { }

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 @@ -119,7 +119,7 @@ class CodeGenerationTests : BaseTest() {

val declaration2 = """
@DataSchema
interface $type2
interface $type2 { }

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 All @@ -146,7 +146,7 @@ class CodeGenerationTests : BaseTest() {
val personClass = (Person::class).qualifiedName!!
val expected = """
@DataSchema
interface $personClass
interface $personClass { }
""".trimIndent() + "\n" + expectedProperties(personClassName, personShortName)

val code = CodeGenerator.create(useFqNames = false)
Expand Down Expand Up @@ -203,7 +203,7 @@ class CodeGenerationTests : BaseTest() {
val code = codeGen.generate(df.schema(), "Person", false, true, true).code.declarations
val expected = """
@DataSchema
interface Person
interface Person { }

""".trimIndent() + "\n" + expectedProperties("Person", "Person")
code shouldBe expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ReplCodeGenTests : BaseTest() {

val expected = """
@DataSchema
interface $marker
interface $marker { }

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 Down Expand Up @@ -104,7 +104,7 @@ class ReplCodeGenTests : BaseTest() {
val marker3 = marker + "1"
val expected3 = """
@DataSchema
interface $marker3 : $markerFull
interface $marker3 : $markerFull { }

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 @@ -122,7 +122,7 @@ class ReplCodeGenTests : BaseTest() {
val marker5 = marker + "2"
val expected5 = """
@DataSchema
interface $marker5 : $markerFull
interface $marker5 : $markerFull { }

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 All @@ -145,7 +145,7 @@ class ReplCodeGenTests : BaseTest() {

val expected = """
@DataSchema
interface ${Test2._DataFrameType2::class.simpleName!!} : ${Test2._DataFrameType::class.qualifiedName}, ${Test2._DataFrameType1::class.qualifiedName}
interface ${Test2._DataFrameType2::class.simpleName!!} : ${Test2._DataFrameType::class.qualifiedName}, ${Test2._DataFrameType1::class.qualifiedName} { }

""".trimIndent()

Expand All @@ -164,7 +164,7 @@ 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 $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 @@ -51,4 +51,14 @@ class CodeGenerationTests : DataFrameJupyterTest() {
row.a
""".checkCompilation()
}

@Test
fun `interface without body compiled correctly`() {
"""
val a = dataFrameOf("a")(1, 2, 3)
val b = dataFrameOf("b")(1, 2, 3)
val ab = dataFrameOf("a", "b")(1, 2)
ab.a
""".checkCompilation()
}
}