Skip to content

Commit 3171953

Browse files
authored
Merge pull request #211 from TedZen/3.4.0-bugfix#198
bug fixed #198
2 parents 2ba7565 + 9873a97 commit 3171953

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/main/kotlin/wu/seal/jsontokotlin/classscodestruct/Property.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ data class Property(
3030
append(annotationsCode).append(separatorBetweenAnnotationAndProperty)
3131
}
3232
}
33-
append(keyword).append(" ").append(name).append(": ").append(type)
33+
append(keyword).append(" ")
34+
append(if (name.first().isDigit() || name.contains('$')) "`$name`" else name)
35+
append(": ").append(type)
3436
if (value.isNotBlank()) {
3537
append(" = ").append(value)
3638
}

src/main/kotlin/wu/seal/jsontokotlin/codeelements/KProperty.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ interface IProperty {
1717

1818
}
1919

20-
class KProperty(private val rawPropertyName: String, private val propertyType: String, private val propertyValue: String) : IProperty {
20+
class KProperty(rawPropertyName: String, private val propertyType: String, private val propertyValue: String) : IProperty {
21+
22+
private val noLinebreakPropertyName = rawPropertyName.replace("\n","\\n").take(255)
2123

2224
override fun getPropertyStringBlock(): String {
2325

2426
val blockBuilder = StringBuilder()
2527

26-
blockBuilder.append(NoneSupporter.getNoneLibSupporterProperty(rawPropertyName, propertyType))
28+
blockBuilder.append(NoneSupporter.getNoneLibSupporterProperty(noLinebreakPropertyName, propertyType))
2729

2830
return blockBuilder.toString()
2931
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package extensions.ted.zeng
2+
3+
import com.winterbe.expekt.should
4+
import org.junit.Before
5+
import org.junit.Test
6+
import wu.seal.jsontokotlin.ConfigManager
7+
import wu.seal.jsontokotlin.codeelements.KProperty
8+
import wu.seal.jsontokotlin.test.TestConfig
9+
10+
class BugTest198 {
11+
@Before
12+
fun setup(){
13+
TestConfig.isTestModel = true
14+
ConfigManager.indent = 0
15+
}
16+
@Test
17+
fun propertyNameCheck(){
18+
val kp = KProperty("X\n\nX","Int","1")
19+
kp.getPropertyStringBlock().should.equal("val X\\n\\nX: Int")
20+
21+
}
22+
23+
24+
}

0 commit comments

Comments
 (0)