From fbd06315a0991e727e3ea537b97cc87967c37ec8 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Thu, 20 Mar 2014 22:52:02 +0100 Subject: [PATCH] #157 refactoring, adding ParameterAssignment Freemarker template and using it. --- .../ap/model/IterableMappingMethod.java | 22 ++-- .../mapstruct/ap/model/MapMappingMethod.java | 39 +++---- .../ap/model/ParameterAssignment.java | 64 ++++++++++- .../mapstruct/ap/model/PropertyMapping.java | 39 +++---- .../ap/processor/MapperCreationProcessor.java | 24 +--- ...pstruct.ap.model.IterableMappingMethod.ftl | 19 +-- ...rg.mapstruct.ap.model.MapMappingMethod.ftl | 58 +++------- ...org.mapstruct.ap.model.MethodReference.ftl | 28 ++++- ...mapstruct.ap.model.ParameterAssignment.ftl | 65 +++++++++++ ...org.mapstruct.ap.model.PropertyMapping.ftl | 108 ++++++------------ 10 files changed, 248 insertions(+), 218 deletions(-) create mode 100644 processor/src/main/resources/org.mapstruct.ap.model.ParameterAssignment.ftl diff --git a/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java index 92ac7721a..3e8277ab5 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java @@ -33,15 +33,13 @@ import org.mapstruct.ap.util.Strings; */ public class IterableMappingMethod extends MappingMethod { - private final MethodReference elementMappingMethod; - private final TypeConversion conversion; + private final ParameterAssignment elementAssignment; private final MethodReference factoryMethod; - public IterableMappingMethod(SourceMethod method, MethodReference elementMappingMethod, - TypeConversion conversion, MethodReference factoryMethod) { + public IterableMappingMethod(SourceMethod method, ParameterAssignment parameterAssignment, + MethodReference factoryMethod) { super( method ); - this.elementMappingMethod = elementMappingMethod; - this.conversion = conversion; + this.elementAssignment = parameterAssignment; this.factoryMethod = factoryMethod; } @@ -55,20 +53,16 @@ public class IterableMappingMethod extends MappingMethod { throw new IllegalStateException( "Method " + this + " has no source parameter." ); } - public MethodReference getElementMappingMethod() { - return elementMappingMethod; - } - - public TypeConversion getConversion() { - return conversion; + public ParameterAssignment getElementAssignment() { + return elementAssignment; } @Override public Set getImportTypes() { Set types = super.getImportTypes(); - if ( conversion != null ) { - types.addAll( conversion.getImportTypes() ); + if ( elementAssignment != null ) { + types.addAll( elementAssignment.getImportTypes() ); } return types; diff --git a/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java index aa9e4c16b..a314c30dc 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java @@ -33,21 +33,16 @@ import org.mapstruct.ap.util.Strings; */ public class MapMappingMethod extends MappingMethod { - private final MethodReference keyMappingMethod; - private final MethodReference valueMappingMethod; - private final TypeConversion keyConversion; - private final TypeConversion valueConversion; + private final ParameterAssignment keyAssignment; + private final ParameterAssignment valueAssignment; private final MethodReference factoryMethod; - public MapMappingMethod(SourceMethod method, MethodReference keyMappingMethod, TypeConversion keyConversion, - MethodReference valueMappingMethod, TypeConversion valueConversion, + public MapMappingMethod(SourceMethod method, ParameterAssignment keyAssignment, ParameterAssignment valueAssignment, MethodReference factoryMethod) { super( method ); - this.keyMappingMethod = keyMappingMethod; - this.keyConversion = keyConversion; - this.valueMappingMethod = valueMappingMethod; - this.valueConversion = valueConversion; + this.keyAssignment = keyAssignment; + this.valueAssignment = valueAssignment; this.factoryMethod = factoryMethod; } @@ -61,31 +56,23 @@ public class MapMappingMethod extends MappingMethod { throw new IllegalStateException( "Method " + this + " has no source parameter." ); } - public MethodReference getKeyMappingMethod() { - return keyMappingMethod; + public ParameterAssignment getKeyAssignment() { + return keyAssignment; } - public TypeConversion getKeyConversion() { - return keyConversion; - } - - public MethodReference getValueMappingMethod() { - return valueMappingMethod; - } - - public TypeConversion getValueConversion() { - return valueConversion; + public ParameterAssignment getValueAssignment() { + return valueAssignment; } @Override public Set getImportTypes() { Set types = super.getImportTypes(); - if ( valueConversion != null ) { - types.addAll( valueConversion.getImportTypes() ); + if ( keyAssignment != null ) { + types.addAll( keyAssignment.getImportTypes() ); } - if ( keyConversion != null ) { - types.addAll( keyConversion.getImportTypes() ); + if ( valueAssignment != null ) { + types.addAll( valueAssignment.getImportTypes() ); } return types; diff --git a/processor/src/main/java/org/mapstruct/ap/model/ParameterAssignment.java b/processor/src/main/java/org/mapstruct/ap/model/ParameterAssignment.java index 2d2eccdd4..4d50011af 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/ParameterAssignment.java +++ b/processor/src/main/java/org/mapstruct/ap/model/ParameterAssignment.java @@ -18,6 +18,13 @@ */ package org.mapstruct.ap.model; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.mapstruct.ap.model.common.ModelElement; +import org.mapstruct.ap.model.common.Type; + /** * This class carries the possible ways to do an assignment to a parameter on a mapping target * @@ -30,20 +37,28 @@ package org.mapstruct.ap.model; * * @author Sjaak Derksen */ -public class ParameterAssignment { +public class ParameterAssignment extends ModelElement { + + public static enum AssignmentType { TYPE_CONVERSION, METHOD_REFERENCE, ASSIGNMENT }; + private MethodReference methodReference; private TypeConversion typeConversion; + private final AssignmentType assignmentType; + public ParameterAssignment() { + assignmentType = AssignmentType.ASSIGNMENT; } public ParameterAssignment( MethodReference methodReference ) { + assignmentType = AssignmentType.METHOD_REFERENCE; this.methodReference = methodReference; } public ParameterAssignment( TypeConversion typeConversion ) { + assignmentType = AssignmentType.TYPE_CONVERSION; this.typeConversion = typeConversion; } @@ -55,4 +70,51 @@ public class ParameterAssignment { return typeConversion; } + public AssignmentType getAssignmentType() { + return assignmentType; + } + + public List getExceptionTypes() { + List exceptionTypes = new ArrayList(); + switch ( assignmentType ) { + case METHOD_REFERENCE: +// exceptionTypes.addAll( methodReference.getExceptionTypes() ); + break; + case TYPE_CONVERSION: + exceptionTypes.addAll( typeConversion.getExceptionTypes() ); + break; + default: + } + return exceptionTypes; + } + + @Override + public Set getImportTypes() { + Set importedTypes = new HashSet(); + switch ( assignmentType ) { + case METHOD_REFERENCE: + importedTypes.addAll( methodReference.getImportTypes() ); + break; + case TYPE_CONVERSION: + importedTypes.addAll( typeConversion.getImportTypes() ); + break; + default: + } + return importedTypes; + } + + @Override + public String toString() { + String result = ""; + switch ( assignmentType ) { + case METHOD_REFERENCE: + result = methodReference.toString(); + break; + case TYPE_CONVERSION: + result = typeConversion.toString(); + break; + default: + } + return result; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java index bb16c4d71..6f61c6403 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java @@ -23,7 +23,7 @@ import java.util.Set; import org.mapstruct.ap.model.common.ModelElement; import org.mapstruct.ap.model.common.Type; - +import org.mapstruct.ap.model.ParameterAssignment.AssignmentType; /** * Represents the mapping between a source and target property, e.g. from * {@code String Source#foo} to {@code int Target#bar}. Name and type of source @@ -45,12 +45,12 @@ public class PropertyMapping extends ModelElement { private final boolean isTargetAccessorSetter; private final String targetReadAccessorName; - private final MethodReference mappingMethod; - private final TypeConversion conversion; + private final ParameterAssignment parameterAssignment; + public PropertyMapping(String sourceBeanName, String sourceName, String sourceAccessorName, Type sourceType, String targetName, String targetAccessorName, Type targetType, - MethodReference mappingMethod, TypeConversion conversion) { + ParameterAssignment parameterAssignment ) { this.sourceBeanName = sourceBeanName; this.sourceName = sourceName; @@ -64,8 +64,7 @@ public class PropertyMapping extends ModelElement { this.targetReadAccessorName = this.isTargetAccessorSetter ? "get" + targetAccessorName.substring( 3 ) : targetAccessorName; - this.mappingMethod = mappingMethod; - this.conversion = conversion; + this.parameterAssignment = parameterAssignment; } public String getSourceBeanName() { @@ -96,12 +95,8 @@ public class PropertyMapping extends ModelElement { return targetType; } - public MethodReference getMappingMethod() { - return mappingMethod; - } - - public TypeConversion getConversion() { - return conversion; + public ParameterAssignment getParameterAssignment() { + return parameterAssignment; } /** @@ -125,16 +120,17 @@ public class PropertyMapping extends ModelElement { @Override public Set getImportTypes() { Set importTypes = new HashSet(); + if ( parameterAssignment != null ) { + if ( isTargetAccessorSetter() + && parameterAssignment.getAssignmentType().equals( AssignmentType.ASSIGNMENT ) + && ( targetType.isCollectionType() || targetType.isMapType() ) ) { + importTypes.addAll( targetType.getImportTypes() ); + } - if ( isTargetAccessorSetter() && getMappingMethod() == null - && ( targetType.isCollectionType() || targetType.isMapType() ) ) { - importTypes.addAll( targetType.getImportTypes() ); + if ( !parameterAssignment.getAssignmentType().equals( AssignmentType.ASSIGNMENT ) ) { + importTypes.addAll( parameterAssignment.getImportTypes() ); + } } - - if ( conversion != null && mappingMethod == null ) { - importTypes.addAll( conversion.getImportTypes() ); - } - return importTypes; } @@ -145,8 +141,7 @@ public class PropertyMapping extends ModelElement { "\n sourceType=" + sourceType + "," + "\n targetName='" + targetAccessorName + "\'," + "\n targetType=" + targetType + "," + - "\n mappingMethod=" + mappingMethod + "," + - "\n Conversion='" + conversion + "\'," + + "\n parameterAssignment=" + parameterAssignment + "\n}"; } } diff --git a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java index 3e7729ec5..a2886e17a 100644 --- a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java @@ -662,8 +662,7 @@ public class MapperCreationProcessor implements ModelElementProcessor mapperReferences, List methods, @@ -787,15 +781,7 @@ public class MapperCreationProcessor implements ModelElementProcessor for ( <@includeModel object=sourceParameter.type.typeParameters[0]/> ${loopVariableName} : ${sourceParameter.name} ) { - <#if elementMappingMethod??> - ${resultName}.add( <@includeModel object=elementMappingMethod input="${loopVariableName}" targetType="${resultType.typeParameters[0].name}"/> ); - <#elseif conversion??> - <#if (conversion.exceptionTypes?size == 0) > - ${resultName}.add( <@includeModel object=conversion/> ); - <#else> - try { - ${resultName}.add( <@includeModel object=conversion/> ); - } - <#list conversion.exceptionTypes as exceptionType> - catch( <@includeModel object=exceptionType/> e ) { - throw new RuntimeException( e ); - } - - - <#else> - ${resultName}.add( ${loopVariableName} ); - + <@includeModel object=elementAssignment target="${resultName}.add" source="${loopVariableName}" targetType="${resultType.typeParameters[0].name}"/> } <#if returnType.name != "void"> diff --git a/processor/src/main/resources/org.mapstruct.ap.model.MapMappingMethod.ftl b/processor/src/main/resources/org.mapstruct.ap.model.MapMappingMethod.ftl index 31fd1006a..2c9664125 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.MapMappingMethod.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.MapMappingMethod.ftl @@ -32,52 +32,26 @@ <#-- Once #148 has been addressed, the simple name of Map.Entry can be used --> for ( java.util.Map.Entry<<#list sourceParameter.type.typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > ${entryVariableName} : ${sourceParameter.name}.entrySet() ) { - <#-- key --> - <#if keyMappingMethod??> - <@includeModel object=resultType.typeParameters[0]/> ${keyVariableName} = <@includeModel object=keyMappingMethod input="entry.getKey()" targetType="${resultType.typeParameters[0].name}"/>; - <#elseif keyConversion??> - <#if (keyConversion.exceptionTypes?size == 0) > - <@includeModel object=resultType.typeParameters[0]/> ${keyVariableName} = <@includeModel object=keyConversion/>; - <#else> - <@includeModel object=resultType.typeParameters[0]/> ${keyVariableName}; - try { - ${keyVariableName} = <@includeModel object=keyConversion/>; - } - <#list keyConversion.exceptionTypes as exceptionType> - catch( <@includeModel object=exceptionType/> e ) { - throw new RuntimeException( e ); - } - - - <#else> - <@includeModel object=resultType.typeParameters[0]/> ${keyVariableName} = entry.getKey(); - + <@includeModel object=keyAssignment + target=keyVariableName + targetType=typeName(resultType.typeParameters[0]) + source="entry.getKey()" + isLocalVar=true/> <#-- value --> - <#if valueMappingMethod??> - <@includeModel object=resultType.typeParameters[1]/> ${valueVariableName} = <@includeModel object=valueMappingMethod input="entry.getValue()" targetType="${resultType.typeParameters[1].name}"/>; - <#elseif valueConversion??> - <#if (valueConversion.exceptionTypes?size == 0) > - <@includeModel object=resultType.typeParameters[1]/> ${valueVariableName} = <@includeModel object=valueConversion/>; - <#else> - <@includeModel object=resultType.typeParameters[1]/> ${valueVariableName}; - try { - ${valueVariableName} = <@includeModel object=valueConversion/>; - } - <#list valueConversion.exceptionTypes as exceptionType> - catch( <@includeModel object=exceptionType/> e ) { - throw new RuntimeException( e ); - } - - - <#else> - <@includeModel object=resultType.typeParameters[1]/> ${valueVariableName} = entry.getValue(); - - + <@includeModel object=valueAssignment + target=valueVariableName + targetType=typeName(resultType.typeParameters[1]) + source="entry.getValue()" + isLocalVar=true/> ${resultName}.put( ${keyVariableName}, ${valueVariableName} ); } <#if returnType.name != "void"> - return ${resultName}; + return ${resultName}; -} \ No newline at end of file +} +<#function typeName type> + <#local result><@includeModel object=type/> + <#return result> + diff --git a/processor/src/main/resources/org.mapstruct.ap.model.MethodReference.ftl b/processor/src/main/resources/org.mapstruct.ap.model.MethodReference.ftl index 485aa58bb..0cf63f5ef 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.MethodReference.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.MethodReference.ftl @@ -18,8 +18,26 @@ limitations under the License. --> -<#if methodRefChild??> - <#if declaringMapper??>${mapperVariableName}.${name}(<#list parameters as param> <#if param.targetType>${ext.targetType}.class<#else><@includeModel object=methodRefChild input=ext.input targetType=singleSourceParameterType.name/><#if param_has_next>,<#else> <#if contextParam??>, ${contextParam})<#t> -<#else> - <#if declaringMapper??>${mapperVariableName}.${name}(<#list parameters as param> <#if param.targetType>${ext.targetType}.class<#else>${ext.input}<#if param_has_next>,<#else> <#if contextParam??>, ${contextParam})<#t> - \ No newline at end of file +<@compress single_line=true> + <#-- method is either internal to the mapper class, or external (via uses) declaringMapper!=null --> + <#if declaringMapper??>${mapperVariableName}.${name}( <@arguments/> ) + <#macro arguments> + <#list parameters as param> + <#if param.targetType> + <#-- a class is passed on for casting, see @TargetType --> + ${ext.targetType}.class + <#else> + <#if methodRefChild??> + <#-- the nested case --> + <@includeModel object=methodRefChild source=ext.source targetType=singleSourceParameterType.name/> + <#else> + <#-- the non nested case --> + ${ext.source} + + + <#if param_has_next>, + + <#-- context parameter, e.g. for buildin methods concerning date conversion --> + <#if contextParam??>, ${contextParam} + + diff --git a/processor/src/main/resources/org.mapstruct.ap.model.ParameterAssignment.ftl b/processor/src/main/resources/org.mapstruct.ap.model.ParameterAssignment.ftl new file mode 100644 index 000000000..269d1400d --- /dev/null +++ b/processor/src/main/resources/org.mapstruct.ap.model.ParameterAssignment.ftl @@ -0,0 +1,65 @@ +<#-- + + Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/) + and/or other contributors as indicated by the @authors tag. See the + copyright.txt file in the distribution for a full listing of all + contributors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<#if ( ext.isLocalVar?? && ext.isLocalVar==true )> + <#-- assignment is a local variable assignment --> + <#if (exceptionTypes?size == 0) > + ${ext.targetType} ${ext.target} = <@assignment/>; + <#else> + ${ext.targetType} ${ext.target}; + try { + ${ext.target} = <@assignment/>; + } + <#list exceptionTypes as exceptionType> + catch ( <@includeModel object=exceptionType/> e ) { + throw new RuntimeException( e ); + } + + +<#else> + <#-- assignment is a method call --> + <#if (exceptionTypes?size == 0) > + ${ext.target}( <@assignment/> ); + <#else> + try { + ${ext.target}( <@assignment/> ); + } + <#list exceptionTypes as exceptionType> + catch ( <@includeModel object=exceptionType/> e ) { + throw new RuntimeException( e ); + } + + + +<#macro assignment> + <#compress> + <#switch assignmentType> + <#case "TYPE_CONVERSION"> + <@includeModel object=typeConversion/> + <#break> + <#case "METHOD_REFERENCE"> + <@includeModel object=methodReference source="${ext.source}" targetType=ext.targetType raw=ext.raw/> + <#break> + <#case "ASSIGNMENT"> + ${ext.source} + <#break> + + + diff --git a/processor/src/main/resources/org.mapstruct.ap.model.PropertyMapping.ftl b/processor/src/main/resources/org.mapstruct.ap.model.PropertyMapping.ftl index 69d42e91c..258432fad 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.PropertyMapping.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.PropertyMapping.ftl @@ -18,87 +18,55 @@ limitations under the License. --> -<#-- a) invoke mapping method --> -<#if mappingMethod??> - <@assignResult - existingInstanceMapping=ext.existingInstanceMapping - targetAccessorSetter=targetAccessorSetter - targetType=targetType - targetBeanName=ext.targetBeanName - targetReadAccessorName=targetReadAccessorName - targetAccessorName=targetAccessorName - sourceBeanName=sourceBeanName - sourceAccessorName=sourceAccessorName><#compress> - <@includeModel object=mappingMethod input="${sourceBeanName}.${sourceAccessorName}()" targetType=targetType raw=true/> - -<#-- b) simple conversion --> -<#elseif conversion??> - <#if sourceType.primitive == false> + <#if !( targetType.collectionType || targetType.mapType ) > + <#-- non collections or maps --> + <#if ( !sourceType.primitive && parameterAssignment.assignmentType!="ASSIGNMENT" ) > if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { - <@applyConversion targetBeanName=ext.targetBeanName targetAccessorName=targetAccessorName conversion=conversion/> + <@assignmentLine/> } <#else> - <@applyConversion targetBeanName=ext.targetBeanName targetAccessorName=targetAccessorName conversion=conversion/> + <@assignmentLine/> -<#-- c) simply set --> <#else> - <@assignResult - existingInstanceMapping=ext.existingInstanceMapping - targetAccessorSetter=targetAccessorSetter - targetType=targetType - targetBeanName=ext.targetBeanName - targetReadAccessorName=targetReadAccessorName - targetAccessorName=targetAccessorName - sourceBeanName=sourceBeanName - sourceAccessorName=sourceAccessorName - ; use_plain><#compress> - <#if use_plain> - ${sourceBeanName}.${sourceAccessorName}() - <#else> - new <#if targetType.implementationType??><@includeModel object=targetType.implementationType/><#else><@includeModel object=targetType/>( ${sourceBeanName}.${sourceAccessorName}() ) - - - -<#macro assignResult existingInstanceMapping targetAccessorSetter targetType targetBeanName targetReadAccessorName targetAccessorName sourceBeanName sourceAccessorName> - <#if ( existingInstanceMapping || !targetAccessorSetter ) && ( targetType.collectionType || targetType.mapType ) > - if ( ${targetBeanName}.${targetReadAccessorName}() != null ) { - <#if existingInstanceMapping> - ${targetBeanName}.${targetReadAccessorName}().clear(); - <#t> - if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { + <#-- collections or maps --> + <#if ( ext.existingInstanceMapping || !targetAccessorSetter ) > + if ( ${ext.targetBeanName}.${targetReadAccessorName}() != null ) { + <#if ext.existingInstanceMapping> + ${ext.targetBeanName}.${targetReadAccessorName}().clear(); + <#t> + if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { <#if targetType.collectionType> - ${targetBeanName}.${targetReadAccessorName}().addAll( <#nested true> ); + <@collectionOrMapAssignmentLine target="${ext.targetBeanName}.${targetReadAccessorName}().addAll"/> <#else> - ${targetBeanName}.${targetReadAccessorName}().putAll( <#nested true> ); + <@collectionOrMapAssignmentLine target="${ext.targetBeanName}.${targetReadAccessorName}().putAll"/> } } <#if targetAccessorSetter> - else if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { - ${targetBeanName}.${targetAccessorName}( <#nested false> ); - } + else if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { + <@collectionOrMapAssignmentLine/> + } <#elseif targetAccessorSetter> - <#if targetType.collectionType || targetType.mapType> - if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { - ${targetBeanName}.${targetAccessorName}( <#nested false> ); - } - <#else> - ${targetBeanName}.${targetAccessorName}( <#nested true> ); - - + if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { + <@collectionOrMapAssignmentLine/> + } + + + <#macro collectionOrMapAssignmentLine + target="${ext.targetBeanName}.${targetAccessorName}" + source="${sourceBeanName}.${sourceAccessorName}"> + <#compress> + <#if parameterAssignment?? && parameterAssignment.assignmentType!="ASSIGNMENT"> + <@assignmentLine target source/> + <#else> + ${target}( new <#if targetType.implementationType??><@includeModel object=targetType.implementationType/><#else><@includeModel object=targetType/>( ${source}() ) ); + + + + +<#macro assignmentLine + target="${ext.targetBeanName}.${targetAccessorName}" + source="${sourceBeanName}.${sourceAccessorName}"> + <@includeModel object=parameterAssignment target=target source="${source}()" targetType=targetType raw=true/> -<#macro applyConversion targetBeanName targetAccessorName conversion> - <#if (conversion.exceptionTypes?size == 0) > - ${targetBeanName}.${targetAccessorName}( <@includeModel object=conversion/> ); - <#else> - try { - ${targetBeanName}.${targetAccessorName}( <@includeModel object=conversion/> ); - } - <#list conversion.exceptionTypes as exceptionType> - catch( <@includeModel object=exceptionType/> e ) { - throw new RuntimeException( e ); - } - - - \ No newline at end of file