Imogen is a Kotlin Symbol Processing (KSP) processor that generates implementations of interfaces with additional functionality. It simplifies the creation of model/data classes by generating concrete implementations from interface definitions.
- Automatically generates implementation classes from interfaces
- Customizable class naming with prefixes and suffixes
- Support for default values of various types
- Clean, boilerplate-free model definitions
Add KSP and Imogen to your project:
// Root build.gradle.kts
plugins {
id("com.google.devtools.ksp") version "YOUR_KSP_VERSION" apply false
kotlin("jvm") version "YOUR_KOTLIN_VERSION" apply false
}
// Module build.gradle.kts
plugins {
kotlin("jvm")
id("com.google.devtools.ksp")
}
dependencies {
implementation("me.ademirqueiroga:imogen:0.9.0-SNAPSHOT")
ksp("me.ademirqueiroga:imogen:0.9.0-SNAPSHOT")
}
- Define your model as an interface with the
@Generate
annotation:
import annotations.Generate
@Generate(name = "UserImpl")
interface User {
val id: String
val name: String
val email: String
val age: Int
}
- The processor will automatically generate an implementation class:
// Generated code
class UserImpl(
override val id: String,
override val name: String,
override val email: String,
override val age: Int
) : User
You can customize the generated class name:
@Generate(
name = "MyUser", // Required: Name of the implementation class
prefix = "Concrete", // Optional: Prefix for the class name
suffix = "Model" // Optional: Suffix for the class name
)
This would generate ConcreteMyUserModel
.
You can specify default values using annotations:
import annotations.*
@Generate(name = "UserImpl")
interface User {
@StringDefault("Anonymous")
val name: String
@IntDefault(18)
val age: Int
@BooleanDefault(true)
val isActive: Boolean
}
See the sample
directory for a complete example:
import annotations.Generate
@Generate(name = "SampleImpl")
interface Sample {
val string: String
val int: Int
val long: Long
val double: Double
val float: Float
val sample: Sample
}
This project is still a work in progress. Future updates may include:
- More customization options
- Additional annotations
- Enhanced documentation
This project is licensed under the MIT License - see the LICENSE file for details.
Ademir Queiroga ([email protected])