Skip to content

Commit

Permalink
Fixes #625
Browse files Browse the repository at this point in the history
  • Loading branch information
raamcosta committed May 4, 2024
1 parent 4553d7b commit 66b866a
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,25 @@ internal data class RawNavGraphTree(
internal val setOfPublicStartParticipatingTypes = mutableSetOf<Importable>()

internal fun makeNavGraphTrees(
navGraphs: List<RawNavGraphGenParams>,
customNavGraphs: List<RawNavGraphGenParams>,
generatedDestinations: List<CodeGenProcessedDestination>
): List<RawNavGraphTree> {
val navGraphsByType = (navGraphs + rootNavGraphGenParams).associateBy { it.annotationType }
val allNavGraphs = customNavGraphs + rootNavGraphGenParams
val navGraphsByType: Map<Importable, RawNavGraphGenParams> = allNavGraphs.associateBy { it.annotationType }

val destinationsByNavGraphParams: Map<RawNavGraphGenParams, List<CodeGenProcessedDestination>> =
val destinationsByParent: Map<RawNavGraphGenParams, List<CodeGenProcessedDestination>> =
generatedDestinations.filter { it.navGraphInfo != null }.groupBy { destination ->
navGraphsByType[destination.navGraphInfo!!.graphType]!!
}

val rawNavGraphGenByParent: Map<Importable?, List<RawNavGraphGenParams>> =
destinationsByNavGraphParams.keys.groupBy { it.parent }
allNavGraphs.groupBy { it.parent }

return (navGraphs + destinationsByNavGraphParams.keys).toSet()
.filter { it.parent == null }
.map {
val topLevelGraphs = rawNavGraphGenByParent[null].orEmpty()

return topLevelGraphs.mapNotNull {
it.makeGraphTree(
destinationsByNavGraphParams,
destinationsByParent,
rawNavGraphGenByParent,
)
}
Expand All @@ -88,11 +89,15 @@ internal fun makeNavGraphTrees(
internal fun RawNavGraphGenParams.makeGraphTree(
destinationsByNavGraphParams: Map<RawNavGraphGenParams, List<CodeGenProcessedDestination>>,
navGraphsByParentType: Map<Importable?, List<RawNavGraphGenParams>>
): RawNavGraphTree {
): RawNavGraphTree? {
val destinations = destinationsByNavGraphParams[this].orEmpty()
val nestedNavGraphs = navGraphsByParentType[annotationType].orEmpty()

val nestedGraphs = nestedNavGraphs.map {
if (destinations.isEmpty() && nestedNavGraphs.isEmpty()) {
return null
}

val nestedGraphs = nestedNavGraphs.mapNotNull {
it.makeGraphTree(destinationsByNavGraphParams, navGraphsByParentType)
}

Expand Down

0 comments on commit 66b866a

Please sign in to comment.