#373 Flattening and simplifying generated forged method

This commit is contained in:
sjaakd 2014-12-08 21:26:04 +01:00 committed by Andreas Gudian
parent 21010bae7f
commit c551a2d27d
2 changed files with 13 additions and 23 deletions

View File

@ -39,7 +39,6 @@ import org.mapstruct.ap.util.Strings;
*/
public class NestedPropertyMappingMethod extends MappingMethod {
private final List<String> existingVariableNames;
private final List<SafePropertyEntry> 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<SafePropertyEntry> sourcePropertyEntries,
List<String> existingVariableNames ) {
private NestedPropertyMappingMethod( Method method, List<SafePropertyEntry> 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;

View File

@ -20,19 +20,16 @@
-->
<#lt>private <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>) {
<#compress>
<@includeModel object=returnType/> ${targetLocalVariable} = null;
if ( ${sourceParameter.name} != null ) {
if ( ${sourceParameter.name} == null ) {
return 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>;
if ( ${entry.name} != null ) {
<#if !entry_has_next>${targetLocalVariable} = ${entry.name};</#if>
</#list>
<#list propertyEntries as entry>
if ( ${entry.name} == null ) {
return null;
}
<#if !entry_has_next>
return ${entry.name};
</#if>
</#list>
}
return ${targetLocalVariable};
</#compress>
}