Metaprogramming with Kotlin Symbol Processing
summary
Builds a small code generator that scans classes annotated with Tag annotation, derives each class name with the KSP resolver, and emits one file of extension properties using KotlinPoet and the KSP code generator. The pipeline uses an annotation module plus a compiler module (registered via the provider resource), sets retention to SOURCE, filters KSClassDeclarations, and writes files with addOriginatingKSFile so incremental recompiles work. Emphasizes KSP’s determinism versus LLMs and shows a working Tagger symbol processor that reliably generates tag properties.
AI-written summary · about
chapters (21)
- 0:00Metaprogramming introduction
- 1:12What is metaprogramming
- 2:37Metaprogramming history
- 4:47Annotation processing evolution
- 6:16KSP with logger tags
- 8:24Setup KSP with modules
- 9:49Define tag annotation
- 10:51Create KSP processor provider
- 11:56Implement KSP processor
- 13:21Find annotated classes
- 14:23Generate code with Poet
- 16:10Build extension property
- 17:31Handling rounds and results
- 18:35Write generated code
- 19:58Generated code usage
- 20:39AI versus traditional metaprogramming
- 22:04Advantages of traditional metaprogramming
- 22:49AI metaprogramming benefits
- 24:14When to write metaprogramming tool
- 25:42Risks of metaprogramming tools
- 26:46Resources and closing
related talks
25mCode Generation Using Kotlin Symbol Processing (KSP)
36mExploring Kotlin Symbol Processing: A Practical Guide
26mBuild your own compiler with KSP
36mFact or kapt? Build your next annotation processor with KSP
47mDealing With KSP in Common Code for Android and iOS
35mExploring Kotlin Symbol Processing: A Practical Guide
38mKSP and Plugins. Optimizing Kotlin Multiplatform common code
33mMeta-programming with KSP and Kotlin compiler plugins
