#2882: target type is now correctly passed on through the MethodReferencePresenceCheck to the MethodReference.

This commit is contained in:
Ben Zegveld 2022-06-09 22:36:47 +02:00 committed by Filip Hrisafov
parent 07d144ebd1
commit 88745d151e
4 changed files with 37 additions and 2 deletions

View File

@ -6,4 +6,5 @@
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MethodReferencePresenceCheck" --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MethodReferencePresenceCheck" -->
<@includeModel object=methodReference/> <@includeModel object=methodReference
targetType=ext.targetType/>

View File

@ -15,7 +15,8 @@
--> -->
<#macro handleSourceReferenceNullCheck> <#macro handleSourceReferenceNullCheck>
<#if sourcePresenceCheckerReference??> <#if sourcePresenceCheckerReference??>
if ( <@includeModel object=sourcePresenceCheckerReference /> ) { if ( <@includeModel object=sourcePresenceCheckerReference
targetType=ext.targetType/> ) {
<#nested> <#nested>
} }
<@elseDefaultAssignment/> <@elseDefaultAssignment/>

View File

@ -50,6 +50,12 @@ public class ConditionalMappingTest {
assertThat( employee.getName() ).isNull(); assertThat( employee.getName() ).isNull();
} }
@IssueKey( "2882" )
@ProcessorTest
@WithClasses( { ConditionalMethodWithTargetType.class } )
public void conditionalMethodWithTargetTypeShouldCompile() {
}
@ProcessorTest @ProcessorTest
@WithClasses({ @WithClasses({
ConditionalMethodAndBeanPresenceCheckMapper.class ConditionalMethodAndBeanPresenceCheckMapper.class

View File

@ -0,0 +1,27 @@
/*
* 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.conditional.basic;
import org.mapstruct.Condition;
import org.mapstruct.Mapper;
import org.mapstruct.TargetType;
import org.mapstruct.factory.Mappers;
/**
* @author Ben Zegveld
*/
@Mapper
public interface ConditionalMethodWithTargetType {
ConditionalMethodWithTargetType INSTANCE = Mappers.getMapper( ConditionalMethodWithTargetType.class );
BasicEmployee map(BasicEmployeeDto employee);
@Condition
default boolean isNotBlank(String value, @TargetType Class<?> targetType) {
return value != null && !value.trim().isEmpty();
}
}