Skip to content

Commit 980acba

Browse files
authored
mapstruct#971 Make sure that an Iterable or Map MapingMethod are equal if their source parameters are from the same type
1 parent 9a53775 commit 980acba

9 files changed

Lines changed: 316 additions & 2 deletions

File tree

processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ public boolean equals(Object obj) {
304304
}
305305

306306
for ( int i = 0; i < getSourceParameters().size(); i++ ) {
307+
if ( !getSourceParameters().get( i ).getType().equals( other.getSourceParameters().get( i ).getType() ) ) {
308+
return false;
309+
}
307310
List<Type> thisTypeParameters = getSourceParameters().get( i ).getType().getTypeParameters();
308311
List<Type> otherTypeParameters = other.getSourceParameters().get( i ).getType().getTypeParameters();
309312

processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,14 @@ public boolean equals(Object obj) {
319319
}
320320

321321
for ( int i = 0; i < getSourceParameters().size(); i++ ) {
322-
if ( !getSourceParameters().get( i ).getType().getTypeParameters().get( 0 )
323-
.equals( other.getSourceParameters().get( i ).getType().getTypeParameters().get( 0 ) ) ) {
322+
if ( !getSourceParameters().get( i ).getType().equals( other.getSourceParameters().get( i ).getType() ) ) {
323+
return false;
324+
}
325+
326+
List<Type> thisTypeParameters = getSourceParameters().get( i ).getType().getTypeParameters();
327+
List<Type> otherTypeParameters = other.getSourceParameters().get( i ).getType().getTypeParameters();
328+
329+
if ( !thisTypeParameters.equals( otherTypeParameters ) ) {
324330
return false;
325331
}
326332
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/)
3+
* and/or other contributors as indicated by the @authors tag. See the
4+
* copyright.txt file in the distribution for a full listing of all
5+
* contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.mapstruct.ap.test.bugs._971;
20+
21+
import java.util.List;
22+
23+
/**
24+
*
25+
* @author Filip Hrisafov
26+
*/
27+
public class CollectionSource {
28+
29+
private List<Integer> integers;
30+
private List<Integer> integersCollection;
31+
32+
33+
public List<Integer> getIntegers() {
34+
return integers;
35+
}
36+
37+
public void setIntegers(List<Integer> integers) {
38+
this.integers = integers;
39+
}
40+
41+
public List<Integer> getIntegersCollection() {
42+
return integersCollection;
43+
}
44+
45+
public void setIntegersCollection(List<Integer> integersCollection) {
46+
this.integersCollection = integersCollection;
47+
}
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/)
3+
* and/or other contributors as indicated by the @authors tag. See the
4+
* copyright.txt file in the distribution for a full listing of all
5+
* contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.mapstruct.ap.test.bugs._971;
20+
21+
import java.util.Collection;
22+
import java.util.List;
23+
24+
/**
25+
*
26+
* @author Filip Hrisafov
27+
*/
28+
public class CollectionTarget {
29+
30+
private List<String> integers;
31+
private Collection<String> integersCollection;
32+
33+
public List<String> getIntegers() {
34+
return integers;
35+
}
36+
37+
public void setIntegers(List<String> integers) {
38+
this.integers = integers;
39+
}
40+
41+
public Collection<String> getIntegersCollection() {
42+
return integersCollection;
43+
}
44+
45+
public void setIntegersCollection(Collection<String> integersCollection) {
46+
this.integersCollection = integersCollection;
47+
}
48+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/)
3+
* and/or other contributors as indicated by the @authors tag. See the
4+
* copyright.txt file in the distribution for a full listing of all
5+
* contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.mapstruct.ap.test.bugs._971;
20+
21+
import org.mapstruct.Mapper;
22+
import org.mapstruct.factory.Mappers;
23+
24+
/**
25+
*
26+
* @author Filip Hrisafov
27+
*/
28+
@Mapper
29+
public interface Issue971CollectionMapper {
30+
31+
Issue971CollectionMapper INSTANCE = Mappers.getMapper( Issue971CollectionMapper.class );
32+
33+
CollectionSource mapTargetToSource(CollectionTarget source);
34+
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/)
3+
* and/or other contributors as indicated by the @authors tag. See the
4+
* copyright.txt file in the distribution for a full listing of all
5+
* contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.mapstruct.ap.test.bugs._971;
20+
21+
import org.mapstruct.Mapper;
22+
import org.mapstruct.factory.Mappers;
23+
24+
/**
25+
*
26+
* @author Filip Hrisafov
27+
*/
28+
@Mapper
29+
public interface Issue971MapMapper {
30+
31+
Issue971MapMapper INSTANCE = Mappers.getMapper( Issue971MapMapper.class );
32+
33+
MapSource mapTargetToSource(MapTarget source);
34+
35+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/)
3+
* and/or other contributors as indicated by the @authors tag. See the
4+
* copyright.txt file in the distribution for a full listing of all
5+
* contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.mapstruct.ap.test.bugs._971;
20+
21+
import org.junit.Test;
22+
import org.junit.runner.RunWith;
23+
import org.mapstruct.ap.testutil.IssueKey;
24+
import org.mapstruct.ap.testutil.WithClasses;
25+
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
26+
27+
/**
28+
* @author Filip Hrisafov
29+
*
30+
*/
31+
@RunWith(AnnotationProcessorTestRunner.class)
32+
@IssueKey("971")
33+
public class Issue971Test {
34+
35+
@Test
36+
@WithClasses({ CollectionSource.class, CollectionTarget.class, Issue971CollectionMapper.class })
37+
public void shouldCompileForCollections() { }
38+
39+
@Test
40+
@WithClasses({ MapSource.class, MapTarget.class, Issue971MapMapper.class })
41+
public void shouldCompileForMaps() { }
42+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/)
3+
* and/or other contributors as indicated by the @authors tag. See the
4+
* copyright.txt file in the distribution for a full listing of all
5+
* contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.mapstruct.ap.test.bugs._971;
20+
21+
import java.util.Map;
22+
23+
/**
24+
*
25+
* @author Filip Hrisafov
26+
*/
27+
public class MapSource {
28+
29+
private Map<Integer, String> integersSortedMap;
30+
private Map<Integer, String> integersBaseMap;
31+
32+
33+
public Map<Integer, String> getIntegersSortedMap() {
34+
return integersSortedMap;
35+
}
36+
37+
public void setIntegersSortedMap(Map<Integer, String> integersSortedMap) {
38+
this.integersSortedMap = integersSortedMap;
39+
}
40+
41+
public Map<Integer, String> getIntegersBaseMap() {
42+
return integersBaseMap;
43+
}
44+
45+
public void setIntegersBaseMap(Map<Integer, String> integersBaseMap) {
46+
this.integersBaseMap = integersBaseMap;
47+
}
48+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/)
3+
* and/or other contributors as indicated by the @authors tag. See the
4+
* copyright.txt file in the distribution for a full listing of all
5+
* contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.mapstruct.ap.test.bugs._971;
20+
21+
import java.util.Map;
22+
import java.util.SortedMap;
23+
24+
/**
25+
*
26+
* @author Filip Hrisafov
27+
*/
28+
public class MapTarget {
29+
30+
private SortedMap<String, Integer> integersSortedMap;
31+
private Map<String, Integer> integersBaseMap;
32+
33+
34+
public SortedMap<String, Integer> getIntegersSortedMap() {
35+
return integersSortedMap;
36+
}
37+
38+
public void setIntegersSortedMap(SortedMap<String, Integer> integersSortedMap) {
39+
this.integersSortedMap = integersSortedMap;
40+
}
41+
42+
public Map<String, Integer> getIntegersBaseMap() {
43+
return integersBaseMap;
44+
}
45+
46+
public void setIntegersBaseMap(Map<String, Integer> integersBaseMap) {
47+
this.integersBaseMap = integersBaseMap;
48+
}
49+
}

0 commit comments

Comments
 (0)