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

Renaming a @Getter annotated field results in a getter inside the mapping definition (instead of the new field name)

Open lmartelli opened this issue 1 year ago • 4 comments

public class User {
    String name;
}

@Mapper
public interface UserMapper {
    @Mapping(source="name", target="nom")
    UserDto toDto(User user)
}

When you rename User.name to lastName, the mapping becomes @Mapping(source="getLastName", target="nom")

lmartelli avatar May 15 '24 13:05 lmartelli

Hi @lmartelli!

Which version of the plugin are you currently using? How does your model look like in detail?

Not able to reproduce this with the following code:

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper
interface Issue197Mapper {
    @Mapping(source="name", target="nom")
    UserDto toDto(User user);
}

class UserDto {
    public String nom;
}

class User {
    String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

thunderhook avatar May 15 '24 21:05 thunderhook

Hi @lmartelli!

Which version of the plugin are you currently using?

1.7.0

How does your model look like in detail?

I use Lombok to generate getters, sorry for no specifying this in the first place :

import lombok.Getter;

@Getter
static class User {
    private String name2;
}

lmartelli avatar May 15 '24 22:05 lmartelli

Yes, this is reproducible when using Lombok:

reproducal-rename-lombok

I don't think we can fix this on our end. We just provide elements that can be renamed in the MapstructSourceTargetParameterRenameHandler. How those parameters are used by the PsiElementRenameHandler is beyond our control. At least to my knowledge.

thunderhook avatar May 22 '24 20:05 thunderhook

Thanks for the analysis @thunderhook. I'm also not sure what we can do. Perhaps this is some kind of a bug in the Lombok plugin. It works correctly when renaming a field (which triggers method rename) and renaming the getter directly

filiphr avatar Jun 01 '24 10:06 filiphr