Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Fix asKotlin extension function to just working with fqName #130

Merged
merged 5 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions arrow-meta/src/main/java/arrow/meta/encoder/jvm/JvmMetaApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,14 @@ interface JvmMetaApi : MetaApi, TypeElementEncoder, ProcessorUtils, TypeDecoder
/**
* @see [MetaApi.asKotlin]
*/
override fun TypeName.Classy.asKotlin(): TypeName.Classy =
if (simpleName == "Iterable") copy(simpleName = simpleName.asKotlin(), fqName = fqName.asKotlin(), pckg = PackageName("kotlin.collections"))
else copy(simpleName = simpleName.asKotlin(), fqName = fqName.asKotlin(), pckg = PackageName(pckg.value.asKotlin()))
override fun TypeName.Classy.asKotlin(): TypeName.Classy {
val fqNameAsKotlin = fqName.asKotlin()
return copy(
fqName = fqNameAsKotlin,
simpleName = fqNameAsKotlin.substringAfterLast("."),
pckg = PackageName(fqNameAsKotlin.substringBeforeLast("."))
)
}

/**
* @see [MetaApi.asPlatform]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ interface KotlinPoetEncoder {
annotations = annotations.map { it.toMeta() }
)

private fun com.squareup.kotlinpoet.ClassName.toMeta(): TypeName.Classy =
TypeName.Classy(
simpleName = simpleName.asKotlin(),
fqName = canonicalName.asKotlin(),
private fun com.squareup.kotlinpoet.ClassName.toMeta(): TypeName.Classy {
val fqNameAsKotlin = canonicalName.asKotlin()
return TypeName.Classy(
fqName = fqNameAsKotlin,
simpleName = fqNameAsKotlin.substringAfterLast("."),
pckg = PackageName(fqNameAsKotlin.substringBeforeLast(".")),
annotations = annotations.map { it.toMeta() },
nullable = isNullable,
pckg = PackageName(packageName.asKotlin())
nullable = isNullable
)
}

private fun com.squareup.kotlinpoet.ParameterizedTypeName.toMeta(): TypeName =
TypeName.ParameterizedType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ fun String.asKotlin(): String =
.replace("java.util.SortedMap", "kotlin.collections.SortedMap")
.replace("java.util.Collection", "kotlin.collections.Collection")
.replace("java.lang.Number", "kotlin.Number")
.replace("java.lang.Throwable", "kotlin.Throwable").let {
if (it == "java.lang") it.replace("java.lang", "kotlin")
else it
}.let {
if (it == "java.util") it.replace("java.util", "kotlin.collections")
else it
}
.replace("java.lang.Comparable", "kotlin.Comparable")
.replace("java.lang.Boolean", "kotlin.Boolean")
.replace("java.lang.Long", "kotlin.Long")
.replace("java.lang.Throwable", "kotlin.Throwable")
.replace("kotlin.Integer", "kotlin.Int")
.replace("Integer", "Int")
hadilq marked this conversation as resolved.
Show resolved Hide resolved
.replace("java.lang.String", "kotlin.String")
Expand Down