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

Exorcism of Annotation-Processing Tools

Exorcism of Annotation-Processing Tools

By : Budi Oktaviyan, Engineering Manager Grab
Live : https://www.youtube.com/watch?v=X2qKs6VhHMA

More Decks by Android Enthusiast Jakarta

Other Decks in Technology

Transcript

  1. Run-Time Annotation-Processing • Run time code generation • JVM based

    support and “Native” java code • Using reflections method
  2. Run-Time Annotation-Processing • Run time code generation • JVM based

    support and “Native” java code • Using reflections method
  3. Run-Time Annotation-Processing • Run time code generation • JVM based

    support and “Native” java code • Using reflections method
  4. Compile-Time Annotation-Processing • Compile time code generation • JVM based

    support and “Native” java code • Without reflections method
  5. Compile-Time Annotation-Processing • Compile time code generation • JVM based

    support and “Native” java code • Without reflections method
  6. Compile-Time Annotation-Processing • Compile time code generation • JVM based

    support and “Native” java code • Without reflections method
  7. • TYPE • FIELD • METHOD • FUNCTION • PARAMETER

    • CONSTRUCTOR Annotation Marker - @Target
  8. Processing The Modules • Initialize, using the init() function •

    Processing, using the process() function with or without a Kotlin Poet • Qualifying names of the annotations, using the getSupportedAnnotationTypes() function • Tell compiler which java version do we use, using getSupportedSourceVersion() function
  9. Processing The Modules • Initialize, using the init() function •

    Processing, using the process() function with or without a Kotlin Poet • Qualifying names of the annotations, using the getSupportedAnnotationTypes() function • Tell compiler which java version do we use, using getSupportedSourceVersion() function
  10. Processing The Modules • Initialize, using the init() function •

    Processing, using the process() function with or without a Kotlin Poet • Qualifying names of the annotations, using the getSupportedAnnotationTypes() function • Tell compiler which java version do we use, using getSupportedSourceVersion() function
  11. Processing The Modules • Initialize, using the init() function •

    Processing, using the process() function with or without a Kotlin Poet • Qualifying names of the annotations, using the getSupportedAnnotationTypes() function • Tell compiler which java version do we use, using getSupportedSourceVersion() function
  12. Annotation-Processing Limitations • Reflection inspect or access existing object (Not

    create a new ones) • Processing rounds on Run-Time (First initialization) issue • Processing rounds on Compile-Time (Build-Time) issue • Annotation-Processor is not debugable or testable • Not supporting multiple processing rounds (KAPT)
  13. Why KSP ? • Challenge to make build speed faster

    (Compile-Time) • APT/KAPT slow on Compile-Time (Build-Time) • Kotlin does not have a “Native” annotation-processing system • Offers powerful and simple API to parse Kotlin code directly • Claim 2x faster than KAPT (Build-Time)
  14. Processing KSP Modules • Initialize, using the init() function •

    Processing, using the process() function • Generating, using the finish() function
  15. Processing KSP Modules • Initialize, using the init() function •

    Processing, using the process() function • Generating, using the finish() function
  16. Processing KSP Modules • Initialize, using the init() function •

    Processing, using the process() function • Generating, using the finish() function
  17. Symbolic-Processing Downside • Minimum IDE or tooling support • Multi-Module

    are not yet supported • Questioning of faster Compile-Time (Build-Time) • Experimental supported for Room and Moshi • Dagger and Hilt are not yet supported
  18. Reference • https://hannesdorfmann.com/annotation-processing/annotationprocessing101 • https://iammert.medium.com/annotation-processing-dont-repeat-yourself-generate-your-code-8425e60c6 657 • https://medium.com/swlh/all-about-annotations-and-annotation-processors-4af47159f29d • https://medium.com/@workingkills/pushing-the-limits-of-kotlin-annotation-processing-8611027b6711

    • https://android-developers.googleblog.com/2021/02/announcing-kotlin-symbol-processing-ksp • https://medium.com/@jsuch2362/my-first-kotlin-symbol-processing-tool-for-android-4eb3a2cfd600 • https://kennay-kermani.medium.com/kotlin-symbol-processing-speeds-up-your-android-build-process-707 9ff0bff07 • https://www.zacsweers.dev/kotlin-symbol-processor-early-thoughts