-
-
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
base: main
Are you sure you want to change the base?
Add generics support #273
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
|
|
||
| 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)
Author
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. I added this specifically to ensure the tests run correctly on Windows. Without these configurations, the testing framework is unable to access packages |
||
| PsiTestUtil.addLibrary( | ||
| myFixture.getProjectDisposable(), | ||
| myFixture.getModule(), | ||
|
|
||
| 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; | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } |
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?