#2901: Fix @TargetType annotation on a @Condition annotated method for a Collection value

This commit is contained in:
Zegveld 2022-08-20 13:01:47 +02:00 committed by GitHub
parent 849085e026
commit 17997ef617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 1 deletions

View File

@ -60,7 +60,8 @@
<#macro handleLocalVarNullCheck needs_explicit_local_var>
<#if sourcePresenceCheckerReference??>
if ( <@includeModel object=sourcePresenceCheckerReference
targetPropertyName=ext.targetPropertyName/> ) {
targetType=ext.targetType
targetPropertyName=ext.targetPropertyName /> ) {
<#if needs_explicit_local_var>
<@includeModel object=nullCheckLocalVarType/> ${nullCheckLocalVarName} = <@lib.handleAssignment/>;
<#nested>

View File

@ -0,0 +1,23 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2901;
import java.util.List;
import org.mapstruct.Condition;
import org.mapstruct.Mapper;
import org.mapstruct.TargetType;
@Mapper
public interface ConditionWithTargetTypeOnCollectionMapper {
Target map(Source source);
@Condition
default boolean check(List<String> test, @TargetType Class<?> type) {
return type.isInstance( test );
}
}

View File

@ -0,0 +1,22 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2901;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;
/**
* @author Ben Zegveld
*/
@IssueKey( "2901" )
class Issue2901Test {
@ProcessorTest
@WithClasses( { Source.class, Target.class, ConditionWithTargetTypeOnCollectionMapper.class } )
void shouldCompile() {
}
}

View File

@ -0,0 +1,21 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2901;
import java.util.List;
public class Source {
private List<String> field;
public List<String> getField() {
return field;
}
public void setField(List<String> field) {
this.field = field;
}
}

View File

@ -0,0 +1,21 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2901;
import java.util.List;
public class Target {
private List<Integer> field;
public List<Integer> getField() {
return field;
}
public void setField(List<Integer> field) {
this.field = field;
}
}