mapstruct-idea icon indicating copy to clipboard operation
mapstruct-idea copied to clipboard

Refactor-rename a field breaks mapping when also using lombok

Open eekboom opened this issue 8 years ago • 3 comments

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" )

eekboom avatar Sep 28 '17 19:09 eekboom

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.

filiphr avatar Sep 29 '17 17:09 filiphr

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.

mkrumpholz avatar Jun 30 '20 15:06 mkrumpholz

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 avatar Sep 05 '21 15:09 linzch3

@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)

thunderhook avatar Jan 13 '24 21:01 thunderhook

Thanks for testing this @thunderhook. Going to close it for now. If someone still has issues with this we can reopen it.

filiphr avatar Jan 28 '24 17:01 filiphr