I wonder if the frontend of compiler plugin has ex...
# compiler
c
I wonder if the frontend of compiler plugin has extension that implicitly modify visibility of declarations. I want to make the constructors of all classes marked with an annotation
private
. Is that possible now?
d
No, but it will be possible with K2 plugins API
K 4
r
That’s exciting!
c
No, but it will be possible with K2 plugins API
And is it possible to remove implicit declarations now or K2, for example Kotlin will create a primary constructor for the class implicitly, I want to remove it
d
No, declarations removal is not supported, because it may break some contracts (e.g. contract that each class should have at least one constructor) What's your usecase?
c
What’s your usecase?
I have a class that doesn’t allow manual creation (instance are usually returned by certain methods), so I want to delete the primary constructor or make its visibility
private
, also, when there is a primary constructor,
operator fun invoke()
will be overwritten.
d
You can not delete it, because without any constructor you can not instantiate it (lack of constructor also breaks jvm bytecode contracts) But, if class have no explicit constructors frontend generates implicit one for which you can change visibiltiy to
private
as for explicitly declared constructor
You even can distinguish implicit primary constrcutor from explicit one (e.g. with no arguments) and apply some different logic to them if you want
c
Yes, I mean, if any constructor is explicitly declared, I will use the
Checker
to report errors, so I just want to hide the primary constructor automatically generated by the frontend