Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lmartelli opened this issue May 15, 2024 · 4 comments

Comments

@lmartelli
Copy link

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

@thunderhook
Copy link
Contributor

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;
    }
}

@lmartelli
Copy link
Author

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;
}

@thunderhook
Copy link
Contributor

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 thunderhook changed the title Fields are renamed with getter Renaming an @Getter annotated field results in a getter inside the mapping definition (instead of the new field name) May 23, 2024
@thunderhook thunderhook changed the title Renaming an @Getter annotated field results in a getter inside the mapping definition (instead of the new field name) Renaming a @Getter annotated field results in a getter inside the mapping definition (instead of the new field name) May 23, 2024
@filiphr
Copy link
Member

filiphr commented Jun 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants