Skip to content

Commit

Permalink
Adapt to KSP2 API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
FooIbar committed Dec 23, 2024
1 parent 91a2f2b commit 04d35e0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,14 @@ fun KSValueParameter.toParameter(
)
}

fun KSType.toGenVisibility(): Visibility {
fun Any.toGenVisibility(): Visibility {
// Enum entries in annotation arguments are evaluated as KSClassDeclaration instead of KSType in KSP2
// https://github.com/google/ksp/blob/main/docs/ksp2api.md#evaluation-of-enum-entries-in-annotation-arguments
val declaration = when (this) {
is KSType -> declaration
is KSClassDeclaration -> this
else -> error("Unexpected type for 'visibility' param $this")
}
return when (val visibility = declaration.simpleName.asString()) {
"PUBLIC" -> Visibility.PUBLIC
"INTERNAL" -> Visibility.INTERNAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ internal class KspToCodeGenDestinationsMapper(
}

private fun KSAnnotation.getDestinationVisibility(): Visibility? {
return findArgumentValue<KSType>("visibility")?.toGenVisibility()
return findArgumentValue<Any>("visibility")?.toGenVisibility()
}

private val activityType by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal class KspToCodeGenNavGraphsMapper(
val navGraphAnnotationNameArg = navGraphAnnotation
.findArgumentValue<String>(DESTINATION_ANNOTATION_ROUTE_ARGUMENT)
val navGraphVisibility = navGraphAnnotation
.findArgumentValue<KSType>("visibility")!!
.findArgumentValue<Any>("visibility")!!
.toGenVisibility()
val navGraphDefaultTransitions = navGraphAnnotation
.findArgumentValue<KSType>("defaultTransitions")
Expand Down

0 comments on commit 04d35e0

Please sign in to comment.