Hi all, I have an annotation `MyCustomAnnotation` ...
# ksp
d
Hi all, I have an annotation
MyCustomAnnotation
and a class of the following manner:
Copy code
@MyCustomAnnotation
abstract class User {
    val id: Int = 11
    val name: String
}
Now I am trying to generate the following function using KSP:
Copy code
fun getUser(id: Int = 11, name: String): User {
    return User(id, name)
}
I am unable to get the value defined of the variable
id
, so the function generated has no default arguments. Any method to get the value of a class variable? Currently the following function is being generated:
Copy code
fun getUser(id: Int name: String): User {
    return User(id, name)
}
Thanks
c
I think you cannot get that through KSP, since the value is not part of the signature of the class, but part of the implementation
d
Thanks 👍
a
you could try to generate another annotation that’ll be used for properties in your class and specify de default value there
d
Yes that could also work, but I was looking for something that could handle complex data types also (user defined data classes). Probably something that can simply copy the string after "=", and provide it at compile time.