Let me know if you'd prefer this as a separate project entirely, but I think within the Immutables project is a good place for it.
One thing I've noticed that Lombok does really well (with its IntelliJ plugin) is have support for "Find Usages". With Immutables, finding when a field is set or accessed can be really annoying, especially if you're using Modifiable. There are many possible methods with which you can set a field: The setter in the Builder, the setter in the Modifiable, the copy-on-write setter in the Immutable, etc.
It would be a lot more convenient if doing a "Find usages" on the getter in the interface also found usages of the various setters. This obviously cannot be fixed in the Immutables library itself, but requires an IDE plugin.
Thank you for raising this. These are some assorted thoughts I have about this
I personally don't have expertise and time to invest in IntelliJ plugin building so help/contribution is needed for this
If I correctly understand the problem, we want to establish linking between manual accessors (including overriden impl) and corresponded purely generated initializers in builder or setters in modifiable.
(Continued 2, actually) It would be useful to have Find Usages and Refactoring (rename in particular, maybe safe delete etc) support for these elements.
Last time (3-4 years ago) I looked into IDEA and they lacked plugin API to introduce refactoring participant (as those called in Eclipse) which would expected to be published in some future (from that time). Dunno about find usages extension points.
Ideal solution for this as I see it introducing special annotations that would be added to generated elements. These annotations would carry a link to originating element as well as any linking metadata such as name derivation pattern ("set*" for x() -> setX()). These annotations then can be used by IDEA plugin, as well as any other tools (like CLI "renamer" tool). Obviously, these annotations would not have any value without the corresponding tool/plugin which supports them. The good part, that I mentioned, is that these annotations and tools can be applicable to many annotation processors and code generators, not just Immutables.
github.com/immutables org, no problem here (as well as any separate user/org would be ok too)Perhaps you could include some specific use cases and examples of where IntelliJ doesn't work well today, and where a plugin would make it better?
In my experience, IntelliJ is actually quite good at seeing the generated code and refactoring / searching it accordingly, just as if it was "normal" code. Lombok _requires_ such a plugin because it doesn't product actual code, and the fact that Immutables is so usable w/o needing an extra plugin is a _major_ win.
For the specific example you called out, about determining where a field was set, here's the simple process I use to answer this question in IntelliJ:
Nothing other than compiling is needed to be able to do this.
for me the need is clear, when you rename accessor (for example) you would also want to rename corresponding initializer on a buider. There's nothing addressing this out for the box. If you just rename accessor, on the next compilation you'll get a buch of errors complaining that methods are not defined (as generated initializers changes names following source accessors, but the usages was not updated). The ideal solution, as I can think of it, is that generated elements can have metadata/annotations pointing to which source elements they are derived from and what naming pattern was used to derive the name of an element. Then, some generic IDE plugin can rename not only source elements but also derived elements (found by matching metadata) honoring name derivation pattern (also included in metadata as mentioned before). The Eclipse have a notion of "refactoring participant" so that you can write a plugin for that. As of a couple of years ago, IDEA didn't have any public/published API to accomplish this, but things, probably, have changed since then.
@cdeszaq A common use case for me is to find all the places that a value is set. I find myself needing to look for and do Find Usages on the setter in the generated builder, or in the generated Modifiable, or the "with"er method in the generated Immutable, or in the constructor(s), but not the setter in the generated Json.
I agree that you can do this without a plugin, but it's much more tedious and possible to miss one if you are using several features that can generate modifier methods.
Compare with the Lombok plugin, where you find usages on the property, and it finds all the usages of getters and setters all at once. This is a superior experience once you have the plugin installed.
Another problem is when you have multiple Immutables generated classes that implement a shared interface. Then it can be extremely difficult to find usages of setters of the shared getter, since there are that many more generated setters.
Hi,
I created an initial implementation of such plugin: https://github.com/plaskowski/find-immutables-usages-plugin
Bests,
Piotr
Most helpful comment
Hi,
I created an initial implementation of such plugin: https://github.com/plaskowski/find-immutables-usages-plugin
Bests,
Piotr