Skip to content

Commit 3697eed

Browse files
Automated commit of generated code
1 parent 7dc2d41 commit 3697eed

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import kotlin.reflect.full.superclasses
2727
import kotlin.reflect.jvm.jvmErasure
2828
import kotlin.reflect.typeOf
2929
import kotlin.time.Instant
30+
import kotlin.uuid.Uuid
3031

3132
internal class ReplCodeGeneratorImpl : ReplCodeGenerator {
3233

@@ -120,24 +121,34 @@ internal class ReplCodeGeneratorImpl : ReplCodeGenerator {
120121
result.newMarkers.forEach {
121122
generatedMarkers[it.name] = it
122123
}
123-
return if (schema.hasExperimentalInstant()) {
124+
125+
val optIns = buildString {
126+
if (schema.hasExperimentalInstant()) appendLine("@file:OptIn(kotlin.time.ExperimentalTime::class)")
127+
if (schema.hasExperimentalUuid()) appendLine("@file:OptIn(kotlin.uuid.ExperimentalUuidApi::class)")
128+
}
129+
130+
return if (optIns.isNotEmpty()) {
124131
result.code.copy(
125-
declarations = "@file:OptIn(kotlin.time.ExperimentalTime::class)\n" + result.code.declarations,
132+
declarations = optIns + "\n" + result.code.declarations,
126133
)
127134
} else {
128135
result.code
129136
}
130137
}
131138

132-
private fun DataFrameSchema.hasExperimentalInstant(): Boolean =
139+
private fun DataFrameSchema.hasColumnOfType(type: KType): Boolean =
133140
columns.values.any { column ->
134141
when (column) {
135-
is ColumnSchema.Frame -> column.schema.hasExperimentalInstant()
136-
is ColumnSchema.Group -> column.schema.hasExperimentalInstant()
137-
is ColumnSchema.Value -> column.type.isSubtypeOf(typeOf<Instant?>())
142+
is ColumnSchema.Frame -> column.schema.hasColumnOfType(type)
143+
is ColumnSchema.Group -> column.schema.hasColumnOfType(type)
144+
is ColumnSchema.Value -> column.type.isSubtypeOf(type)
138145
}
139146
}
140147

148+
private fun DataFrameSchema.hasExperimentalInstant(): Boolean = hasColumnOfType(typeOf<Instant?>())
149+
150+
private fun DataFrameSchema.hasExperimentalUuid(): Boolean = hasColumnOfType(typeOf<Uuid?>())
151+
141152
override fun process(markerClass: KClass<*>): Code {
142153
val newMarkers = mutableListOf<Marker>()
143154

0 commit comments

Comments
 (0)