-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Feature/2663 #3007
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
Feature/2663 #3007
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
06eec69
#2377 Reproducal
filiphr b7306d2
#2663 Updated the 2337 reproducal to be more correct and moved it.
cc9228f
#2663: correctly change it into being a reproduction of the issue.
fda83f8
Merge branch 'main' into feature/2663
7fb8e6f
#2663: replace generics during 2-step mapping to correctly search for…
504a48b
fix checkstyle
4e82f77
#2663: lessen code for generic replacement in type.
357fde7
#2663: do not replace generics if newType is null.
d54a59b
#2663: do not replace generics with primitive, but boxed version.
23282a1
#2663: added a nested example.
6275d70
#2663: make javadoc complete for the new method in Type. Also format …
4433b4e
Merge branch 'main' into feature/2663
1a0ac3e
#3163: Type.isAssignableTo other parameter is now stripped of wildcar…
fd3951a
#3163: Generated annotation removed from test code.
9886dd5
Revert "#3163: Generated annotation removed from test code."
filiphr 3509571
Revert "#3163: Type.isAssignableTo other parameter is now stripped of…
filiphr 32f087c
Polish
filiphr 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
31 changes: 31 additions & 0 deletions
31
processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Issue2663Mapper.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,31 @@ | ||
| /* | ||
| * 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._2663; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.factory.Mappers; | ||
|
|
||
| /** | ||
| * @author Filip Hrisafov | ||
| */ | ||
| @Mapper( uses = NullableHelper.class ) | ||
| public interface Issue2663Mapper { | ||
|
|
||
| Issue2663Mapper INSTANCE = Mappers.getMapper( Issue2663Mapper.class ); | ||
|
|
||
| Request map(RequestDto dto); | ||
|
|
||
| default JsonNullable<Request.ChildRequest> mapJsonNullableChildren(JsonNullable<RequestDto.ChildRequestDto> dtos) { | ||
| if ( dtos.isPresent() ) { | ||
| return JsonNullable.of( mapChild( dtos.get() ) ); | ||
| } | ||
| else { | ||
| return JsonNullable.undefined(); | ||
| } | ||
| } | ||
|
|
||
| Request.ChildRequest mapChild(RequestDto.ChildRequestDto dto); | ||
| } |
47 changes: 47 additions & 0 deletions
47
processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Issue2663Test.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,47 @@ | ||
| /* | ||
| * 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._2663; | ||
|
|
||
| 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; | ||
|
|
||
| /** | ||
| * @author Filip Hrisafov | ||
| */ | ||
| @IssueKey( "2663" ) | ||
| @WithClasses({ | ||
| Issue2663Mapper.class, | ||
| JsonNullable.class, | ||
| Nullable.class, | ||
| NullableHelper.class, | ||
| Request.class, | ||
| RequestDto.class | ||
| }) | ||
| public class Issue2663Test { | ||
|
|
||
| @ProcessorTest | ||
| public void shouldUnpackGenericsCorrectly() { | ||
| RequestDto dto = new RequestDto(); | ||
| dto.setName( JsonNullable.of( "Tester" ) ); | ||
|
|
||
| Request request = Issue2663Mapper.INSTANCE.map( dto ); | ||
|
|
||
| assertThat( request.getName() ) | ||
| .extracting( Nullable::get ) | ||
| .isEqualTo( "Tester" ); | ||
|
|
||
| dto.setName( JsonNullable.undefined() ); | ||
|
|
||
| request = Issue2663Mapper.INSTANCE.map( dto ); | ||
|
|
||
| assertThat( request.getName() ) | ||
| .extracting( Nullable::isPresent ) | ||
| .isEqualTo( false ); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/JsonNullable.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,44 @@ | ||
| /* | ||
| * 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._2663; | ||
|
|
||
| import java.util.NoSuchElementException; | ||
|
|
||
| /** | ||
| * @author Filip Hrisafov | ||
| */ | ||
| public class JsonNullable<T> { | ||
|
|
||
| private static final JsonNullable<?> UNDEFINED = new JsonNullable<>( null, false ); | ||
|
|
||
| private final T value; | ||
| private final boolean present; | ||
|
|
||
| private JsonNullable(T value, boolean present) { | ||
| this.value = value; | ||
| this.present = present; | ||
| } | ||
|
|
||
| public T get() { | ||
| if (!present) { | ||
| throw new NoSuchElementException("Value is undefined"); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| public boolean isPresent() { | ||
| return present; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public static <T> JsonNullable<T> undefined() { | ||
| return (JsonNullable<T>) UNDEFINED; | ||
| } | ||
|
|
||
| public static <T> JsonNullable<T> of(T value) { | ||
| return new JsonNullable<>( value, true ); | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Nullable.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,45 @@ | ||
| /* | ||
| * 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._2663; | ||
|
|
||
| import java.util.NoSuchElementException; | ||
|
|
||
| /** | ||
| * @author Filip Hrisafov | ||
| */ | ||
| public class Nullable<T> { | ||
|
|
||
| @SuppressWarnings("rawtypes") | ||
| private static final Nullable UNDEFINED = new Nullable<>( null, false ); | ||
|
|
||
| private final T value; | ||
| private final boolean present; | ||
|
|
||
| private Nullable(T value, boolean present) { | ||
| this.value = value; | ||
| this.present = present; | ||
| } | ||
|
|
||
| public T get() { | ||
| if (!present) { | ||
| throw new NoSuchElementException("Value is undefined"); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| public boolean isPresent() { | ||
| return present; | ||
| } | ||
|
|
||
| public static <T> Nullable<T> of(T value) { | ||
| return new Nullable<>( value, true ); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public static <T> Nullable<T> undefined() { | ||
| return (Nullable<T>) UNDEFINED; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/NullableHelper.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,23 @@ | ||
| /* | ||
| * 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._2663; | ||
|
|
||
| /** | ||
| * @author Filip Hrisafov | ||
| */ | ||
| public class NullableHelper { | ||
|
|
||
| private NullableHelper() { | ||
| // Helper class | ||
| } | ||
|
|
||
| public static <T> Nullable<T> jsonNullableToNullable(JsonNullable<T> jsonNullable) { | ||
| if ( jsonNullable.isPresent() ) { | ||
| return Nullable.of( jsonNullable.get() ); | ||
| } | ||
| return Nullable.undefined(); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Request.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,44 @@ | ||
| /* | ||
| * 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._2663; | ||
|
|
||
| /** | ||
| * @author Filip Hrisafov | ||
| */ | ||
| public class Request { | ||
|
|
||
| private Nullable<String> name = Nullable.undefined(); | ||
| private Nullable<ChildRequest> child = Nullable.undefined(); | ||
|
|
||
| public Nullable<String> getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void setName(Nullable<String> name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public Nullable<ChildRequest> getChild() { | ||
| return child; | ||
| } | ||
|
|
||
| public void setChild(Nullable<ChildRequest> child) { | ||
| this.child = child; | ||
| } | ||
|
|
||
| public static class ChildRequest { | ||
|
|
||
| private Nullable<String> name = Nullable.undefined(); | ||
|
|
||
| public Nullable<String> getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void setName(Nullable<String> name) { | ||
| this.name = name; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.