google / ksp

Kotlin Symbol Processing API
https://github.com/google/ksp
Apache License 2.0
2.72k stars 255 forks source link

[feature request] Retrieve property default value for compile time constants #1868

Open Chuckame opened 2 months ago

Chuckame commented 2 months ago

Currently, it's not possible to retrieve the default value as it is expensive to compute (#642).

This feature request is not about extracting all the default values, but just the compile time constants, that would cover the same values as annotations. It would help a lot for static analysis, for schema generation by example.

Example:

data class MyClass(
   val staticString: String = "static string", // would extract 'static string'
   val staticInt: Int = 42, // would extract '42'
   val fieldDependentDefault: String = staticString, // would extract 'static string' as it is the static default of staticString field
   val dynamicDefault: String = staticString, // would extract nothing (or a DYNAMIC placeholder) as it is not constant
)
neetopia commented 1 month ago

This is fair, we will revisit this once KSP2 is stable.

Chuckame commented 1 month ago

Great news! Do you have a planned date for ksp2 to be stable?