-
-
Save dilrajsingh1997/6392f8e0aefd37dee6c7850b5454992e 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
file addLine "fun parseArguments(backStackEntry: NavBackStackEntry): $dataClassName {" | |
tabs++ | |
file addLine "return " | |
file addPhrase "$dataClassName(" | |
tabs++ | |
properties.forEach { property -> | |
val argumentName = property.simpleName.asString() | |
val resolvedType: KSType = property.type.resolve() | |
fun getParsedElement(): String { | |
return try { | |
when (resolver.getClassDeclarationByName(resolvedType.declaration.qualifiedName!!) | |
?.toString()) { | |
"Boolean" -> "backStackEntry.arguments?.getBoolean(\"$argumentName\") ?: false | |
"String" -> "backStackEntry.arguments?.getString(\"$argumentName\") ?: \"\"" | |
"Float" -> "backStackEntry.arguments?.getFloat(\"$argumentName\") ?: 0F" | |
"Int" -> "backStackEntry.arguments?.getInt(\"$argumentName\") ?: 0" | |
"Long" -> "backStackEntry.arguments?.getLong(\"$argumentName\") ?: 0L" | |
else -> { | |
logger.error("complex data types not yet supported", property) | |
"" | |
} | |
} | |
} catch (e: Exception) { | |
"" | |
} | |
} | |
file addLine "$argumentName = ${getParsedElement()}" | |
file addPhrase ", " | |
} | |
tabs-- | |
file addLine ")" | |
tabs-- | |
file addLine "}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment