Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to KSP2 API changes #643

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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