https://kotlinlang.org logo
#kapt
Title
# kapt
s

Sam

02/24/2019, 9:57 PM
Where are kotlin stdlib's annotation processors defined?
g

gildor

02/25/2019, 12:19 AM
There are no APs in stdlib, what do you exactly mean?
s

Sam

02/25/2019, 2:35 PM
@gildor I meant, some of the annotations that comes with stdlib like JvmStatic
How are those applied?
m

Marc Knaup

02/25/2019, 7:32 PM
s

Sam

02/25/2019, 10:01 PM
@Marc Knaup Yes, but i'm looking for the processor implementation for JvmStatic
m

Marc Knaup

02/25/2019, 11:11 PM
I guess it's part of the Kotlin compiler and doesn't need a separate annotation processor.
s

Sam

02/25/2019, 11:13 PM
Okay, is that source available somewhere? The closest i came to is plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt which has this single entry point (doAnnotationProcessing) to work with all loaded processors
g

gildor

02/25/2019, 11:27 PM
@Sam As Marc said, there is no annotation processing involved, this is part of compiler and compiler uses those annotations and generate bytecode directly, this is pretty different from annotation processing which is Java API to generate source code File that you mention above is part of kapt, tool to support annotation processing for Kotlin code, but this is not used by kotlin itself, only to support third party APs
s

Sam

02/25/2019, 11:29 PM
@gildor Gotcha, thanks. Let me see if i can find corresponding code in compiler project.
g

gildor

02/25/2019, 11:31 PM
What exactly are you looking for?
s

Sam

02/25/2019, 11:33 PM
an existing implementation for best practice and now i'm curious how different would it be from a third party APs
g

gildor

02/25/2019, 11:34 PM
Beat practices of what?
s

Sam

02/25/2019, 11:35 PM
of the actual processing
g

gildor

02/25/2019, 11:35 PM
This is completely different from annotation processor, because it doesn't work with source, but with own AST and generates bytecode, not code
s

Sam

02/25/2019, 11:35 PM
Oh wov, interesting
g

gildor

02/25/2019, 11:40 PM
Also, it's not something isolated like annotation processor for a single annotation, this is part of compilation process which has a lot of different parts I just don't think that you can find any best practices or useful code there if you don't plan to contribute to Kotlin Compiler
s

Sam

02/25/2019, 11:41 PM
Makes sense, thanks
g

gildor

02/25/2019, 11:58 PM
It's possible to implement something similar using compiler plugin, but there is no API and for now it highly coupled with the compiler
s

Sam

02/25/2019, 11:58 PM
Yeah, looking forward to the compiler plugin feature
g

gildor

02/26/2019, 12:01 AM
It’s not something that will be available soon
s

Sam

02/26/2019, 12:01 AM
Yeah, fingers crossed
@gildor FWIW, i found Transform API from AGP which can be used for byte code transformations for Android (before Dex/D8). It gets class files post javac/kotlinc compilation. http://tools.android.com/tech-docs/new-build-system/transform-api
g

gildor

03/05/2019, 9:30 AM
Yes, it one of possible ways, some libraries use it, for example Smuggler https://github.com/joomcode/smuggler