Skip to content

Commit 758e6fa

Browse files
authored
Merge pull request #111 from kezhenxu94/master
polishing code
2 parents 1ac166c + 2839956 commit 758e6fa

File tree

13 files changed

+39
-47
lines changed

13 files changed

+39
-47
lines changed

src/main/kotlin/wu/seal/jsontokotlin/IConfigManager.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ interface IConfigManager {
9595
PropertiesComponent.getInstance().setValue(TARGET_JSON_CONVERTER_LIB_KEY, value.name)
9696
}
9797

98-
@Deprecated("Not use since Version 2.0")
99-
var isPropertyNullable: Boolean
100-
get() = PropertiesComponent.getInstance().isTrueValue(IS_PROPERTY_NULLABLE_KEY)
101-
set(value) = PropertiesComponent.getInstance().setValue(IS_PROPERTY_NULLABLE_KEY, value)
102-
10398
var propertyTypeStrategy: PropertyTypeStrategy
10499
get() = if (TestConfig.isTestModel) TestConfig.propertyTypeStrategy else PropertyTypeStrategy.valueOf(
105100
PropertiesComponent.getInstance().getValue(

src/main/kotlin/wu/seal/jsontokotlin/KotlinCodeMaker.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ class KotlinCodeMaker {
9696
stringBuilder.append(" {")
9797
stringBuilder.append("\n")
9898
val nestedClassCode = toBeAppend.joinToString("\n\n") {
99-
it.split("\n").joinToString("\n") {
100-
indent + it
99+
it.split("\n").joinToString("\n") { line ->
100+
indent + line
101101
}
102102
}
103103
stringBuilder.append(nestedClassCode)

src/main/kotlin/wu/seal/jsontokotlin/KotlinDataClassMaker.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ class KotlinDataClassMaker(private val rootClassName: String, private val json:
126126
newKotlinDataClass: ParsedKotlinDataClass
127127
) {
128128
classes.forEach {
129-
it.properties.forEach {
130-
if (it.kotlinDataClassPropertyTypeRef == originDataClass) {
131-
it.kotlinDataClassPropertyTypeRef = newKotlinDataClass
129+
it.properties.forEach { p ->
130+
if (p.kotlinDataClassPropertyTypeRef == originDataClass) {
131+
p.kotlinDataClassPropertyTypeRef = newKotlinDataClass
132132
}
133133
}
134134
}
@@ -140,17 +140,17 @@ class KotlinDataClassMaker(private val rootClassName: String, private val json:
140140
fun synchronizedPropertyTypeWithTypeRef(unSynchronizedTypeClasses: List<ParsedKotlinDataClass>): List<ParsedKotlinDataClass> {
141141
return unSynchronizedTypeClasses.map { dataClass: ParsedKotlinDataClass ->
142142

143-
val newProperties = dataClass.properties.map { it ->
144-
if (it.kotlinDataClassPropertyTypeRef != ParsedKotlinDataClass.NONE) {
145-
val rawPropertyReferenceType = getRawType(getChildType(it.propertyType))
143+
val newProperties = dataClass.properties.map { property ->
144+
if (property.kotlinDataClassPropertyTypeRef != ParsedKotlinDataClass.NONE) {
145+
val rawPropertyReferenceType = getRawType(getChildType(property.propertyType))
146146
val tobeReplaceNewType =
147-
it.propertyType.replace(rawPropertyReferenceType, it.kotlinDataClassPropertyTypeRef.name)
148-
if (it.propertyValue.isNotBlank()) {
149-
it.copy(propertyType = tobeReplaceNewType, propertyValue = getDefaultValue(tobeReplaceNewType))
147+
property.propertyType.replace(rawPropertyReferenceType, property.kotlinDataClassPropertyTypeRef.name)
148+
if (property.propertyValue.isNotBlank()) {
149+
property.copy(propertyType = tobeReplaceNewType, propertyValue = getDefaultValue(tobeReplaceNewType))
150150
} else
151-
it.copy(propertyType = tobeReplaceNewType)
151+
property.copy(propertyType = tobeReplaceNewType)
152152
} else {
153-
it
153+
property
154154
}
155155
}
156156
dataClass.copy(properties = newProperties)
@@ -188,4 +188,4 @@ class KotlinDataClassMaker(private val rootClassName: String, private val json:
188188
return newClassName
189189
}
190190

191-
}
191+
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ data class KotlinDataClass(
2828
} else {
2929
append("data class ").append(name).append("(").append("\n")
3030
}
31-
properties.forEach {
32-
val code = it.getCode()
31+
properties.forEach { p ->
32+
val code = p.getCode()
3333
val addIndentCode = code.split("\n").joinToString("\n") { indent + it }
3434
append(addIndentCode)
35-
if (it.isLast.not()) append(",")
36-
if (it.comment.isNotBlank()) append(" // ").append(getCommentCode(it.comment))
35+
if (p.isLast.not()) append(",")
36+
if (p.comment.isNotBlank()) append(" // ").append(getCommentCode(p.comment))
3737
append("\n")
3838
}
3939
append(")")
@@ -51,13 +51,13 @@ data class KotlinDataClass(
5151
}
5252
}
5353
return if (extraIndent.isNotEmpty()) {
54-
code.split("\n").map {
54+
code.split("\n").joinToString("\n") {
5555
if (it.isNotBlank()) {
5656
extraIndent + it
5757
} else {
5858
it
5959
}
60-
}.joinToString("\n")
60+
}
6161
} else {
6262
code
6363
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ data class Property(
1818

1919
return buildString {
2020
if (annotations.isNotEmpty()) {
21-
val annotationsCode = annotations.map { it.getAnnotationString() }.joinToString("\n")
21+
val annotationsCode = annotations.joinToString("\n") { it.getAnnotationString() }
2222
if (annotationsCode.isNotBlank()) {
2323
append(annotationsCode).append("\n")
2424
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ abstract class KName : IKName {
2222
)
2323

2424

25-
protected val illegalCharacter = listOf<String>(
25+
protected val illegalCharacter = listOf(
2626
"\\+", "\\-", "\\*", "/", "%", "=", "&", "\\|", "!", "\\[", "\\]", "\\{", "\\}", "\\(", "\\)", "\\\\", "\"", "_"
2727
, ",", "\\.", ":", "\\?", "\\>", "\\<", "@", ";", "'", "\\`", "\\~", "\\$", "\\^", "#", "\\", "/", " ", "\t", "\n"
2828
)
2929

3030

31-
protected val nameSeparator = listOf<String>(" ", "_", "\\-", ":")
31+
protected val nameSeparator = listOf(" ", "_", "\\-", ":")
3232

3333

3434
/**
3535
* remove the start number or whiteSpace characters in this string
3636
*/
3737
protected fun removeStartNumberAndIllegalCharacter(it: String): String {
3838

39-
val numberAndIllegalCharacters = listOf<String>(*illegalCharacter.toTypedArray(), "\\d")
39+
val numberAndIllegalCharacters = listOf(*illegalCharacter.toTypedArray(), "\\d")
4040

4141
val firstNumberAndIllegalCharactersRegex = "^(${numberAndIllegalCharacters.toRegex()})+".toRegex()
4242

src/main/kotlin/wu/seal/jsontokotlin/interceptor/MinimalAnnotationKotlinDataClassInterceptor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import wu.seal.jsontokotlin.classscodestruct.KotlinDataClass
1010
class MinimalAnnotationKotlinDataClassInterceptor : IKotlinDataClassInterceptor {
1111

1212
override fun intercept(kotlinDataClass: KotlinDataClass): KotlinDataClass {
13-
val newProperties = kotlinDataClass.properties.map {
14-
if (it.originName == it.name) {
15-
it.copy(annotations = it.annotations.filter { it.rawName.isBlank() })
13+
val newProperties = kotlinDataClass.properties.map { p ->
14+
if (p.originName == p.name) {
15+
p.copy(annotations = p.annotations.filter { it.rawName.isBlank() })
1616
} else {
17-
it
17+
p
1818
}
1919
}
2020

src/main/kotlin/wu/seal/jsontokotlin/ui/JsonInputDialog.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package wu.seal.jsontokotlin.ui
22

33
import com.google.gson.*
44
import com.intellij.json.JsonFileType
5-
import com.intellij.openapi.application.Application
65
import com.intellij.openapi.application.ApplicationManager
76
import com.intellij.openapi.editor.Editor
87
import com.intellij.openapi.editor.EditorFactory

src/main/kotlin/wu/seal/jsontokotlin/utils/KotlinDataClassFileGenerator.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ class KotlinDataClassFileGenerator(private val interceptors: List<IKotlinDataCla
151151
newKotlinDataClass: ParsedKotlinDataClass
152152
) {
153153
classes.forEach {
154-
it.properties.forEach {
155-
if (it.kotlinDataClassPropertyTypeRef == originDataClass) {
156-
it.kotlinDataClassPropertyTypeRef = newKotlinDataClass
154+
it.properties.forEach { p ->
155+
if (p.kotlinDataClassPropertyTypeRef == originDataClass) {
156+
p.kotlinDataClassPropertyTypeRef = newKotlinDataClass
157157
}
158158
}
159159
}

src/main/kotlin/wu/seal/jsontokotlin/utils/classblockparse/ClassCodeParser.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ class ClassCodeParser(private val classBlockString: String) {
156156
private fun getPropertyValue(propertyLine: String, isLastLine: Boolean): String {
157157
val deleteCommentPropertyLine = propertyLine.substringBefore("//")
158158
val typeAndValueBlock = deleteCommentPropertyLine.substringAfterLast(":")
159-
if (typeAndValueBlock.contains("=")) {
159+
return if (typeAndValueBlock.contains("=")) {
160160
val propertyValuePre = typeAndValueBlock.split("=")[1]
161-
return if (isLastLine) {
161+
if (isLastLine) {
162162
propertyValuePre.trim()
163163
} else {
164164
propertyValuePre.trim().dropLast(1)
165165
}
166166
} else {
167-
return ""
167+
""
168168
}
169169

170170
}

0 commit comments

Comments
 (0)