Skip to content

Commit 1190d8f

Browse files
committed
move queue processing to other class
1 parent 6ea3df4 commit 1190d8f

File tree

4 files changed

+5
-11
lines changed

4 files changed

+5
-11
lines changed

core/src/main/kotlin/com/fractalwrench/json2kotlin/JsonNames.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package com.fractalwrench.json2kotlin
22

3-
import com.google.gson.JsonElement
43

54
// TODO move to a symbol pool class (or equivalent)
65

7-
internal fun nameForArrayField(sanitisedName: String) = "${sanitisedName}Array"
8-
9-
internal fun nameForObjectInArray(it: IndexedValue<JsonElement>, sanitisedName: String): String {
10-
return if (it.index > 0) "$sanitisedName${it.index + 1}" else sanitisedName
11-
}
12-
6+
internal fun nameForArrayField(index: Int, identifier: String): String =
7+
if (index == 0) identifier else "$identifier${index + 1}"
138

149
// TODO move to a symbol pool class (or equivalent)
1510

core/src/main/kotlin/com/fractalwrench/json2kotlin/JsonProcessor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ internal class JsonProcessor { // TODO crappy name
8282
with(it.value) {
8383
when {
8484
isJsonPrimitive -> arrayTypes.add(typeForJsonPrimitive(asJsonPrimitive))
85-
isJsonArray -> arrayTypes.add(typeForJsonArray(asJsonArray, nameForArrayField(sanitisedName)))
86-
isJsonObject -> arrayTypes.add(typeForJsonObject(asJsonObject, nameForObjectInArray(it, sanitisedName)))
85+
isJsonArray -> arrayTypes.add(typeForJsonArray(asJsonArray, nameForArrayField(it.index, sanitisedName)))
86+
isJsonObject -> arrayTypes.add(typeForJsonObject(asJsonObject, nameForArrayField(it.index, sanitisedName)))
8787
isJsonNull -> nullable = true
8888
else -> throw IllegalStateException("Unexpected state in array")
8989
}

core/src/main/kotlin/com/fractalwrench/json2kotlin/JsonReader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class JsonReader(private val jsonParser: JsonParser) {
2828
* Adds an object as root which wraps the array
2929
*/
3030
private fun addRootWrapper(jsonArray: JsonArray, className: String): JsonObject {
31-
return JsonObject().apply { add(nameForArrayField(className).decapitalize(), jsonArray) }
31+
return JsonObject().apply { add(nameForArrayField(0, "${className}Array").decapitalize(), jsonArray) }
3232
}
3333

3434
}

core/src/main/kotlin/com/fractalwrench/json2kotlin/ReverseJsonTreeTraverser.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,4 @@ internal class ReverseJsonTreeTraverser {
6161

6262
private fun shouldAddToStack(element: JsonElement) = element.isJsonArray || element.isJsonObject
6363

64-
6564
}

0 commit comments

Comments
 (0)