Revert "Add setting for Kotlin package to codegen (#194)" (#271)

This reverts commit 7f404fff49.

The package is derived from the module name.
Having `module com.example.Foo` in Pkl
will create Kotlin `package com.example`.

Eventually, we may want to introduce a way to map
Pkl names to package names that provides finer
controls to the code generator.
This commit is contained in:
Daniel Chao
2024-03-04 07:51:39 -08:00
committed by GitHub
parent 4f3858aaaf
commit 11f07d1ce8
7 changed files with 8 additions and 145 deletions

View File

@@ -133,8 +133,7 @@ class KotlinCodeGeneratorTest {
pklCode: String,
generateKdoc: Boolean = false,
generateSpringBootConfig: Boolean = false,
implementSerializable: Boolean = false,
kotlinPackage: String? = null,
implementSerializable: Boolean = false
): String {
val module = Evaluator.preconfigured().evaluateSchema(ModuleSource.text(pklCode))
@@ -145,8 +144,7 @@ class KotlinCodeGeneratorTest {
KotlinCodegenOptions(
generateKdoc = generateKdoc,
generateSpringBootConfig = generateSpringBootConfig,
implementSerializable = implementSerializable,
kotlinPackage = kotlinPackage ?: "",
implementSerializable = implementSerializable
)
)
return generator.kotlinFile
@@ -555,92 +553,6 @@ class KotlinCodeGeneratorTest {
assertCompilesSuccessfully(kotlinCode)
}
@Test
fun `custom kotlin package prefix`() {
val kotlinCode =
generateKotlinCode(
"""
module my.mod
class Person {
name: String
age: Int
hobbies: List<String>
friends: Map<String, Person>
sibling: Person?
}
""",
kotlinPackage = "cool.pkg.path",
)
assertEqualTo(
"""
package cool.pkg.path.my
import kotlin.Long
import kotlin.String
import kotlin.collections.List
import kotlin.collections.Map
object Mod {
data class Person(
val name: String,
val age: Long,
val hobbies: List<String>,
val friends: Map<String, Person>,
val sibling: Person?
)
}
""",
kotlinCode
)
assertCompilesSuccessfully(kotlinCode)
}
@Test
fun `empty kotlin package prefix`() {
val kotlinCode =
generateKotlinCode(
"""
module my.mod
class Person {
name: String
age: Int
hobbies: List<String>
friends: Map<String, Person>
sibling: Person?
}
""",
kotlinPackage = "",
)
assertEqualTo(
"""
package my
import kotlin.Long
import kotlin.String
import kotlin.collections.List
import kotlin.collections.Map
object Mod {
data class Person(
val name: String,
val age: Long,
val hobbies: List<String>,
val friends: Map<String, Person>,
val sibling: Person?
)
}
""",
kotlinCode
)
assertCompilesSuccessfully(kotlinCode)
}
@Test
fun `recursive types`() {
val kotlinCode =