Skip to content

Commit 17997ef

Browse files
authored
#2901: Fix @TargetType annotation on a @Condition annotated method for a Collection value
1 parent 849085e commit 17997ef

File tree

5 files changed

+89
-1
lines changed

5 files changed

+89
-1
lines changed

processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
<#macro handleLocalVarNullCheck needs_explicit_local_var>
6161
<#if sourcePresenceCheckerReference??>
6262
if ( <@includeModel object=sourcePresenceCheckerReference
63-
targetPropertyName=ext.targetPropertyName/> ) {
63+
targetType=ext.targetType
64+
targetPropertyName=ext.targetPropertyName /> ) {
6465
<#if needs_explicit_local_var>
6566
<@includeModel object=nullCheckLocalVarType/> ${nullCheckLocalVarName} = <@lib.handleAssignment/>;
6667
<#nested>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.ap.test.bugs._2901;
7+
8+
import java.util.List;
9+
10+
import org.mapstruct.Condition;
11+
import org.mapstruct.Mapper;
12+
import org.mapstruct.TargetType;
13+
14+
@Mapper
15+
public interface ConditionWithTargetTypeOnCollectionMapper {
16+
17+
Target map(Source source);
18+
19+
@Condition
20+
default boolean check(List<String> test, @TargetType Class<?> type) {
21+
return type.isInstance( test );
22+
}
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.ap.test.bugs._2901;
7+
8+
import org.mapstruct.ap.testutil.IssueKey;
9+
import org.mapstruct.ap.testutil.ProcessorTest;
10+
import org.mapstruct.ap.testutil.WithClasses;
11+
12+
/**
13+
* @author Ben Zegveld
14+
*/
15+
@IssueKey( "2901" )
16+
class Issue2901Test {
17+
18+
@ProcessorTest
19+
@WithClasses( { Source.class, Target.class, ConditionWithTargetTypeOnCollectionMapper.class } )
20+
void shouldCompile() {
21+
}
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.ap.test.bugs._2901;
7+
8+
import java.util.List;
9+
10+
public class Source {
11+
12+
private List<String> field;
13+
14+
public List<String> getField() {
15+
return field;
16+
}
17+
18+
public void setField(List<String> field) {
19+
this.field = field;
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.ap.test.bugs._2901;
7+
8+
import java.util.List;
9+
10+
public class Target {
11+
12+
private List<Integer> field;
13+
14+
public List<Integer> getField() {
15+
return field;
16+
}
17+
18+
public void setField(List<Integer> field) {
19+
this.field = field;
20+
}
21+
}

0 commit comments

Comments
 (0)