Kotlin Compiler Plugin - Write your own code transformer without dealing with bytecode
summary
Facebook prototypes a Kotlin compiler plugin that rewrites annotated methods into inline traceBegin traceEnd with try finally so no bytecode editing is needed and transformed files are written as virtual files into the build folder. Implementation uses a Gradle subplugin to pass options, a command line processor plus ComponentRegistrar, and an analysis handler extension that runs a KT tree visitor to edit source text. Plugin is on GitHub works on modules using the Kotlin compiler but breaks IDE breakpoints and cannot modify third party compiled libraries.
AI-written summary · about
chapters (12)
- 0:00Introduction
- 0:55Why Kotlin Compiler Plugin
- 3:25Use Cases for Code Transformation
- 5:10Challenges of Writing Plugin
- 6:34Gradle Plugin Setup
- 8:18Kotlin Gradle Subplugin
- 10:22Kotlin Compiler Plugin
- 11:48Analysis Handler Extension
- 13:57Tree Visitor for Parsing
- 16:26Full Transformation Process
- 16:46Best Practices and Warnings
- 18:36Q&A Session
