-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
#3652 Inverse Inheritance possible for ignore-mappings without source #3675
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Bar.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
|
|
||
| package org.mapstruct.ap.test.bugs._3652; | ||
|
|
||
| public class Bar { | ||
|
|
||
| private int secret; | ||
| private int doesNotExistInFoo; | ||
|
|
||
| public int getSecret() { | ||
| return secret; | ||
| } | ||
|
|
||
| public void setSecret(int secret) { | ||
| this.secret = secret; | ||
| } | ||
|
|
||
| public int getDoesNotExistInFoo() { | ||
| return doesNotExistInFoo; | ||
| } | ||
|
|
||
| public void setDoesNotExistInFoo(int doesNotExistInFoo) { | ||
| this.doesNotExistInFoo = doesNotExistInFoo; | ||
| } | ||
|
|
||
| } |
21 changes: 21 additions & 0 deletions
21
processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Foo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
|
|
||
| package org.mapstruct.ap.test.bugs._3652; | ||
|
|
||
| public class Foo { | ||
|
|
||
| private int secret; | ||
|
|
||
| public int getSecret() { | ||
| return secret; | ||
| } | ||
|
|
||
| public void setSecret(int secret) { | ||
| this.secret = secret; | ||
| } | ||
|
|
||
| } |
24 changes: 24 additions & 0 deletions
24
processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/FooBarConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
|
|
||
| package org.mapstruct.ap.test.bugs._3652; | ||
|
|
||
| import org.mapstruct.InheritInverseConfiguration; | ||
| import org.mapstruct.MapperConfig; | ||
| import org.mapstruct.Mapping; | ||
| import org.mapstruct.MappingInheritanceStrategy; | ||
|
|
||
| @MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_ALL_FROM_CONFIG) | ||
| public interface FooBarConfig { | ||
|
|
||
| @Mapping(target = "doesNotExistInFoo", ignore = true) | ||
| @Mapping(target = "secret", ignore = true) | ||
| Bar toBar(Foo foo); | ||
|
|
||
| @InheritInverseConfiguration(name = "toBar") | ||
| Foo toFoo(Bar bar); | ||
|
|
||
| } |
21 changes: 21 additions & 0 deletions
21
processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/FooBarMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
|
|
||
| package org.mapstruct.ap.test.bugs._3652; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.factory.Mappers; | ||
|
|
||
| @Mapper(config = FooBarConfig.class) | ||
| public interface FooBarMapper { | ||
|
|
||
| FooBarMapper INSTANCE = Mappers.getMapper( FooBarMapper.class ); | ||
|
|
||
| Bar toBar(Foo foo); | ||
|
|
||
| Foo toFoo(Bar bar); | ||
|
|
||
| } |
35 changes: 35 additions & 0 deletions
35
processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Issue3652Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
|
|
||
| package org.mapstruct.ap.test.bugs._3652; | ||
|
|
||
| import org.mapstruct.ap.testutil.IssueKey; | ||
| import org.mapstruct.ap.testutil.ProcessorTest; | ||
| import org.mapstruct.ap.testutil.WithClasses; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @IssueKey("3652") | ||
| public class Issue3652Test { | ||
|
|
||
| @WithClasses({ | ||
| Bar.class, | ||
| Foo.class, | ||
| FooBarConfig.class, | ||
| FooBarMapper.class, | ||
| }) | ||
| @ProcessorTest | ||
| void ignoreMappingsWithoutSourceShouldBeInvertible() { | ||
| Bar bar = new Bar(); | ||
| bar.setSecret( 123 ); | ||
| bar.setDoesNotExistInFoo( 6 ); | ||
|
|
||
| Foo foo = FooBarMapper.INSTANCE.toFoo( bar ); | ||
|
|
||
| assertThat( foo.getSecret() ).isEqualTo( 0 ); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still curious why this was explicitly stated here. I tried looking at the history of this method, but did not find a hint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was curious too @zyberzebra. This looks like an ancient thing. The
MappingOptionswas calledMappingat some point. The rename was done in 7bee121.The line
isIgnored && sourceName == nullwas added first in 4d8bc29. And looking at that commit it seems like the logic was not ported properly, because prior to that we hadand after that we had
Things were quite different back then. We are now handling the target later and differently to back then, so the fix done by @Hypnagokali looks like spot on.