File tree Expand file tree Collapse file tree 2 files changed +53
-1
lines changed
main/kotlin/io/mcarle/konvert/processor/codegen
test/kotlin/io/mcarle/konvert/processor Expand file tree Collapse file tree 2 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -182,7 +182,7 @@ $className(${"⇥\n%L"}
182182 valueParamHasDefault = true
183183 )
184184 if (convertedValue != null ) {
185- CodeBlock .of(" $targetVarName .${sourceProperty.targetName} ·=·$convertedValue " )
185+ CodeBlock .of(" $targetVarName .${sourceProperty.targetName} ·=·%L " , convertedValue )
186186 } else {
187187 null
188188 }
Original file line number Diff line number Diff line change @@ -923,4 +923,56 @@ data class TargetClass(val property: Int)
923923 assertContains(compilationResult.messages, NoMatchingTypeConverterException ::class .qualifiedName!! )
924924 }
925925
926+ @Test
927+ fun emptyConstructorPropertiesDifferentPackage () {
928+ val (compilation) = compileWith(
929+ enabledConverters = listOf (SameTypeConverter ()),
930+ code = arrayOf(
931+ SourceFile .kotlin(
932+ name = " a/SourceClass.kt" ,
933+ contents =
934+ """
935+ package a
936+
937+ import io.mcarle.konvert.api.KonvertTo
938+ import io.mcarle.konvert.processor.SomeTestClass
939+ import b.TargetClass
940+
941+ @KonvertTo(TargetClass::class)
942+ data class SourceClass(val property: SomeTestClass)
943+ """ .trimIndent()
944+ ),
945+ SourceFile .kotlin(
946+ name = " b/TargetClass.kt" ,
947+ contents =
948+ """
949+ package b
950+
951+ import io.mcarle.konvert.processor.SomeOtherTestClass
952+
953+ class TargetClass {
954+ var property: SomeOtherTestClass? = null
955+ }
956+ """ .trimIndent()
957+ ),
958+ )
959+ )
960+ val extensionFunctionCode = compilation.generatedSourceFor(" SourceClassKonverter.kt" )
961+ println (extensionFunctionCode)
962+
963+ assertSourceEquals(
964+ """
965+ package a
966+
967+ import b.TargetClass
968+ import io.mcarle.konvert.processor.toSomeOtherTestClass
969+
970+ public fun SourceClass.toTargetClass(): TargetClass = TargetClass().also { targetClass ->
971+ targetClass.property = property.toSomeOtherTestClass()
972+ }
973+ """ .trimIndent(),
974+ extensionFunctionCode
975+ )
976+ }
977+
926978}
You can’t perform that action at this time.
0 commit comments