yatagan icon indicating copy to clipboard operation
yatagan copied to clipboard

All @Inject fields/properties must be public

Open kirich1409 opened this issue 2 years ago • 3 comments

I use Dagger 2 and have a lot of Java fields with Inject annotation and package-private or protected access. With Yatagan isn't possible to have the same restrictions in access and I need to make all fields like this public. I found out that the restriction connected with reflection mode, but reflection API has possibility to allow modify not public fields

kirich1409 avatar Mar 02 '23 13:03 kirich1409

I'll investigate the possibility of using such API.

Jeffset avatar Mar 02 '23 13:03 Jeffset

Well, Yatagan doesn't generate any factories/injectors in the same package as Dagger does. So even if it is possible to use isAccessible = true with RT mode, the compilation will fail with generated code if the component declaration is in the different package than the class with @Inject constructor/fields being accessed. So there's no point in using this reflection API at all. Now, what can be done, is more precise access checks instead of conservatively requiring everything to be public/internal. This is more difficult to implement, and may introduce additional performance overhead in RT. This needs more investigation. And, of course, this will not let us to use package-private/protected fields/constructors with components from another packages.

Jeffset avatar Mar 15 '23 16:03 Jeffset

As the profit of solving this is, sadly, less than we expected, I'll lower the priority.

Jeffset avatar Mar 15 '23 16:03 Jeffset