Hello, I'm working on analyzing class constructor ...
# ksp
a
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
ok, thanks 👍
a
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
it is still hard to evaluate the psi expression on your side though.
👍 1