Skip to content

FEATURE IDEA: Lombok Refactoring

Maaartinus edited this page Oct 26, 2018 · 4 revisions

A tool (that would need an interface, and thus might be most useful as an IDE plugin) that can scan existing java source code and suggest ways in which lombok can remove boilerplate. For some transformations, this is straightforward (such as @Getter), but for others, this will need some user feedback (for example, the odds that a user’s hashCode() is exactly equal to what @Data generates is small, but nevertheless, a class with toString, hashCode, equals, that all look roughly look they are just boilerplate should trigger a suggestion to replace them all with @Data – it cannot make this decision automatically, however).

A basic design would probably involve a list of lombok transformations on one side, with checkboxes for each of them, as well as a list of files with candidate rewrites, which adjusts to only those rewrites with a selected transformation on the left hand side (so each transformation has a checkbox but can also be selected). Upon clicking a source file, a diff view is shown about what lombok suggests. The suggested version should be editable, and the page should have a save button, or a ‘leave as is’ button (which removes that file from the list).

A related idea: Allow hiding lombok generated methods from the IDE outline. While lombok keeps the written code concise, the outline shows all the boilerplate which often isn’t useful. OTOH, as stated in #1923, the outline provides the only possibility for non-text-based searches for generated code, so it’s important. A toggle would be nice. Graying out the generated stuff would be an option, too.