google / google/ksp

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

Open
#1,868 4 comments 7 reactions 0 assignees View on GitHub
feature request P3
Dominant language
Kotlin
Stars
3.5k
Forks
415
Avg merge
1d 2h
Merged PRs (30d)
53

Description

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:
```kotlin
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 = UUID.random().toString(), // would extract nothing (or a DYNAMIC placeholder) as it is not constant
)
```

EDIT: fixed a typo on `dynamicDefault` example

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.