mapstruct / mapstruct-eclipse

An Eclipse plug-in for working with MapStruct
Other
13 stars 8 forks source link

Quick fix for unmapped target properties #18

Closed agudian closed 9 years ago

agudian commented 9 years ago

This PR adds some basic stuff for creating quick fixes and also adds the first quick fix:

For the error/warning message "Unmapped target properties", the quick-fix "Ignore unmapped target properties" adds @Mapping(target = "<prop>", ignore = true) for each of the unmapped properties.

The quick fix can handle the following cases:

I used an early version of this some weeks ago while working on a large number of mappers that I switched to unmappedTargetPolicy=ERROR and it was really fun... :smile:

gunnarmorling commented 9 years ago

@agudian Finally looking into this. Another possible fix would be to set the "unmapped target policy" in the @Mapper annotation to IGNORE. WDYT?

gunnarmorling commented 9 years ago

The indentation / line breaks might be improved a bit further.

E.g. that's what I have:

@Mappings({
})

And that's how it's quick fixed:

@Mappings({@Mapping(target = "color", ignore = true)
})

Or that's what I have:

@Mappings({
    @Mapping(target = "age", ignore = true),
    @Mapping(target = "name", ignore = true)
})

And that's how it's quick fixed:

@Mappings({
    @Mapping(target = "age", ignore = true),
    @Mapping(target = "name", ignore = true), @Mapping(target = "color", ignore = true)
})
gunnarmorling commented 9 years ago

@agudian, great stuff, works like a charm! I've added some comments, but nothing earth-shaking. Looks good overall!

agudian commented 9 years ago

Another possible fix would be to set the "unmapped target policy" in the @Mapper annotation to IGNORE. WDYT?

Good idea. Let's track that in a separate issue.

On your formatting remarks: as you can see in the code, I only add nodes to the AST, not the source text itself. The source should be rendered using your specific formatter-settings. Check the line-breaks for annotation members and array-initializers... That should do the trick for you :-)

Thanks for the review! I'll work in some of the suggestions, add a commit for adding checkstyle to the build and push everything to master then... Some time tonight ;-)