mapstruct-idea
mapstruct-idea copied to clipboard
Refactor-rename a field breaks mapping when also using lombok
When I refactor-rename a field (and its getter) using IDEA, then the mapping annotation is changed incorrectly.
For example when I rename a field from foo to bar, then the target/source value in the mapping annotation is changed from foo to getBar.
You can reproduce this with the included "mapstruct-lombok" example: Rename Source.test to Source.foo and the Mapping in SourceTargetMapper will incorrectly be
@Mapping( source = "getFoo", target = "testing" )
This is an issue with the lombok plugin specifically. I'll have to investigate how I can resolve this problem. Without lombok it works as expected.
When renaming the field in the bean it will use intellij (or lombok's) rename handler and just rename java fields and methods and break the mapping annotation.
When renaming the reference on the annotation (the string literal on source or target) idea asks which rename handler to use: lombok's oder mapstruct's. But the results are the same, renaming works for the fields and methods (getter, setter) and leaves the mapping parameter alone while breaking the mapping.
It is missing the rename of the literal where the reference to it should be found for the field that is about to be renamed. I think find references should return something to do the additional work on the annotation.
This is an issue with the lombok plugin specifically. I'll have to investigate how I can resolve this problem. Without lombok it works as expected.
Hi~ fillphr, thank u for your great tool, it is really helpful! The above problem still seems to exist, for me, refactor code is a daliy job :),so this problem has bothered me for a long time. And do you have any plans to fix this problem?
looking forward to your reply😄
@linzch3 It seems to me that this problem is now solved (maybe since IntelliJ integrated the lombok plugin into the IDE itself?) Would you mind testing it again? It worked for me with my version:
IntelliJ IDEA 2023.3.2 (Ultimate Edition)
Build #IU-233.13135.103, built on December 20, 2023
Non-Bundled Plugins:
org.mapstruct.intellij (1.6.1)
Thanks for testing this @thunderhook. Going to close it for now. If someone still has issues with this we can reopen it.