Skip to content

Commit

Permalink
Merge branch 'raamcosta:main' into ksp2
Browse files Browse the repository at this point in the history
  • Loading branch information
FooIbar authored Oct 26, 2024
2 parents 4cea2e7 + 0920105 commit 3549d53
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ramcosta.composedestinations.codegen

import com.ramcosta.composedestinations.codegen.commons.RESULT_BACK_NAVIGATOR_QUALIFIED_NAME
import com.ramcosta.composedestinations.codegen.commons.firstTypeInfoArg
import com.ramcosta.composedestinations.codegen.commons.isCustomArrayOrArrayListTypeNavArg
import com.ramcosta.composedestinations.codegen.facades.CodeOutputStreamMaker
Expand All @@ -11,6 +12,8 @@ import com.ramcosta.composedestinations.codegen.model.NavTypeSerializer
import com.ramcosta.composedestinations.codegen.model.RawDestinationGenParams
import com.ramcosta.composedestinations.codegen.model.RawNavGraphGenParams
import com.ramcosta.composedestinations.codegen.model.SubModuleInfo
import com.ramcosta.composedestinations.codegen.model.TypeArgument
import com.ramcosta.composedestinations.codegen.model.TypeInfo
import com.ramcosta.composedestinations.codegen.servicelocator.ServiceLocator
import com.ramcosta.composedestinations.codegen.servicelocator.customNavTypeWriter
import com.ramcosta.composedestinations.codegen.servicelocator.defaultKtxSerializableNavTypeSerializerWriter
Expand Down Expand Up @@ -98,23 +101,25 @@ class CodeGenerator(

private fun shouldWriteKtxSerializableNavTypeSerializer(
destinations: List<CodeGenProcessedDestination>,
) = destinations.any {
it.navArgs.any { navArg ->
if (navArg.type.isCustomArrayOrArrayListTypeNavArg()) {
navArg.type.value.firstTypeInfoArg.run {
isKtxSerializable &&
!hasCustomTypeSerializer &&
!isParcelable &&
!isSerializable
}
} else {
navArg.type.run {
isKtxSerializable &&
!hasCustomTypeSerializer &&
!isParcelable &&
!isSerializable
): Boolean {
return destinations.any { destination ->
val hasKtxSerializableNavArgs = destination.navArgs.any { navArg ->
if (navArg.type.isCustomArrayOrArrayListTypeNavArg()) {
navArg.type.value.firstTypeInfoArg.needsToUseKtxSerializable()
} else {
navArg.type.needsToUseKtxSerializable()
}
}

val hasKtxSerializableResultBackTypes = destination.parameters
.firstOrNull { it.type.importable.qualifiedName == RESULT_BACK_NAVIGATOR_QUALIFIED_NAME }
?.type?.value
?.typeArguments?.first()?.let { (it as? TypeArgument.Typed)?.type }
?.needsToUseKtxSerializable() ?: false

hasKtxSerializableNavArgs || hasKtxSerializableResultBackTypes
}
}

private fun TypeInfo.needsToUseKtxSerializable() = isKtxSerializable && !hasCustomTypeSerializer && !isParcelable && !isSerializable
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ internal class InitialValidator(
?: throw IllegalDestinationsSetup(
"ResultRecipient second type argument must be a valid type with no '*' variance."
)
validateResultType(resultType)
validateResultType(resultType, parameter.type.toTypeCode())

val resultOriginQualifiedName = parameter.getFirstArgTypeQualifiedName()

Expand Down Expand Up @@ -262,6 +262,17 @@ internal class InitialValidator(
"Destination annotated Composables must have at most one ResultBackNavigator"
)
}

resultBackNavigatorParams.forEach { parameter ->
val resultType =
(parameter.type.typeArguments.firstOrNull() as? TypeArgument.Typed?)?.type
?: throw IllegalDestinationsSetup(
"Composable '${annotatedName}': " +
"ResultBackNavigator type argument must be a valid type with no type arguments."
)

validateResultType(resultType, parameter.type.toTypeCode())
}
}

private fun DestinationGeneratingParams.validateOpenResultRecipients() {
Expand All @@ -272,10 +283,11 @@ internal class InitialValidator(
val resultType =
(parameter.type.typeArguments.firstOrNull() as? TypeArgument.Typed?)?.type
?: throw IllegalDestinationsSetup(
"OpenResultRecipient type argument must be a valid type with no type arguments."
"Composable '${annotatedName}': " +
"OpenResultRecipient type argument must be a valid type with no type arguments."
)

validateResultType(resultType)
validateResultType(resultType, parameter.type.toTypeCode())
}
}

Expand Down Expand Up @@ -321,9 +333,9 @@ internal class InitialValidator(
return (firstTypeArg as? TypeArgument.Typed)?.type?.importable?.qualifiedName
}

private fun DestinationGeneratingParams.validateResultType(resultType: TypeInfo) {
private fun DestinationGeneratingParams.validateResultType(resultType: TypeInfo, argString: String) {
if (!resultType.isNavArgType()) {
throw IllegalDestinationsSetup("Composable $annotatedName, ${resultType.toTypeCode()}: Result types must be of a valid navigation argument type.")
throw IllegalDestinationsSetup("Composable '$annotatedName', $argString: Result types must be of a valid navigation argument type, but was '${resultType.toTypeCode()}'.")
}
}

Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ targetSdk = "34"

kotlin = "2.0.20"
dependencyCheckPluginVersion = "0.51.0"
agp = "8.7.0"
agp = "8.7.1"
mavenPublishPluginVersion = "0.28.0"

composeViewModel = "2.8.6"
Expand All @@ -19,10 +19,10 @@ ksp = "2.0.20-1.0.25"

junit = "4.13.2"

compose = "1.7.3"
composeMaterial = "1.7.3"
compose = "1.7.4"
composeMaterial = "1.7.4"
composeNavigationMaterial = "1.7.0-beta01"
composeNavigation = "2.8.2"
composeNavigation = "2.8.3"

ktxSerialization = "1.7.3"
pprint = "1.1.0"
Expand Down
2 changes: 1 addition & 1 deletion playground/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ android {

// Possible Compose Destinations configs:
ksp {
arg("compose-destinations.debugMode", "$rootDir")
// arg("compose-destinations.debugMode", "$rootDir")
// // Module name.
// // It will be used as the generated sealed Destinations prefix
// arg("compose-destinations.moduleName", "featureX")
Expand Down
2 changes: 1 addition & 1 deletion playground/featurex/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
}

ksp {
arg("compose-destinations.debugMode", "$rootDir")
// arg("compose-destinations.debugMode", "$rootDir")
arg("compose-destinations.moduleName", "featureX")
arg("compose-destinations.htmlMermaidGraph", "$rootDir/playground/docs")
arg("compose-destinations.mermaidGraph", "$rootDir/playground/docs")
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion playground/featurey/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
}

ksp {
arg("compose-destinations.debugMode", "$rootDir")
// arg("compose-destinations.debugMode", "$rootDir")
arg("compose-destinations.moduleName", "featureY")
arg("compose-destinations.htmlMermaidGraph", "$rootDir/playground/docs")
arg("compose-destinations.mermaidGraph", "$rootDir/playground/docs")
Expand Down
2 changes: 1 addition & 1 deletion playground/featurey/sub/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
}

ksp {
arg("compose-destinations.debugMode", "$rootDir")
// arg("compose-destinations.debugMode", "$rootDir")
arg("compose-destinations.moduleName", "subFeatureY")
arg("compose-destinations.htmlMermaidGraph", "$rootDir/playground/docs")
arg("compose-destinations.mermaidGraph", "$rootDir/playground/docs")
Expand Down
2 changes: 1 addition & 1 deletion playground/featurez/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
}

ksp {
arg("compose-destinations.debugMode", "$rootDir")
// arg("compose-destinations.debugMode", "$rootDir")
arg("compose-destinations.moduleName", "featureZ")
}
}
Expand Down

0 comments on commit 3549d53

Please sign in to comment.