kapt-annotation-processing-for-kotlin
better-annotation-processing-supporting-stubs-in-kapt
Implement Annotation Processing API (JSR 269) natively in Kotlin
Use javac annotation processing implementation, generate AST stubs for Kotlin classes
Notes:-
- @Component
- @Module
- @Provides
- @Module
Shows Planets being injected via constructor by qualifier
public class TerrestrialPlanets @Inject (@Named("Mercury") val mercury: Planet,
@Named("Venus") val venus: Planet,
@Named("Earth") val earth: Planet,
@Named("Mars") val mars: Planet) {
}
The TerrestrialPlanetsModule, for example, provides a singleton named "Mercury" etc.
@Module
public class TerrestrialPlanetsModule {
@Provides @Singleton @Named("Mercury")
public fun first() : Planet {
return Mercury()
}
@Provides @Singleton @Named("Venus")
public fun second() : Planet {
return Venus()
}
@Provides @Singleton @Named("Earth")
public fun third() : Planet {
return Earth()
}
@Provides @Singleton @Named("Mars")
public fun fourth() : Planet {
return Mars()
}
}
- Outer Planets module
- Jupiter
- Saturn
- Uranus
- Neptune
Gradle build
./gradlew run
./gradlew test