-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#159 support fluent setters with super types (e.g. lomboks @SuperBuilder
- Loading branch information
1 parent
e8b9e48
commit f822fdd
Showing
5 changed files
with
363 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
62 changes: 62 additions & 0 deletions
62
...org/mapstruct/intellij/inspection/UnmappedSuperBuilderTargetPropertiesInspectionTest.java
This file contains 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,62 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at https://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.intellij.inspection; | ||
|
||
import java.util.List; | ||
|
||
import com.intellij.codeInsight.intention.IntentionAction; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author Oliver Erhart | ||
*/ | ||
public class UnmappedSuperBuilderTargetPropertiesInspectionTest extends BaseInspectionTest { | ||
|
||
@NotNull | ||
@Override | ||
protected Class<UnmappedTargetPropertiesInspection> getInspection() { | ||
return UnmappedTargetPropertiesInspection.class; | ||
} | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
myFixture.copyFileToProject( | ||
"UnmappedSuperBuilderTargetPropertiesData.java", | ||
"org/example/data/UnmappedSuperBuilderTargetPropertiesData.java" | ||
); | ||
} | ||
|
||
public void testUnmappedSuperBuilderTargetProperties() { | ||
doTest(); | ||
String testName = getTestName( false ); | ||
List<IntentionAction> allQuickFixes = myFixture.getAllQuickFixes(); | ||
|
||
assertThat( allQuickFixes ) | ||
.extracting( IntentionAction::getText ) | ||
.as( "Intent Text" ) | ||
.containsExactly( | ||
"Ignore unmapped target property: 'testName'", | ||
"Add unmapped target property: 'testName'", | ||
"Ignore unmapped target property: 'moreTarget'", | ||
"Add unmapped target property: 'moreTarget'", | ||
"Ignore unmapped target property: 'moreTarget'", | ||
"Add unmapped target property: 'moreTarget'", | ||
"Ignore unmapped target property: 'testName'", | ||
"Add unmapped target property: 'testName'", | ||
"Ignore all unmapped target properties", | ||
"Ignore unmapped target property: 'testName'", | ||
"Add unmapped target property: 'testName'", | ||
"Ignore unmapped target property: 'moreTarget'", | ||
"Add unmapped target property: 'moreTarget'" | ||
); | ||
|
||
allQuickFixes.forEach( myFixture::launchAction ); | ||
myFixture.checkResultByFile( testName + "_after.java" ); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
testData/inspection/UnmappedSuperBuilderTargetProperties.java
This file contains 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,64 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at https://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import org.mapstruct.Context; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.MappingTarget; | ||
import org.mapstruct.Mappings; | ||
import org.example.data.UnmappedFluentTargetPropertiesData.Target; | ||
import org.example.data.UnmappedFluentTargetPropertiesData.Source; | ||
|
||
interface NotMapStructMapper { | ||
|
||
Target map(Source source); | ||
} | ||
|
||
@Mapper | ||
interface SingleMappingsMapper { | ||
|
||
@Mappings({ | ||
@Mapping(target = "moreTarget", source = "moreSource") | ||
}) | ||
Target <warning descr="Unmapped target property: testName">map</warning>(Source source); | ||
} | ||
|
||
@Mapper | ||
interface SingleMappingMapper { | ||
|
||
@Mapping(target = "testName", source = "name") | ||
Target <warning descr="Unmapped target property: moreTarget">map</warning>(Source source); | ||
} | ||
|
||
@Mapper | ||
interface NoMappingMapper { | ||
|
||
Target <warning descr="Unmapped target properties: moreTarget, testName">map</warning>(Source source); | ||
|
||
@org.mapstruct.InheritInverseConfiguration | ||
Source reverse(Target target); | ||
} | ||
|
||
@Mapper | ||
interface AllMappingMapper { | ||
|
||
@Mapping(target = "testName", source = "name") | ||
@Mapping(target = "moreTarget", source = "moreSource") | ||
Target mapWithAllMapping(Source source); | ||
} | ||
|
||
@Mapper | ||
interface UpdateMapper { | ||
|
||
@Mapping(target = "moreTarget", source = "moreSource") | ||
void <warning descr="Unmapped target property: testName">update</warning>(@MappingTarget Target target, Source source); | ||
} | ||
|
||
@Mapper | ||
interface MultiSourceUpdateMapper { | ||
|
||
void <warning descr="Unmapped target property: moreTarget">update</warning>(@MappingTarget Target moreTarget, Source source, String testName, @Context String matching); | ||
} |
133 changes: 133 additions & 0 deletions
133
testData/inspection/UnmappedSuperBuilderTargetPropertiesData.java
This file contains 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,133 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at https://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.example.data; | ||
|
||
public class UnmappedFluentTargetPropertiesData { | ||
public static class Source { | ||
|
||
private String name; | ||
private String matching; | ||
private String moreSource; | ||
private String onlyInSource; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getMatching() { | ||
return matching; | ||
} | ||
|
||
public void setMatching(String matching) { | ||
this.matching = matching; | ||
} | ||
|
||
public String getMoreSource() { | ||
return moreSource; | ||
} | ||
|
||
public void setMoreSource(String moreSource) { | ||
this.moreSource = moreSource; | ||
} | ||
|
||
public String getOnlyInSource() { | ||
return onlyInSource; | ||
} | ||
|
||
public void setOnlyInSource(String onlyInSource) { | ||
this.onlyInSource = onlyInSource; | ||
} | ||
} | ||
|
||
public static class Target { | ||
|
||
private String testName; | ||
private String matching; | ||
private String moreTarget; | ||
|
||
protected Target(TargetBuilder<?, ?> b) { | ||
this.testName = b.testName; | ||
this.matching = b.matching; | ||
this.moreTarget = b.moreTarget; | ||
} | ||
|
||
public static TargetBuilder<?, ?> builder() { | ||
return new TargetBuilderImpl(); | ||
} | ||
|
||
public String getTestName() { | ||
return this.testName; | ||
} | ||
|
||
public String getMatching() { | ||
return this.matching; | ||
} | ||
|
||
public String getMoreTarget() { | ||
return this.moreTarget; | ||
} | ||
|
||
public void setTestName(String testName) { | ||
this.testName = testName; | ||
} | ||
|
||
public void setMatching(String matching) { | ||
this.matching = matching; | ||
} | ||
|
||
public void setMoreTarget(String moreTarget) { | ||
this.moreTarget = moreTarget; | ||
} | ||
|
||
public static abstract class TargetBuilder<C extends Target, B extends TargetBuilder<C, B>> { | ||
private String testName; | ||
private String matching; | ||
private String moreTarget; | ||
|
||
public B testName(String testName) { | ||
this.testName = testName; | ||
return self(); | ||
} | ||
|
||
public B matching(String matching) { | ||
this.matching = matching; | ||
return self(); | ||
} | ||
|
||
public B moreTarget(String moreTarget) { | ||
this.moreTarget = moreTarget; | ||
return self(); | ||
} | ||
|
||
protected abstract B self(); | ||
|
||
public abstract C build(); | ||
|
||
public String toString() { | ||
return "Target.TargetBuilder(testName=" + this.testName + ", matching=" + this.matching + ", moreTarget=" + | ||
this.moreTarget + ")"; | ||
} | ||
} | ||
|
||
private static final class TargetBuilderImpl extends TargetBuilder<Target, TargetBuilderImpl> { | ||
private TargetBuilderImpl() { | ||
} | ||
|
||
protected TargetBuilderImpl self() { | ||
return this; | ||
} | ||
|
||
public Target build() { | ||
return new Target( this ); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.