Skip to content

Commit

Permalink
Merge pull request #201 from wuseal/3.4.0-bugfix/#193
Browse files Browse the repository at this point in the history
3.4.0 bugfix/#193
  • Loading branch information
wuseal authored Jul 21, 2019
2 parents d444119 + 0e596ef commit 074e94c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -170,25 +170,36 @@ class KotlinDataClassFileGenerator(private val interceptors: List<IKotlinDataCla
}

fun buildTypeReference(classes: List<ParsedKotlinDataClass>): List<ParsedKotlinDataClass> {
val classNameList = classes.map { it.name }
val notBeenReferencedClass = mutableListOf<ParsedKotlinDataClass>().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<String>, notBeenReferencedClass: MutableList<ParsedKotlinDataClass>) {
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,
Expand Down Expand Up @@ -243,7 +254,7 @@ class KotlinDataClassFileGenerator(private val interceptors: List<IKotlinDataCla
private fun changeClassNameIfCurrentListContains(classesNames: List<String>, 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"
}
Expand Down

0 comments on commit 074e94c

Please sign in to comment.