Skip to content

Conversation

@hduelme
Copy link
Contributor

@hduelme hduelme commented Jul 6, 2024

I added an inspection if a target property is explicitly (using @Mapping) mapped more than once.
The error is directly reported on the target field:
grafik

Same applies if used inside @Mappings
grafik

If a own annotation containing @Mapping or @Mappings is used the error is reported on the annotation directly
grafik

@filiphr
Copy link
Member

filiphr commented Jul 7, 2024

Good one @hduelme.

This looks good to me. Should we perhaps offer some quick fixes for it? Perhaps:

  • Remove @Mapping
  • Rename target

I can't think of another quick fox for this.

@thunderhook
Copy link
Contributor

Nice @hduelme!

If a own annotation containing @mapping or @mappings is used the error is reported on the annotation directly

For this scenario there might be a "remove @MyMappingAnnotation" as a quick fix. But I think this is more of an edge-case and not worth implementing.

I think the quick fix can be done in a separate issue.

@hduelme
Copy link
Contributor Author

hduelme commented Jul 7, 2024

@filiphr , @thunderhook I added your suggested quick fixes. The replace (or change) target quick fix currently only selects the text to change. If you know a better way to handle this, let me know.

Another idea for a quick fix is, to allow reusing properties automatically. For example, if the other annotation doesn't have a default source, we could offer a way to use our source as a default source.

Copy link
Contributor

@thunderhook thunderhook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few notes, thanks @hduelme! Don't know if @filiphr would like to take a look.

Copy link
Member

@filiphr filiphr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me @hduelme. I'll leave it up to you to decide whether we should only select the text or remove it.

Can you please fix the conflicts? I believe the merge for the Java 17 upgrade caused some merge conflicts.

@hduelme hduelme force-pushed the Target-property-mapped-more-than-once-inspection branch from 6d73f14 to 05521ae Compare July 21, 2024 12:25
@hduelme
Copy link
Contributor Author

hduelme commented Jul 21, 2024

@filiphr I resolved the merge conflicts.

@filiphr filiphr merged commit 48f4d6a into mapstruct:main Jul 21, 2024
@filiphr filiphr added this to the 1.8.0 milestone Jul 21, 2024
@filiphr
Copy link
Member

filiphr commented Jul 21, 2024

Thanks @hduelme

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants