Skip to content

Commit 5490fed

Browse files
committed
test and bugfix
1 parent 12310a3 commit 5490fed

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/CodeGeneratorImpl.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,19 @@ private val letterCategories = setOf(
5353
CharCategory.DECIMAL_DIGIT_NUMBER
5454
)
5555

56-
internal fun String.needsQuoting(): Boolean {
57-
return isBlank() ||
56+
internal fun String.needsQuoting(): Boolean =
57+
if (isQuoted()) false
58+
else isBlank() ||
5859
first().isDigit() ||
5960
contains(charsToQuote) ||
6061
HardKeywords.VALUES.contains(this) ||
6162
ModifierKeywords.VALUES.contains(this) ||
6263
all { it == '_' } ||
6364
any { it != '_' && it.category !in letterCategories }
64-
}
6565

66-
internal fun String.quoteIfNeeded() = if (needsQuoting()) "`$this`" else this
66+
public fun String.isQuoted(): Boolean = startsWith("`") && endsWith("`")
67+
68+
public fun String.quoteIfNeeded(): String = if (needsQuoting()) "`$this`" else this
6769

6870
internal fun List<Code>.join() = joinToString("\n")
6971

@@ -250,7 +252,7 @@ internal open class ExtensionsCodeGeneratorImpl(
250252
val markerName = marker.name
251253
val markerType = "$markerName${marker.typeArguments}"
252254
val visibility = renderTopLevelDeclarationVisibility(marker)
253-
val shortMarkerName = markerName.substring(markerName.lastIndexOf('.') + 1)
255+
val shortMarkerName = markerName.substring(markerName.lastIndexOf('.') + 1).removeQuotes()
254256
val nullableShortMarkerName = "Nullable$shortMarkerName"
255257

256258
fun String.toNullable() = if (this.last() == '?' || this == "*") this else "$this?"
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
package org.jetbrains.dataframe.ksp
22

33
import com.google.devtools.ksp.symbol.KSDeclaration
4+
import org.jetbrains.kotlinx.dataframe.impl.codeGen.quoteIfNeeded
45

5-
fun KSDeclaration.getQualifiedNameOrThrow(): String {
6-
return (qualifiedName ?: error("@DataSchema declaration ${simpleName.asString()} at $location must have qualified name")).asString()
7-
}
6+
fun KSDeclaration.getQualifiedNameOrThrow(): String =
7+
qualifiedName
8+
?.let {
9+
buildString {
10+
val qualifier = it.getQualifier()
11+
if (qualifier.isNotEmpty()) {
12+
for (it in qualifier.split('.')) {
13+
append(it.quoteIfNeeded() + '.')
14+
}
15+
}
16+
17+
append(it.getShortName().quoteIfNeeded())
18+
}
19+
}
20+
?: error("@DataSchema declaration ${simpleName.asString()} at $location must have qualified name")

plugins/symbol-processor/src/test/kotlin/org/jetbrains/dataframe/ksp/DataFrameSymbolProcessorTest.kt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,48 @@ class DataFrameSymbolProcessorTest {
3333
KspCompilationTestRunner.compilationDir.deleteRecursively()
3434
}
3535

36+
@Test
37+
fun `interface with backticked name`() {
38+
val result = KspCompilationTestRunner.compile(
39+
TestCompilationParameters(
40+
sources = listOf(
41+
SourceFile.kotlin(
42+
"MySources.kt",
43+
"""
44+
$imports
45+
46+
class OuterClass
47+
48+
@DataSchema(isOpen = false)
49+
interface `Hello Something` {
50+
val name: String
51+
val `test name`: NestedClass
52+
val nullableProperty: Int?
53+
val a: () -> Unit
54+
val d: List<List<*>>
55+
56+
class NestedClass
57+
}
58+
59+
val ColumnsContainer<`Hello Something`>.col1: DataColumn<String> get() = name
60+
val ColumnsContainer<`Hello Something`>.col2: DataColumn<`Hello Something`.NestedClass> get() = `test name`
61+
val ColumnsContainer<`Hello Something`>.col3: DataColumn<Int?> get() = nullableProperty
62+
val ColumnsContainer<`Hello Something`>.col4: DataColumn<() -> Unit> get() = a
63+
val ColumnsContainer<`Hello Something`>.col5: DataColumn<List<List<*>>> get() = d
64+
65+
val DataRow<`Hello Something`>.row1: String get() = name
66+
val DataRow<`Hello Something`>.row2: `Hello Something`.NestedClass get() = `test name`
67+
val DataRow<`Hello Something`>.row3: Int? get() = nullableProperty
68+
val DataRow<`Hello Something`>.row4: () -> Unit get() = a
69+
val DataRow<`Hello Something`>.row5: List<List<*>> get() = d
70+
""".trimIndent()
71+
)
72+
)
73+
)
74+
)
75+
result.successfulCompilation shouldBe true
76+
}
77+
3678
@Test
3779
fun `all interface`() {
3880
val result = KspCompilationTestRunner.compile(

0 commit comments

Comments
 (0)