-
-
Notifications
You must be signed in to change notification settings - Fork 1k
#2945 Stabilise top level imports #2973
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 1 commit
Commits
Show all changes
2 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
Next
Next commit
#2945 Stabilise top level imports
Make sure that GeneratedType always gets the imported types from a Type before adding them
- Loading branch information
commit 7ba027fc756a99f78b1e6cc4ede8dc45419f86af
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
22 changes: 22 additions & 0 deletions
22
processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/Issue2945Mapper.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,22 @@ | ||
| /* | ||
| * 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._2945; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.ap.test.bugs._2945._target.Target; | ||
| import org.mapstruct.ap.test.bugs._2945.source.Source; | ||
| import org.mapstruct.factory.Mappers; | ||
|
|
||
| /** | ||
| * @author Filip Hrisafov | ||
| */ | ||
| @Mapper | ||
| public interface Issue2945Mapper { | ||
|
|
||
| Issue2945Mapper INSTANCE = Mappers.getMapper( Issue2945Mapper.class ); | ||
|
|
||
| Target map(Source source); | ||
| } |
35 changes: 35 additions & 0 deletions
35
processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/Issue2945Test.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._2945; | ||
|
|
||
| import org.mapstruct.ap.test.bugs._2945._target.EnumHolder; | ||
| import org.mapstruct.ap.test.bugs._2945._target.Target; | ||
| import org.mapstruct.ap.test.bugs._2945.source.Source; | ||
| 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("2945") | ||
| @WithClasses({ | ||
| EnumHolder.class, | ||
| Issue2945Mapper.class, | ||
| Source.class, | ||
| Target.class, | ||
| }) | ||
| class Issue2945Test { | ||
|
|
||
| @ProcessorTest | ||
| void shouldCompile() { | ||
| Target target = Issue2945Mapper.INSTANCE.map( new Source( "VALUE_1" ) ); | ||
|
|
||
| assertThat( target.getProperty() ).isEqualTo( EnumHolder.Property.VALUE_1 ); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/_target/EnumHolder.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,13 @@ | ||
| /* | ||
| * 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._2945._target; | ||
|
|
||
| public class EnumHolder { | ||
| public enum Property { | ||
| VALUE_1, | ||
| VALUE_2; | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/_target/Target.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,18 @@ | ||
| /* | ||
| * 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._2945._target; | ||
|
|
||
| public class Target { | ||
| private EnumHolder.Property property; | ||
|
|
||
| public EnumHolder.Property getProperty() { | ||
| return property; | ||
| } | ||
|
|
||
| public void setProperty(EnumHolder.Property property) { | ||
| this.property = property; | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/source/Source.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,22 @@ | ||
| /* | ||
| * 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._2945.source; | ||
|
|
||
| /** | ||
| * @author Filip Hrisafov | ||
| */ | ||
| public class Source { | ||
|
|
||
| private final String property; | ||
|
|
||
| public Source(String property) { | ||
| this.property = property; | ||
| } | ||
|
|
||
| public String getProperty() { | ||
| return property; | ||
| } | ||
| } |
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.
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.
ok.. how could this work in the first place? Now we don't add typeToAdd itself, but the required imported types..
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.
Have a look at the
Typeimplementation. We are a bit smart there when we need to do an import and only use theTopLevel.Nestedfor nested. There is a complex logic for computing whether we need to import a type or not.When I did the initial work for this I changed a lot of places where we were adding types to actually return
Type#getImportedTypes, but apparently this is not everywhere (considering the bug reports we've been receiving)