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

Target property mapped more than once inspection

Open hduelme opened this issue 1 year ago • 3 comments

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

hduelme avatar Jul 06 '24 23:07 hduelme

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.

filiphr avatar Jul 07 '24 07:07 filiphr

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.

thunderhook avatar Jul 07 '24 10:07 thunderhook

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

hduelme avatar Jul 07 '24 15:07 hduelme

@filiphr I resolved the merge conflicts.

hduelme avatar Jul 21 '24 12:07 hduelme

Thanks @hduelme

filiphr avatar Jul 21 '24 15:07 filiphr