File tree Expand file tree Collapse file tree
main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen
test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen
dataframe-openapi-generator/src/test/kotlin Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
3737import org.jetbrains.kotlinx.dataframe.impl.toSnakeCase
3838import org.jetbrains.kotlinx.dataframe.keywords.HardKeywords
3939import org.jetbrains.kotlinx.dataframe.keywords.ModifierKeywords
40+ import org.jetbrains.kotlinx.dataframe.keywords.SoftKeywords
4041import org.jetbrains.kotlinx.dataframe.schema.ComparisonMode
4142import org.jetbrains.kotlinx.dataframe.schema.DataFrameSchema
4243import kotlin.reflect.KClass
@@ -71,12 +72,15 @@ internal fun String.needsQuoting(): Boolean =
7172 isBlank() ||
7273 first().isDigit() ||
7374 contains(charsToQuote) ||
74- HardKeywords . VALUES .contains(this ) ||
75- ModifierKeywords . VALUES .contains(this ) ||
75+ hardKeywords .contains(this ) ||
76+ modifierKeywordsToQuote .contains(this ) ||
7677 all { it == ' _' } ||
7778 any { it != ' _' && it.category !in letterCategories }
7879 }
7980
81+ private val hardKeywords: Set <String > = HardKeywords .VALUES .toSet()
82+ private val modifierKeywordsToQuote: Set <String > = ModifierKeywords .VALUES .toSet() - SoftKeywords .VALUES .toSet()
83+
8084public fun String.isQuoted (): Boolean = startsWith(" `" ) && endsWith(" `" )
8185
8286public fun String.quoteIfNeeded (): String = if (needsQuoting()) " `$this `" else this
Original file line number Diff line number Diff line change @@ -196,6 +196,20 @@ class CodeGenerationTests : BaseTest() {
196196 assertEquals(expected, code.value)
197197 }
198198
199+ @Test
200+ fun `generateDataClasses with SoftKeywords` () {
201+ val df = dataFrameOf(" value" to columnOf(123 ))
202+ val code = df.generateDataClasses()
203+ val expected =
204+ """
205+ @DataSchema
206+ data class DataEntry(
207+ val value: Int
208+ )
209+ """ .trimIndent()
210+ assertEquals(expected, code.value)
211+ }
212+
199213 val personClassName = Person ::class .qualifiedName!!
200214
201215 val personShortName = Person ::class .simpleName!!
You can’t perform that action at this time.
0 commit comments