[Resolved] Hi guys, probably a stupid question, but is there a way to use KSP to do this? Let's say...
l
[Resolved] Hi guys, probably a stupid question, but is there a way to use KSP to do this? Let's say I have an annotation called NavigationRoute and it's being used on a class. This class implements a method, that contains list of KType. I want to use KSP to generate a function that has ordered arguments of types defined by aforementioned function. Is there a way to access the actual contents of this list so that I can use it for generating another function? I know that I can add those arguments directly to the annotation but that would duplicate it and I'd prefer not to do it. Here is a sample that uses my custom annotation:
Copy code
@NavigationRoute
object DetailRoute : NavRoute<DetailViewModel> {
    override val route: String = "Detail"

    override fun getActualArguments() = listOf(
        "detailArg" to DetailData::class
    )

    @Composable
    override fun viewModel(parameters: ParametersDefinition?) =
        viewModel<DetailViewModel>(parameters = parameters)

    @Composable
    override fun Content(viewModel: DetailViewModel) = Detail(viewModel)

}
I want to use the result of function getActualArguments to generate method:
Copy code
fun DetailRoute.navigateSafe(detailArg: DetailData) {
}
The point is be able to use arg names and types as specified in above code.
j
What do you mean by
implements a method that contains list of KType
? Can you elaborate with some code snippet?
l
@Jiaxiang I edited my question 🙂
Well, I've used a different approach in the end, I generate whole file instead of extension function