File tree Expand file tree Collapse file tree 3 files changed +31
-3
lines changed
main/kotlin/wu/seal/jsontokotlin
test/kotlin/extensions/ted/zeng Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 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\n X" ," Int" ," 1" )
19+ kp.getPropertyStringBlock().should.equal(" val X\\ n\\ nX: Int" )
20+
21+ }
22+
23+
24+ }
You can’t perform that action at this time.
0 commit comments