diff --git a/build.gradle b/build.gradle index bb5bea8c..9fb02ded 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ buildscript { } plugins { - id "org.jetbrains.intellij" version "0.3.2" + id "org.jetbrains.intellij" version "0.4.9" } apply plugin: 'idea' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d93f2bc7..2fabf20e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon May 14 11:49:38 CST 2018 +#Sun Jul 21 15:52:28 CST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip diff --git a/src/main/kotlin/wu/seal/jsontokotlin/utils/KotlinDataClassFileGenerator.kt b/src/main/kotlin/wu/seal/jsontokotlin/utils/KotlinDataClassFileGenerator.kt index 888c51f0..8d24d178 100644 --- a/src/main/kotlin/wu/seal/jsontokotlin/utils/KotlinDataClassFileGenerator.kt +++ b/src/main/kotlin/wu/seal/jsontokotlin/utils/KotlinDataClassFileGenerator.kt @@ -170,25 +170,36 @@ class KotlinDataClassFileGenerator(private val interceptors: List): List { - val classNameList = classes.map { it.name } + val notBeenReferencedClass = mutableListOf().apply { + addAll(classes) + removeAt(0) + } - /** - * Build Property Type reference to ParsedKotlinDataClass - * Only pre class property type could reference behind classes - */ - classes.forEachIndexed { index, kotlinDataClass -> - kotlinDataClass.properties.forEachIndexed { _, property -> - val indexOfClassName = - classNameList.firstIndexAfterSpecificIndex(getRawType(getChildType(property.propertyType)), index) - if (indexOfClassName != -1) { - property.kotlinDataClassPropertyTypeRef = classes[indexOfClassName] - } - } + val classNameList = notBeenReferencedClass.map { it.name }.toMutableList() + + classes.forEach { + buildClassTypeReference(it, classNameList, notBeenReferencedClass) } return classes } + private fun buildClassTypeReference(tobeBuildTypeReferenceClass: ParsedKotlinDataClass, classNameList: MutableList, notBeenReferencedClass: MutableList) { + tobeBuildTypeReferenceClass.properties.forEach { property -> + val indexOfClassName = + classNameList.indexOf(getRawType(getChildType(property.propertyType))) + if (indexOfClassName != -1) { + val referencedClass = notBeenReferencedClass[indexOfClassName] + notBeenReferencedClass.remove(referencedClass) + classNameList.removeAt(indexOfClassName) + property.kotlinDataClassPropertyTypeRef = referencedClass + + buildClassTypeReference(referencedClass,classNameList,notBeenReferencedClass) + + } + } + } + private fun generateKotlinDataClassFile( fileName: String, packageDeclare: String, @@ -243,7 +254,7 @@ class KotlinDataClassFileGenerator(private val interceptors: List, className: String): String { var newClassName = className - var fileNamesInLowerCase = classesNames.map { it.toLowerCase() } + val fileNamesInLowerCase = classesNames.map { it.toLowerCase() } while (fileNamesInLowerCase.contains(newClassName.toLowerCase())) { newClassName += "X" }