Skip to content

Refactor target reference to report errors during bean mapping instead of creation of the target reference - #2068

Merged
filiphr merged 1 commit into
mapstruct:masterfrom
filiphr:target-reference-refactorings
Apr 13, 2020
Merged

Refactor target reference to report errors during bean mapping instead of creation of the target reference#2068
filiphr merged 1 commit into
mapstruct:masterfrom
filiphr:target-reference-refactorings

Conversation

@filiphr

@filiphr filiphr commented Apr 12, 2020

Copy link
Copy Markdown
Member

With this we can more easily go in the direction of using constructor to map into target beans.

This is a step towards #73

In this PR all tests are passing green (had to change some, but I think that this is OK).

There is an alternative approach to this. That would be to have dedicated ForgedMappingReferences from which we would be able to create the new MappingReferences like we are doing for the SourceMethod. Basically the problem is that we first need to get the accessors and result type and then construct the TargetReference

Fixes #2069

@filiphr
filiphr requested a review from sjaakd April 12, 2020 11:43

@sjaakd sjaakd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi Filip,

I think that for the majority I'm ok.. But I do have some questions:

  1. The whole purpose is to delay checking of the stuff in TargetReference to the moment that we do BeanMapping validations right?
  2. I see you dropped TargetReference but it had an abstract base class AbstractReferenc (shared with SourceReference .. is this still needed?
  3. Do I understand you correctly and you replaced the PropertyEntries by a String. should we do the same at the source side?

<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="MethodLength"/>
<module name="MethodLength">
<property name="max" value="200"/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

finally.. :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

haha, maybe even completely remove it? I am all OK for checks and the likes, but it should not be blocking us

message = "Unknown property \"colour\" in type org.mapstruct.ap.test.namesuggestion.Garage for target" +
" name \"garage.colour.rgb\". Did you mean \"garage.color\"?"),
@Diagnostic(type = PersonGarageWrongTargetMapper.class,
kind = javax.tools.Diagnostic.Kind.WARNING,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suddenly.. more WARNINGS?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Before the entire TargetReference for garage.colour.rgb was invalid which meant that handling the defined mappings led to an hour which stopped the creating of the BeanMappingMethod and this not reporting the unmapped target.

However, with the new change the target reference does not have valid property anymore, so the defined mappings would not report this error and thus we would reach the unmapped target properties reporting.

IMO this is a good thing, since you have more warnings / errors that you can look at initially

@filiphr

filiphr commented Apr 13, 2020

Copy link
Copy Markdown
Member Author

Thanks a lot for the review @sjaakd.

Answers to your questions inline

  1. The whole purpose is to delay checking of the stuff in TargetReference to the moment that we do BeanMapping validations right?

Yes the idea was that the do the checking of the stuff in TargetReference when we have all accessors (the constructor accessors will not be coming from the Type itself). Currently the TargetReference is actually created within the BeanMappingMethod.Builder, so perhaps I can still move the validation into it and create them once I have all builders. Would need to change the nested mapping a bit for that, but I think it is OK.

  1. I see you dropped TargetReference but it had an abstract base class AbstractReferenc (shared with SourceReference .. is this still needed?

What do you mean I dropped? I am no longer inheriting from the AbstractReference since I think that it is no longer necessary. I also found it a bit confusing since there was a mix of accessors that that were depending on the TargetReference or SourceReference.

  1. Do I understand you correctly and you replaced the PropertyEntries by a String. should we do the same at the source side?

Yes that is exactly what I did replacing the property entries with a collection of String. I was thinking to do the same for the source side indeed. However, this was complex enough and I didn't want to make the PR and change even bigger.

@sjaakd

sjaakd commented Apr 13, 2020

Copy link
Copy Markdown
Contributor

What do you mean I dropped? I am no longer inheriting from the AbstractReference since I think that it is no longer necessary. I also found it a bit confusing since there was a mix of accessors that that were depending on the TargetReference or SourceReference

No.. I formulated it a bit crummy.. Sorry. You removed the abstract class AbstractReference.. There's no reason to keep this one around, since its sole purpose now is SourceReference. So, it can be integrated within this class. That was the geste of this remark.

@filiphr

filiphr commented Apr 13, 2020

Copy link
Copy Markdown
Member Author

OK Now it is clear.

Yes you are completely right. However, I'd like to keep that separate. I created #2070 to track the SourceReference refactorings.

… mapping instead of creation of the target reference

With this we can more easily go in the direction of using constructor to map into target beans.
@filiphr
filiphr force-pushed the target-reference-refactorings branch from e79fb45 to b122a8e Compare April 13, 2020 09:57
@filiphr
filiphr merged commit c58f80c into mapstruct:master Apr 13, 2020
@filiphr
filiphr deleted the target-reference-refactorings branch April 13, 2020 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TargetReference refactorings

2 participants