Skip to content

Commit 20fd516

Browse files
authored
Merge pull request #104 from wuseal/revert-102-3.0
Revert "clean up"
2 parents 535a157 + a281628 commit 20fd516

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+362
-164
lines changed

src/main/kotlin/extensions/ExtensionsCollector.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ object ExtensionsCollector {
1010
/**
1111
* all extensions
1212
*/
13-
val extensions = listOf(
13+
val extensions = listOf<Extension>(
1414
PropertyPrefixSupport,
1515
PropertySuffixSupport
1616
)
17-
}
17+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class JsonToKotlinApplication : ApplicationComponent {
1818

1919
LogUtil.i("init JSON To Kotlin Class version ==$PLUGIN_VERSION")
2020

21-
Thread {
21+
Thread() {
2222
try {
2323
sendConfigInfo()
2424
sendHistoryExceptionInfo()

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ class KotlinDataClassCodeMaker( private val rootClassName: String, private val j
2525
val kotlinDataClasses = KotlinDataClassMaker(rootClassName = rootClassName, json = json).makeKotlinDataClasses()
2626

2727
val interceptedDataClasses = kotlinDataClasses.map {it.applyInterceptors(interceptors)}
28-
return interceptedDataClasses.joinToString("\n\n") {
28+
val code = interceptedDataClasses.joinToString("\n\n") {
2929
it.getCode()
3030
}
31+
return code
3132
}
32-
}
33+
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
5656
inputDialog.show()
5757
val className = inputDialog.getClassName()
5858
val inputString = inputDialog.inputString
59-
val json = if (inputString.startsWith("http")) {
59+
val json = if (inputString?.startsWith("http") == true) {
6060
URL(inputString).readText()
6161
} else inputString
62-
if (json.isEmpty()) {
62+
if (json == null || json.isEmpty()) {
6363
return
6464
}
6565
jsonString = json
@@ -179,7 +179,9 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
179179

180180
fun getCleanText(editorText: String): String {
181181
val tempCleanText = editorText.substringBeforeLast("class")
182-
return if (tempCleanText.trim().endsWith("data")) tempCleanText.trim().removeSuffix("data") else tempCleanText
182+
val cleanText =
183+
if (tempCleanText.trim().endsWith("data")) tempCleanText.trim().removeSuffix("data") else tempCleanText
184+
return cleanText
183185
}
184186

185187
fun getCurrentEditFileTemClassName(editorText: String) = editorText.substringAfterLast("class")
@@ -207,7 +209,7 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
207209
)
208210
&& removeDocCommentAndPackageDeclareText.indexOf("class") != -1
209211
&& removeDocCommentAndPackageDeclareText.substringAfter("class").substringAfter("(")
210-
.replace(Regex("\\s"), "").let { it == ")" || it == "){}" })
212+
.replace(Regex("\\s"), "").let { it.equals(")") || it.equals("){}") })
211213
) {
212214
couldGetAndReuseClassNameInCurrentEditFileForInsertCode = true
213215
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ class TargetJsonElement : ITargetJsonElement {
8585
}
8686

8787
private fun getArrayChildElement(jsonArray: JsonArray): JsonElement {
88-
return if (jsonArray.size() >= 1) {
89-
getFullFieldElementFromArrayElement(jsonArray)
88+
if (jsonArray.size() >= 1) {
89+
return getFullFieldElementFromArrayElement(jsonArray)
9090
} else {
91-
Gson().toJsonTree(Any())
91+
return Gson().toJsonTree(Any())
9292
}
9393
}
9494

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import wu.seal.jsontokotlin.utils.numberOf
66
data class Annotation(val annotationTemplate: String, val rawName: String) {
77

88
fun getAnnotationString(): String {
9-
return if (annotationTemplate.contains("%s")) {
9+
if (annotationTemplate.contains("%s")) {
1010
val countS = annotationTemplate.numberOf("%s")
11-
val args = Array(countS) { rawName }
12-
annotationTemplate.format(*args)
11+
val args = Array(countS, { rawName })
12+
return annotationTemplate.format(*args)
1313
} else {
14-
annotationTemplate
14+
return annotationTemplate
1515
}
1616
}
1717

@@ -22,16 +22,16 @@ data class Annotation(val annotationTemplate: String, val rawName: String) {
2222
throw IllegalArgumentException("Only support one line annotation!! current is $annotationString")
2323
}
2424

25-
return if (annotationString.contains("\"")) {
25+
if (annotationString.contains("\"")) {
2626
if (annotationString.numberOf("\"") != 2) {
2727
throw IllegalArgumentException("Only support one line annotation with one couple Double quotes!! current is $annotationString")
2828
}
2929
val rawName = annotationString.substringAfter("\"").substringBefore("\"")
3030
val annotationTemplate =
31-
annotationString.substringBefore("\"") + "\"%s\"" + annotationString.substringAfterLast("\"")
32-
Annotation(annotationTemplate, rawName)
31+
annotationString.substringBefore("\"") + "\"%s\"" + annotationString.substringAfterLast("\"")
32+
return Annotation(annotationTemplate, rawName)
3333
} else {
34-
Annotation(annotationString, "")
34+
return Annotation(annotationString, "")
3535
}
3636

3737
}
@@ -64,4 +64,4 @@ data class Annotation(val annotationTemplate: String, val rawName: String) {
6464

6565
}
6666
}
67-
}
67+
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ data class KotlinDataClass(
1818
val indent = getIndent()
1919
val code = buildString {
2020
if (annotations.isNotEmpty()) {
21-
val annotationsCode = annotations.joinToString("\n") { it.getAnnotationString() }
21+
val annotationsCode = annotations.map { it.getAnnotationString() }.joinToString("\n")
2222
if (annotationsCode.isNotBlank()) {
2323
append(annotationsCode).append("\n")
2424
}
@@ -46,16 +46,16 @@ data class KotlinDataClass(
4646
append("}")
4747
}
4848
}
49-
return if (extraIndent.isNotEmpty()) {
50-
code.split("\n").map {
49+
if (extraIndent.isNotEmpty()) {
50+
return code.split("\n").map {
5151
if (it.isNotBlank()) {
5252
extraIndent + it
5353
} else {
5454
it
5555
}
5656
}.joinToString("\n")
5757
} else {
58-
code
58+
return code
5959
}
6060
}
6161

@@ -99,4 +99,4 @@ data class KotlinDataClass(
9999

100100
}
101101

102-
}
102+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ data class Property(
1616

1717
fun getCode(): String {
1818

19-
return buildString {
19+
val code = buildString {
2020
if (annotations.isNotEmpty()) {
2121
val annotationsCode = annotations.map { it.getAnnotationString() }.joinToString("\n")
2222
if (annotationsCode.isNotBlank()) {
@@ -28,6 +28,7 @@ data class Property(
2828
append(" = ").append(value)
2929
}
3030
}
31+
return code
3132
}
3233

3334
fun toParsedProperty(): ParsedKotlinDataClass.Property {
@@ -76,4 +77,4 @@ data class Property(
7677
)
7778
}
7879
}
79-
}
80+
}

src/main/kotlin/wu/seal/jsontokotlin/codeannotations/LoganSquarePropertyAnnotationTemplate.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class LoganSquarePropertyAnnotationTemplate(val rawName: String) : AnnotationTem
1212
}
1313

1414
override fun getAnnotations(): List<Annotation> {
15-
return listOf(annotation)
15+
return listOf<Annotation>(annotation)
1616
}
17-
}
17+
}

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,26 @@ import wu.seal.jsontokotlin.utils.*
88
*/
99

1010
fun getDefaultValue(propertyType: String): String {
11+
1112
val rawType = getRawType(propertyType)
1213

13-
return when {
14-
rawType == TYPE_INT -> 0.toString()
15-
rawType == TYPE_LONG -> 0L.toString()
16-
rawType == TYPE_STRING -> "\"\""
17-
rawType == TYPE_DOUBLE -> 0.0.toString()
18-
rawType == TYPE_BOOLEAN -> false.toString()
19-
rawType.contains("List<") -> "listOf()"
20-
rawType.contains("Map<") -> "mapOf()"
21-
rawType == TYPE_ANY -> "Any()"
22-
else -> "$rawType()"
14+
if (rawType == TYPE_INT) {
15+
return 0.toString()
16+
} else if (rawType == TYPE_LONG) {
17+
return 0L.toString()
18+
} else if (rawType == TYPE_STRING) {
19+
return "\"\""
20+
} else if (rawType == TYPE_DOUBLE) {
21+
return 0.0.toString()
22+
} else if (rawType == TYPE_BOOLEAN) {
23+
return false.toString()
24+
} else if (rawType.contains("List<")) {
25+
return "listOf()"
26+
} else if (rawType.contains("Map<")) {
27+
return "mapOf()"
28+
} else if (rawType == TYPE_ANY) {
29+
return "Any()"
30+
} else {
31+
return "$rawType()"
2332
}
2433
}

0 commit comments

Comments
 (0)