-
-
Notifications
You must be signed in to change notification settings - Fork 41
Add generics support #273
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
Open
maybetm
wants to merge
1
commit into
mapstruct:main
Choose a base branch
from
maybetm:add_generics_support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add generics support #273
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -205,16 +205,16 @@ PsiType resolvedType() { | |
| PsiElement element = resolve(); | ||
|
|
||
| if ( element instanceof PsiMethod psiMethod ) { | ||
| return firstParameterPsiType( psiMethod ); | ||
| return substituteMemberType( firstParameterPsiType( psiMethod ) ); | ||
| } | ||
| else if ( element instanceof PsiParameter psiParameter ) { | ||
| return psiParameter.getType(); | ||
| } | ||
|
Comment on lines
210
to
212
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is it with PsiParameter (constructor target parameter)? |
||
| else if ( element instanceof PsiRecordComponent psiRecordComponent ) { | ||
| return psiRecordComponent.getType(); | ||
| return substituteMemberType( psiRecordComponent.getType() ); | ||
| } | ||
| else if ( element instanceof PsiField psiField ) { | ||
| return psiField.getType(); | ||
| return substituteMemberType( psiField.getType() ); | ||
| } | ||
|
|
||
| return null; | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -5,16 +5,15 @@ | |
| */ | ||
| package org.mapstruct.intellij; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase; | ||
| import com.intellij.openapi.util.text.StringUtil; | ||
| import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess; | ||
| import com.intellij.testFramework.LightProjectDescriptor; | ||
| import com.intellij.testFramework.PsiTestUtil; | ||
| import com.intellij.util.PathUtil; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| /** | ||
| * Base completion test case for MapStruct. | ||
| * | ||
|
|
@@ -29,7 +28,13 @@ protected void setUp() throws Exception { | |
| super.setUp(); | ||
| final String mapstructLibPath = PathUtil.toSystemIndependentName( new File( BUILD_LIBS_DIRECTORY ) | ||
| .getAbsolutePath() ); | ||
| VfsRootAccess.allowRootAccess( getTestRootDisposable(), mapstructLibPath ); | ||
|
|
||
| allowAccessToDirsIfExists( | ||
| BUILD_LIBS_DIRECTORY, | ||
| "testData", | ||
| "build/test-libs" | ||
| ); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you changes this code? I think this could break building on other OS (Windows) |
||
| PsiTestUtil.addLibrary( | ||
| myFixture.getProjectDisposable(), | ||
| myFixture.getModule(), | ||
|
|
||
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
56 changes: 56 additions & 0 deletions
56
testData/mapping/GenericCarWrapperSourceAutoCompleteAfterCar.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,56 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at https://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package org.mapstruct.ap.test.complex; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.Mapping; | ||
|
|
||
| @Mapper | ||
| public interface GenericCarWrapperMapper { | ||
|
|
||
| @Mapping(target = "id", source = "wrapper.car.<caret>winCode") | ||
| CarEntity toCarDto(CarWrapper<Car> wrapper); | ||
| } | ||
|
|
||
| class CarEntity { | ||
|
|
||
| private String id; | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(String id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class Car { | ||
|
|
||
| private String winCode; | ||
|
|
||
| public String getWinCode() { | ||
| return winCode; | ||
| } | ||
|
|
||
| public void setWinCode(String winCode) { | ||
| this.winCode = winCode; | ||
| } | ||
| } | ||
|
|
||
| class CarWrapper<T> { | ||
|
|
||
| private T car; | ||
|
|
||
| public T getCar() { | ||
| return car; | ||
| } | ||
|
|
||
| public void setCar(T car) { | ||
| this.car = car; | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
testData/mapping/GenericCarWrapperTargetAutoCompleteAfterCar.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,56 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at https://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package org.mapstruct.ap.test.complex; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.Mapping; | ||
| import org.mapstruct.MappingTarget; | ||
|
|
||
| @Mapper | ||
| public interface GenericCarWrapperTargetMapper { | ||
|
|
||
| @Mapping(source = "id", target = "wrapper.car.<caret>winCode") | ||
| void update(@MappingTarget CarWrapper<Car> wrapper, CarEntity entity); | ||
| } | ||
|
|
||
| class CarEntity { | ||
|
|
||
| private String id; | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(String id) { | ||
| this.id = id; | ||
| } | ||
| } | ||
|
|
||
| class Car { | ||
|
|
||
| private String winCode; | ||
|
|
||
| public String getWinCode() { | ||
| return winCode; | ||
| } | ||
|
|
||
| public void setWinCode(String winCode) { | ||
| this.winCode = winCode; | ||
| } | ||
| } | ||
|
|
||
| class CarWrapper<T> { | ||
|
|
||
| private T car; | ||
|
|
||
| public T getCar() { | ||
| return car; | ||
| } | ||
|
|
||
| public void setCar(T car) { | ||
| this.car = car; | ||
| } | ||
| } |
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.
What if the source is named e.g.
entity.id?