CommentExtractor

Extracts @Comment annotations from data class constructor parameters and builds a dot-separated path map of comment metadata.

This object recursively walks the primary constructor of a configuration data class, collecting any Comment annotations and mapping them to their fully qualified dot-notation paths (e.g., "database.connection.host").

Example:

data class DatabaseConfig(
@Comment(["The database host"], placement = CommentPlacement.INLINE)
val host: String = "localhost",
@Comment(["The database port"])
val port: Int = 5432
)

data class AppConfig(
val database: DatabaseConfig = DatabaseConfig()
)

val comments = CommentExtractor.extract(AppConfig::class)
// Returns:
// {
// "database.host" -> CommentData(["The database host"], INLINE),
// "database.port" -> CommentData(["The database port"], ABOVE)
// }

Since

1.0

See also

Functions

Link copied to clipboard
fun extract(klass: KClass<*>, prefix: String = ""): Map<String, CommentData>

Recursively extracts Comment annotations from the primary constructor parameters of klass and all nested data classes.