From 2f708b90f5642a2dcf80ec17474b0fc7ac2ced39 Mon Sep 17 00:00:00 2001 From: hotchemi Date: Wed, 12 Dec 2018 19:56:28 +0900 Subject: [PATCH] Address https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/503. --- .../dispatcher/processor/util/Extensions.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/processor/src/main/kotlin/permissions/dispatcher/processor/util/Extensions.kt b/processor/src/main/kotlin/permissions/dispatcher/processor/util/Extensions.kt index 3f80292b..d9aeb60e 100644 --- a/processor/src/main/kotlin/permissions/dispatcher/processor/util/Extensions.kt +++ b/processor/src/main/kotlin/permissions/dispatcher/processor/util/Extensions.kt @@ -66,8 +66,9 @@ fun VariableElement.isNullable(): Boolean = fun VariableElement.asPreparedType(): TypeName = this.asType() .asTypeName() - .checkStringType() - .checkParameterStringType() + .correctStringType() + .correctParameterStringType() + .correctAnyType() .mapToNullableTypeIf(this.isNullable()) /** @@ -117,21 +118,27 @@ fun FileSpec.Builder.addTypes(types: List): FileSpec.Builder { * To avoid KotlinPoet bug that returns java.lang.String when type name is kotlin.String. * This method should be removed after addressing on KotlinPoet side. */ -fun TypeName.checkStringType() = +fun TypeName.correctStringType() = if (this.toString() == "java.lang.String") ClassName("kotlin", "String") else this /** * Convert [java.lang.String] to [kotlin.String] in a parameter. * ref: https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/427 */ -fun TypeName.checkParameterStringType(): TypeName { +fun TypeName.correctParameterStringType(): TypeName { if (this is ParameterizedTypeName) { - val typeArguments = this.typeArguments.map { it.checkStringType() }.toTypedArray() + val typeArguments = this.typeArguments.map { it.correctStringType() }.toTypedArray() return this.rawType.parameterizedBy(*typeArguments) } return this } +/** + * https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/545 + */ +fun TypeName.correctAnyType() = + if (this.toString() == "java.lang.Object") ClassName("kotlin", "Any") else this + /** * Returns this TypeName as nullable or non-nullable based on the given condition. */