https://kotlinlang.org logo
#ksp
Title
# ksp
a

arnaud.giuliani

09/06/2023, 2:56 PM
Hello, I'm working on analyzing class constructor parameters. When accessing those parameters via
KSValueParameter
class, I see that we have
hasDefault
property to tell if we have default value. How do you get the default value expression behind?
Copy code
class A( val i : Int = 0 )
How to get the default value of "i" here?
a

arnaud.giuliani

09/06/2023, 3:22 PM
ok, thanks 👍
a

asdf asdf

09/06/2023, 3:43 PM
There's a temporary workaround I've been using to accomplish this using if you add the KSP implementation and
kotlin-compiler-embeddable
as a library:
Copy code
val KSPropertyDeclaration.defaultValue: String?
        get() = (this as? KSPropertyDeclarationParameterImpl)
            ?.ktParameter
            ?.defaultValue
Which returns the raw PSI expression of the default value
j

Jiaxiang

09/06/2023, 5:03 PM
it is still hard to evaluate the psi expression on your side though.
👍 1