-
-
Save PaulWoitaschek/3441b731a51ab6350dface411c2bfd7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun generateIosFlow( | |
declaration: KSDeclaration, | |
): FunSpec? { | |
val returnType = when (declaration) { | |
is KSFunctionDeclaration -> { | |
declaration.returnType | |
} | |
is KSPropertyDeclaration -> { | |
declaration.getter?.returnType | |
} | |
else -> error("Unexpected declaration=$declaration") | |
} ?: return null | |
if (!declaration.isPublic()) return null | |
if (returnType.toString() != "Flow") return null | |
val classDeclaration = declaration.closestClassDeclaration() ?: return null | |
if (!classDeclaration.isPublic()) { | |
return null | |
} | |
val resolvedReturnType = returnType.resolve() | |
if (resolvedReturnType.declaration.qualifiedName?.asString() != "kotlinx.coroutines.flow.Flow") { | |
return null | |
} | |
val flowType = resolvedReturnType.arguments.single().type?.resolve() ?: return null | |
val nullableFlowType = flowType.isMarkedNullable | |
val iosFlowName = if (nullableFlowType) { | |
"NullableIOSFlow" | |
} else { | |
"IOSFlow" | |
} | |
val flowTypeName = try { | |
flowType.makeNotNullable().toTypeName() | |
} catch (e: NoSuchElementException) { | |
logger.info("Can't parse type", symbol = declaration) | |
return null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment