Skip to content

Commit 8a4e299

Browse files
committed
Fix iterable plugins
1 parent e9253ef commit 8a4e299

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tasks.wrapper {
1212
allprojects {
1313
group = "com.ucasoft.komm"
1414

15-
version = "2.2.20-0.28.7-RC1"
15+
version = "2.2.20-0.28.9-RC2"
1616

1717
repositories {
1818
mavenCentral()

komm-plugins-iterable/src/main/kotlin/com/ucasoft/komm/plugins/iterable/BaseIterablePlugin.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.ucasoft.komm.plugins.iterable
33
import com.google.devtools.ksp.getAllSuperTypes
44
import com.google.devtools.ksp.symbol.KSClassDeclaration
55
import com.google.devtools.ksp.symbol.KSDeclaration
6+
import com.google.devtools.ksp.symbol.KSName
67
import com.google.devtools.ksp.symbol.KSPropertyDeclaration
78
import com.google.devtools.ksp.symbol.KSType
89
import com.squareup.kotlinpoet.ClassName
@@ -28,6 +29,9 @@ abstract class BaseIterablePlugin: KOMMCastPlugin {
2829
return Pair(sourceIsNullable, destinationIsNullOrNullSubstitute)
2930
}
3031

31-
protected fun ClassName.isAssignableFrom(other: ClassName) =
32-
this == other || other.simpleName.endsWith(this.simpleName)
32+
protected fun KSName.isAssignableFrom(other: ClassName) =
33+
other.simpleName.endsWith(this.getShortName())
34+
35+
protected fun KSName.isAssignableFrom(other: String) =
36+
other.endsWith(this.getShortName())
3337
}

komm-plugins-iterable/src/main/kotlin/com/ucasoft/komm/plugins/iterable/IterablePlugin.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class IterablePlugin: BaseIterablePlugin() {
2121
val destinationParam = destinationType.arguments.first()
2222
val sourceParam = sourceType.arguments.first()
2323
val stringBuilder = StringBuilder(sourceName)
24-
var fromCastDeclaration = sourceType.toClassName()
24+
var fromCastDeclaration = sourceType.declaration.qualifiedName!!.getShortName()
2525
val (sourceIsNullable, destinationIsNullOrNullSubstitute) = parseMappingData(sourceType, sourceProperty, destinationType, destinationProperty)
2626
stringBuilder.append(addSafeNullCall(sourceIsNullable, safeCallOrNullAssertion(destinationIsNullOrNullSubstitute)))
2727
if (!destinationParam.type!!.resolve().isAssignableFrom(sourceParam.type!!.resolve())) {
2828
stringBuilder.append(".map{ it.to${destinationParam.type}() }")
29-
fromCastDeclaration = LIST
29+
fromCastDeclaration = LIST.simpleName
3030
}
31-
if (!destinationType.toClassName().isAssignableFrom(fromCastDeclaration)) {
32-
stringBuilder.append("${addSafeNullCall(sourceIsNullable && destinationIsNullOrNullSubstitute)}.to${destinationType.toClassName().simpleName}()")
31+
if (!destinationType.declaration.qualifiedName!!.isAssignableFrom(fromCastDeclaration)) {
32+
stringBuilder.append("${addSafeNullCall(sourceIsNullable && destinationIsNullOrNullSubstitute)}.to${destinationType.declaration.qualifiedName!!.getShortName()}()")
3333
}
3434
return stringBuilder.toString().trimEnd('?')
3535
}

komm-plugins-iterable/src/main/kotlin/com/ucasoft/komm/plugins/iterable/IterableStringPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class IterableStringPlugin: BaseIterablePlugin() {
3535
stringBuilder.append(")")
3636
} else {
3737
stringBuilder.append(".split(\"$delimiter\")")
38-
if (!destinationType.toClassName().isAssignableFrom(LIST)) {
39-
stringBuilder.append("${addSafeNullCall(sourceIsNullable && destinationIsNullOrNullSubstitute)}.to${destinationType.toClassName().simpleName}()")
38+
if (!destinationType.declaration.qualifiedName!!.isAssignableFrom(LIST)) {
39+
stringBuilder.append("${addSafeNullCall(sourceIsNullable && destinationIsNullOrNullSubstitute)}.to${destinationType.declaration.qualifiedName!!.getShortName()}()")
4040
}
4141
}
4242

komm-plugins-iterable/src/test/kotlin/com/ucasoft/komm/plugins/iterable/BaseIterablePluginTests.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ open class BaseIterablePluginTests {
3838
kType.toString().contains(".MutableList") -> MUTABLE_LIST.canonicalName
3939
else -> (kType.classifier as KClass<*>).qualifiedName!!
4040
}
41+
every { this@with.getShortName() } returns when {
42+
kType.toString().contains(".MutableList") -> MUTABLE_LIST.simpleName
43+
else -> (kType.classifier as KClass<*>).simpleName!!
44+
}
4145
this
4246
}
4347
this

0 commit comments

Comments
 (0)