Skip to content

Commit b3a780a

Browse files
committed
#241 Target dot should not be treated as mapped more than once
1 parent f2abfa0 commit b3a780a

File tree

3 files changed

+119
-1
lines changed

3 files changed

+119
-1
lines changed

src/main/java/org/mapstruct/intellij/inspection/TargetPropertyMappedMoreThanOnceInspection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private static void handleMappingAnnotation(PsiAnnotation psiAnnotation,
149149
PsiAnnotationMemberValue value = psiAnnotation.findDeclaredAttributeValue( "target" );
150150
if (value != null) {
151151
String target = getStringAttributeValue( value );
152-
if (target != null) {
152+
if (target != null && !target.equals( "." )) {
153153
problemMap.computeIfAbsent( target, k -> new ArrayList<>() ).add( value );
154154
}
155155
}

testData/inspection/TargetPropertyMappedMoreThanOnce.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,57 @@ public void setLastName(String lastName) {
4444
}
4545
}
4646

47+
class ComplexSource {
48+
private Source source;
49+
private Target target;
50+
51+
public Source getSource() {
52+
return source;
53+
}
54+
55+
public void setSource(Source source) {
56+
this.source = source;
57+
}
58+
59+
public Target getTarget() {
60+
return target;
61+
}
62+
63+
public void setTarget(Target target) {
64+
this.target = target;
65+
}
66+
}
67+
68+
class ComplexTarget {
69+
private String testName;
70+
private String name;
71+
private String lastName;
72+
73+
public String getTestName() {
74+
return testName;
75+
}
76+
77+
public void setTestName(String testName) {
78+
this.testName = testName;
79+
}
80+
81+
public String getName() {
82+
return name;
83+
}
84+
85+
public void setName(String name) {
86+
this.name = name;
87+
}
88+
89+
public String getLastName() {
90+
return lastName;
91+
}
92+
93+
public void setLastName(String lastName) {
94+
this.lastName = lastName;
95+
}
96+
}
97+
4798
@Retention(RetentionPolicy.CLASS)
4899
@Mapping(target = "testName", source = "name")
49100
@interface MyMappingAnnotation {
@@ -94,4 +145,12 @@ interface TargetMappedMoreThanOnceByMyMappingAnnotationAndMappingsAnnotationMapp
94145
})
95146
<error descr="Target property 'testName' must not be mapped more than once.">@MyMappingAnnotation</error>
96147
Target map(Source source);
148+
}
149+
150+
@Mapper
151+
interface MultipleTargetDotMapper {
152+
153+
@Mapping(target = ".", source = "source")
154+
@Mapping(target = ".", source = "target")
155+
ComplexTarget map(ComplexSource source);
97156
}

testData/inspection/TargetPropertyMappedMoreThanOnce_after.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,57 @@ public void setLastName(String lastName) {
4444
}
4545
}
4646

47+
class ComplexSource {
48+
private Source source;
49+
private Target target;
50+
51+
public Source getSource() {
52+
return source;
53+
}
54+
55+
public void setSource(Source source) {
56+
this.source = source;
57+
}
58+
59+
public Target getTarget() {
60+
return target;
61+
}
62+
63+
public void setTarget(Target target) {
64+
this.target = target;
65+
}
66+
}
67+
68+
class ComplexTarget {
69+
private String testName;
70+
private String name;
71+
private String lastName;
72+
73+
public String getTestName() {
74+
return testName;
75+
}
76+
77+
public void setTestName(String testName) {
78+
this.testName = testName;
79+
}
80+
81+
public String getName() {
82+
return name;
83+
}
84+
85+
public void setName(String name) {
86+
this.name = name;
87+
}
88+
89+
public String getLastName() {
90+
return lastName;
91+
}
92+
93+
public void setLastName(String lastName) {
94+
this.lastName = lastName;
95+
}
96+
}
97+
4798
@Retention(RetentionPolicy.CLASS)
4899
@Mapping(target = "testName", source = "name")
49100
@interface MyMappingAnnotation {
@@ -90,4 +141,12 @@ interface TargetMappedMoreThanOnceByMyMappingAnnotationAndMappingsAnnotationMapp
90141
})
91142
@MyMappingAnnotation
92143
Target map(Source source);
144+
}
145+
146+
@Mapper
147+
interface MultipleTargetDotMapper {
148+
149+
@Mapping(target = ".", source = "source")
150+
@Mapping(target = ".", source = "target")
151+
ComplexTarget map(ComplexSource source);
93152
}

0 commit comments

Comments
 (0)