I am trying to create a plugin that removes `inter...
# compiler
n
I am trying to create a plugin that removes
internal
modifiers in the compiler process. Like
kotlin-allopen
plugin. The idea is to keep a way of having
internal
abuse in kotlin generated code. However, after deep-diving I hit a wall. No extension is running because Square's
Anvil
(and probably KSP) is generating code that does not compile due to publicly exposed
internal
stuff. The only exception is
DeclarationAttributeAltererExtension
, which runs during the resolve phase. However,
DeclarationAttributeAltererExtension
is able to modify only
Modality
. Is there any other way to plugin during
resolve
phase in order to fix compilation errors?
s
I think there's no way to do this currently, but the new frontend may have an extension point for this
n
I found some examples in
fir-plugin-prototype
, and even exactly the code I want to implement: https://github.com/JetBrains/kotlin/blob/master/plugins/fir-plugin-prototype/src/o[…]rains/kotlin/fir/plugin/FirPluginPrototypeExtensionRegistrar.kt However, in my code
FirExtensionRegistrar
is not running at all.
s
Yep, I think there are some flags that you could enable to switch to fir You can also just use 1.7.0-dev(numbers) version from kotlin-dev maven repo
n
1.7.0-dev was not enough, I also needed explicit enable fir:
freeCompilerArgs += "-Xuse-fir"
s
Yep, sorry I wasn't clear enough on that :)
n
Finally! My plugin is working. Thanks for the tip!
s
Congrats! Happy hacking ;)
n
BTW, 1.6.20 works fine with my plugin. However:
Class 'com.vinted.deinternalize.sample.lib.ExternalDep' is compiled by the new Kotlin compiler frontend and cannot be loaded by the old compiler
And also, seems I will not be able to use it in the product soon enough. Too risky
s
Yeah, you'll have to opt-in into experimental features that are known to be unstable