diff --git a/processor/src/main/java/org/mapstruct/ap/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/NestedPropertyMappingMethod.java index f627e978d..1e71aa1e2 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/NestedPropertyMappingMethod.java @@ -39,7 +39,6 @@ import org.mapstruct.ap.util.Strings; */ public class NestedPropertyMappingMethod extends MappingMethod { - private final List existingVariableNames; private final List safePropertyEntries; public static class Builder { @@ -68,15 +67,13 @@ public class NestedPropertyMappingMethod extends MappingMethod { safePropertyEntries.add( new SafePropertyEntry( propertyEntry, safeName ) ); existingVariableNames.add( safeName ); } - return new NestedPropertyMappingMethod( method, safePropertyEntries, existingVariableNames ); + return new NestedPropertyMappingMethod( method, safePropertyEntries ); } } - private NestedPropertyMappingMethod( Method method, List sourcePropertyEntries, - List existingVariableNames ) { + private NestedPropertyMappingMethod( Method method, List sourcePropertyEntries ) { super( method ); this.safePropertyEntries = sourcePropertyEntries; - this.existingVariableNames = existingVariableNames; } public Parameter getSourceParameter() { @@ -101,10 +98,6 @@ public class NestedPropertyMappingMethod extends MappingMethod { return types; } - public String getTargetLocalVariable() { - return Strings.getSaveVariableName( getReturnType().getName(), existingVariableNames ); - } - @Override public int hashCode() { final int prime = 31; diff --git a/processor/src/main/resources/org.mapstruct.ap.model.NestedPropertyMappingMethod.ftl b/processor/src/main/resources/org.mapstruct.ap.model.NestedPropertyMappingMethod.ftl index a092e5cb2..3f479a9a0 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.NestedPropertyMappingMethod.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.NestedPropertyMappingMethod.ftl @@ -20,19 +20,16 @@ --> <#lt>private <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { - <#compress> - <@includeModel object=returnType/> ${targetLocalVariable} = null; - if ( ${sourceParameter.name} != null ) { - <#list propertyEntries as entry> - <@includeModel object=entry.type/> ${entry.name} = <#if entry_index == 0>${sourceParameter.name}.${entry.accessor}<#else>${propertyEntries[entry_index-1].name}.${entry.accessor}; - if ( ${entry.name} != null ) { - <#if !entry_has_next>${targetLocalVariable} = ${entry.name}; - - <#list propertyEntries as entry> - } - + if ( ${sourceParameter.name} == null ) { + return null; } - return ${targetLocalVariable}; - - + <#list propertyEntries as entry> + <@includeModel object=entry.type/> ${entry.name} = <#if entry_index == 0>${sourceParameter.name}.${entry.accessor}<#else>${propertyEntries[entry_index-1].name}.${entry.accessor}; + if ( ${entry.name} == null ) { + return null; + } + <#if !entry_has_next> + return ${entry.name}; + + }