Skip to content

Instantly share code, notes, and snippets.

@dilrajsingh1997
Last active November 21, 2021 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dilrajsingh1997/70a4cac1f808ab23fd7585fbafa3b90a to your computer and use it in GitHub Desktop.
Save dilrajsingh1997/70a4cac1f808ab23fd7585fbafa3b90a to your computer and use it in GitHub Desktop.
file addLine "val argumentList"
file addPhrase ": MutableList<NamedNavArgument> "
tabs ++
file addLine "get() = mutableListOf("
count = 0
properties.forEach { property ->
count ++
val argumentName = property.simpleName.asString()
val resolvedType: KSType = property.type.resolve()
fun getElementNavType(): String {
return try {
when (resolver.getClassDeclarationByName(resolvedType.declaration.qualifiedName!!)
?.toString()) {
"Boolean" -> "NavType.BoolType"
"String" -> "NavType.StringType"
"Float" -> "NavType.FloatType"
"Int" -> "NavType.IntType"
"Long" -> "NavType.LongType"
else -> {
logger.error("complex data types not yet supported", property)
""
}
}
} catch (e: Exception) {
""
}
}
tabs ++
file addLine "navArgument(\"$argumentName\") {"
tabs ++
file addLine "type = ${getElementNavType()}"
tabs --
file addLine "},"
tabs --
argumentString += "$argumentName={$argumentName}"
if (count != propertyCount) {
argumentString += ","
}
}
file addLine ")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment