All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mapstruct.ap.internal.model.MapMappingMethod.ftl Maven / Gradle / Ivy

<#--

    Copyright MapStruct Authors.

    Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0

-->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MapMappingMethod" -->
<#if overridden>@Override
<#lt>${accessibility.keyword} <@includeModel object=returnType /> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> {
    <#list beforeMappingReferencesWithoutMappingTarget as callback>
    	<@includeModel object=callback targetBeanName=resultName targetType=resultType/>
    	<#if !callback_has_next>

    	
    
    if ( ${sourceParameter.name} == null ) {
        <#if !mapNullToDefault>
            return<#if returnType.name != "void"> <#if existingInstanceMapping>${resultName}<#else>null;
        <#else>
            <#if existingInstanceMapping>
                 ${resultName}.clear();
                 return<#if returnType.name != "void"> ${resultName};
            <#else>
                 return <@includeModel object=iterableCreation useSizeIfPossible=false/>;
            
        
    }

    <#if existingInstanceMapping>
        ${resultName}.clear();
    <#else>
        <@includeModel object=resultType /> ${resultName} = <@includeModel object=iterableCreation useSizeIfPossible=true/>;
    

    <#list beforeMappingReferencesWithMappingTarget as callback>
        <@includeModel object=callback targetBeanName=resultName targetType=resultType/>
        <#if !callback_has_next>

        
    
    <#-- Once #148 has been addressed, the simple name of Map.Entry can be used -->
    for ( java.util.Map.Entry<<#list sourceElementTypes as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > ${entryVariableName} : ${sourceParameter.name}.entrySet() ) {
    <#-- key -->
        <@includeModel object=keyAssignment
                   targetWriteAccessorName=keyVariableName
                   targetType=resultElementTypes[0].typeBound/>
    <#-- value -->
        <@includeModel object=valueAssignment
                   targetWriteAccessorName=valueVariableName
                   targetType=resultElementTypes[1].typeBound/>
        ${resultName}.put( ${keyVariableName}, ${valueVariableName} );
    }
    <#list afterMappingReferences as callback>
    	<#if callback_index = 0>

    	
    	<@includeModel object=callback targetBeanName=resultName targetType=resultType/>
    
    <#if returnType.name != "void">

        return ${resultName};
    
}
<#macro throws>
    <#if (thrownTypes?size > 0)><#lt> throws <@compress single_line=true>
        <#list thrownTypes as exceptionType>
            <@includeModel object=exceptionType/>
            <#if exceptionType_has_next>, <#t>
        
    




© 2015 - 2024 Weber Informatics LLC | Privacy Policy