Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Traitement des annotations en Kotlin

Traitement des annotations en Kotlin

Yves Kalume

February 24, 2023
Tweet

More Decks by Yves Kalume

Other Decks in Programming

Transcript

  1. Utilisation d’une annotation @Devscast class Foo(val id: Int, val name:

    String) fun main() { val annotations = Foo.:class.annotations print(annotations) ./ [] une liste vide... pourquoi ? }
  2. Fournisseur de processeur class DevscastProcessorProvider : SymbolProcessorProvider { override fun

    create( environment: SymbolProcessorEnvironment ): SymbolProcessor { return DevscastProcessor(environment) } }
  3. Processeur class ListedProcessor( private val environment: SymbolProcessorEnvironment ) : SymbolProcessor

    { override fun process(resolver: Resolver): List<KSAnnotated>{ ./ traitement } }
  4. dependencies { implementation(project(":lib") ) ksp(project(":lib")) } android { kotlin {

    sourceSets.debug { kotlin.srcDirs += 'build/generated/ksp/debug/kotlin' } sourceSets.release { kotlin.srcDirs += 'build/generated/ksp/release/kotlin' } } }