mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#373 Flattening and simplifying generated forged method
This commit is contained in:
parent
21010bae7f
commit
c551a2d27d
@ -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;
|
||||
|
@ -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 ) {
|
||||
<#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>
|
||||
}
|
||||
</#list>
|
||||
if ( ${sourceParameter.name} == null ) {
|
||||
return null;
|
||||
}
|
||||
return ${targetLocalVariable};
|
||||
</#compress>
|
||||
|
||||
<#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 ) {
|
||||
return null;
|
||||
}
|
||||
<#if !entry_has_next>
|
||||
return ${entry.name};
|
||||
</#if>
|
||||
</#list>
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user