From 517817fbfc4797798482302a2ceabb2f1cf1893b Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Tue, 18 Jun 2013 21:27:44 +0200 Subject: [PATCH] #32 Creating dedicated template for MappingMethod --- .../mapstruct/ap/MapperGenerationVisitor.java | 123 ++++++++++-------- .../org/mapstruct/ap/model/BeanMapping.java | 56 +------- .../java/org/mapstruct/ap/model/Mapper.java | 6 +- .../org/mapstruct/ap/model/MappingMethod.java | 45 ++++++- .../mapstruct/ap/model/PropertyMapping.java | 36 +---- .../org.mapstruct.ap.model.BeanMapping.ftl | 121 +---------------- .../org.mapstruct.ap.model.MappingMethod.ftl | 93 +++++++++++++ 7 files changed, 216 insertions(+), 264 deletions(-) create mode 100644 processor/src/main/resources/org.mapstruct.ap.model.MappingMethod.ftl diff --git a/processor/src/main/java/org/mapstruct/ap/MapperGenerationVisitor.java b/processor/src/main/java/org/mapstruct/ap/MapperGenerationVisitor.java index 449df9481..4fecf36ed 100644 --- a/processor/src/main/java/org/mapstruct/ap/MapperGenerationVisitor.java +++ b/processor/src/main/java/org/mapstruct/ap/MapperGenerationVisitor.java @@ -193,27 +193,31 @@ public class MapperGenerationVisitor extends ElementKindVisitor6 { continue; } - MappingMethod mappingMethod = new MappingMethod( - method.getDeclaringMapper(), - method.getName(), - method.getParameterName(), - getElementMappingMethod( methods, method ) - ); - - MappingMethod reverseMappingMethod = null; Method rawReverseMappingMethod = getReverseMappingMethod( methods, method ); - if ( rawReverseMappingMethod != null ) { - processedMethods.add( rawReverseMappingMethod ); - reverseMappingMethod = new MappingMethod( - rawReverseMappingMethod.getDeclaringMapper(), - rawReverseMappingMethod.getName(), - rawReverseMappingMethod.getParameterName(), - getElementMappingMethod( methods, rawReverseMappingMethod ) + String toConversionString = null; + String fromConversionString = null; + + boolean isIterableMapping = method.getSourceType().isIterableType() && method.getTargetType() + .isIterableType(); + + if ( isIterableMapping ) { + toConversionString = getIterableConversionString( + conversions, + method.getSourceType().getElementType(), + method.getTargetType().getElementType(), + true + ); + fromConversionString = getIterableConversionString( + conversions, + method.getTargetType().getElementType(), + method.getSourceType().getElementType(), + false ); } List propertyMappings = new ArrayList(); + List reversePropertyMappings = new ArrayList(); Set mappedSourceProperties = new HashSet(); Set mappedTargetProperties = new HashSet(); @@ -237,35 +241,71 @@ public class MapperGenerationVisitor extends ElementKindVisitor6 { propertyMappings.add( new PropertyMapping( property.getSourceReadAccessorName(), - property.getSourceWriteAccessorName(), property.getSourceType(), - property.getTargetReadAccessorName(), property.getTargetWriteAccessorName(), property.getTargetType(), propertyMappingMethod != null ? new MappingMethod( propertyMappingMethod.getDeclaringMapper(), propertyMappingMethod.getName(), - propertyMappingMethod.getParameterName() + propertyMappingMethod.getParameterName(), + property.getSourceType(), + property.getTargetType() ) : null, + conversion != null ? conversion.to( + method.getParameterName() + "." + property.getSourceReadAccessorName() + "()", + property.getTargetType() + ) : null + ) + ); + + reversePropertyMappings.add( + new PropertyMapping( + property.getTargetReadAccessorName(), + property.getTargetType(), + property.getSourceWriteAccessorName(), + property.getSourceType(), reversePropertyMappingMethod != null ? new MappingMethod( reversePropertyMappingMethod.getDeclaringMapper(), reversePropertyMappingMethod.getName(), - reversePropertyMappingMethod.getParameterName() + reversePropertyMappingMethod.getParameterName(), + property.getTargetType(), + property.getSourceType() ) : null, - conversion != null ? conversion.to( - mappingMethod.getParameterName() + "." + property.getSourceReadAccessorName() + "()", - property.getTargetType() - ) : null, - conversion != null && reverseMappingMethod != null ? conversion.from( - reverseMappingMethod.getParameterName() + "." + property.getTargetReadAccessorName() + "()", + conversion != null && rawReverseMappingMethod != null ? conversion.from( + rawReverseMappingMethod.getParameterName() + "." + property.getTargetReadAccessorName() + + "()", property.getSourceType() ) : null ) ); } - boolean isIterableMapping = method.getSourceType().isIterableType() && method.getTargetType() - .isIterableType(); + MappingMethod mappingMethod = new MappingMethod( + method.getDeclaringMapper(), + method.getName(), + method.getParameterName(), + method.getSourceType(), + method.getTargetType(), + propertyMappings, + getElementMappingMethod( methods, method ), + toConversionString + ); + + MappingMethod reverseMappingMethod = null; + if ( rawReverseMappingMethod != null ) { + processedMethods.add( rawReverseMappingMethod ); + + reverseMappingMethod = new MappingMethod( + rawReverseMappingMethod.getDeclaringMapper(), + rawReverseMappingMethod.getName(), + rawReverseMappingMethod.getParameterName(), + method.getTargetType(), + method.getSourceType(), + reversePropertyMappings, + getElementMappingMethod( methods, rawReverseMappingMethod ), + fromConversionString + ); + } if ( mappingMethod.isGenerationRequired() && !isIterableMapping ) { reportErrorForUnmappedTargetPropertiesIfRequired( @@ -284,32 +324,9 @@ public class MapperGenerationVisitor extends ElementKindVisitor6 { ); } - String toConversionString = null; - String fromConversionString = null; - - if ( isIterableMapping ) { - toConversionString = getIterableConversionString( - conversions, - method.getSourceType().getElementType(), - method.getTargetType().getElementType(), - true - ); - fromConversionString = getIterableConversionString( - conversions, - method.getTargetType().getElementType(), - method.getSourceType().getElementType(), - false - ); - } - BeanMapping mapping = new BeanMapping( - method.getSourceType(), - method.getTargetType(), - propertyMappings, mappingMethod, - reverseMappingMethod, - toConversionString, - fromConversionString + reverseMappingMethod ); mappings.add( mapping ); @@ -421,7 +438,9 @@ public class MapperGenerationVisitor extends ElementKindVisitor6 { return elementMappingMethod == null ? null : new MappingMethod( elementMappingMethod.getDeclaringMapper(), elementMappingMethod.getName(), - elementMappingMethod.getParameterName() + elementMappingMethod.getParameterName(), + elementMappingMethod.getSourceType(), + elementMappingMethod.getTargetType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/model/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/model/BeanMapping.java index 0a3600184..66f92e346 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/model/BeanMapping.java @@ -18,42 +18,14 @@ */ package org.mapstruct.ap.model; -import java.util.List; - public class BeanMapping extends AbstractModelElement { - private final Type sourceType; - private final Type targetType; - private final List propertyMappings; private final MappingMethod mappingMethod; private final MappingMethod reverseMappingMethod; - private final boolean isIterableMapping; - private final String toConversion; - private final String fromConversion; - public BeanMapping(Type sourceType, Type targetType, List propertyMappings, - MappingMethod mappingMethod, - MappingMethod reverseMappingMethod, String toConversion, String fromConversion) { - this.sourceType = sourceType; - this.targetType = targetType; - this.propertyMappings = propertyMappings; + public BeanMapping(MappingMethod mappingMethod, MappingMethod reverseMappingMethod) { this.mappingMethod = mappingMethod; this.reverseMappingMethod = reverseMappingMethod; - this.isIterableMapping = sourceType.isIterableType() && targetType.isIterableType(); - this.toConversion = toConversion; - this.fromConversion = fromConversion; - } - - public Type getSourceType() { - return sourceType; - } - - public Type getTargetType() { - return targetType; - } - - public List getPropertyMappings() { - return propertyMappings; } public MappingMethod getMappingMethod() { @@ -64,37 +36,11 @@ public class BeanMapping extends AbstractModelElement { return reverseMappingMethod; } - public boolean isIterableMapping() { - return isIterableMapping; - } - - public String getToConversion() { - return toConversion; - } - - public String getFromConversion() { - return fromConversion; - } - @Override public String toString() { StringBuilder sb = new StringBuilder( "BeanMapping {" ); - - sb.append( "\n sourceType=" + sourceType + ',' ); - sb.append( "\n targetType=" + targetType + ',' ); - - sb.append( "\n propertyMappings=[\n" ); - - for ( PropertyMapping propertyMapping : propertyMappings ) { - sb.append( " " + propertyMapping.toString().replaceAll( "\n", "\n " ) ); - } - sb.append( "\n ]" ); - sb.append( "\n mappingMethod=" + mappingMethod.toString().replaceAll( "\n", "\n " ) + ',' ); sb.append( "\n reverseMappingMethod=" + reverseMappingMethod + ',' ); - sb.append( "\n toConversion=" + toConversion + ',' ); - sb.append( "\n fromConversion=" + fromConversion + ',' ); - sb.append( "\n isIterableMapping=" + isIterableMapping ); sb.append( "\n}" ); return sb.toString(); diff --git a/processor/src/main/java/org/mapstruct/ap/model/Mapper.java b/processor/src/main/java/org/mapstruct/ap/model/Mapper.java index 5d9d31b93..0fc5dece1 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/Mapper.java +++ b/processor/src/main/java/org/mapstruct/ap/model/Mapper.java @@ -51,10 +51,10 @@ public class Mapper extends AbstractModelElement { importedTypes.add( Type.forClass( Generated.class ) ); for ( BeanMapping beanMapping : beanMappings ) { - addWithDependents( importedTypes, beanMapping.getSourceType() ); - addWithDependents( importedTypes, beanMapping.getTargetType() ); + addWithDependents( importedTypes, beanMapping.getMappingMethod().getSourceType() ); + addWithDependents( importedTypes, beanMapping.getMappingMethod().getTargetType() ); - for ( PropertyMapping propertyMapping : beanMapping.getPropertyMappings() ) { + for ( PropertyMapping propertyMapping : beanMapping.getMappingMethod().getPropertyMappings() ) { addWithDependents( importedTypes, propertyMapping.getSourceType() ); addWithDependents( importedTypes, propertyMapping.getTargetType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/MappingMethod.java index 30d6e0489..b5f902fb2 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/MappingMethod.java @@ -18,25 +18,44 @@ */ package org.mapstruct.ap.model; -public class MappingMethod { +import java.util.List; + +public class MappingMethod extends AbstractModelElement { private final Type declaringMapper; private final String name; private final String parameterName; + private final Type sourceType; + private final Type targetType; + private final List propertyMappings; private final MappingMethod elementMappingMethod; + private final boolean isIterableMapping; + private final String toConversion; - public MappingMethod(Type declaringMapper, String name, String parameterName) { + public MappingMethod(Type declaringMapper, String name, String parameterName, Type sourceType, Type targetType) { this.declaringMapper = declaringMapper; this.name = name; this.parameterName = parameterName; + this.sourceType = sourceType; + this.targetType = targetType; + this.propertyMappings = null; this.elementMappingMethod = null; + this.isIterableMapping = false; + this.toConversion = null; } - public MappingMethod(Type declaringMapper, String name, String parameterName, MappingMethod elementMappingMethod) { + public MappingMethod(Type declaringMapper, String name, String parameterName, Type sourceType, Type targetType, + List propertyMappings, MappingMethod elementMappingMethod, + String toConversion) { this.declaringMapper = declaringMapper; this.name = name; this.parameterName = parameterName; + this.sourceType = sourceType; + this.targetType = targetType; + this.propertyMappings = propertyMappings; this.elementMappingMethod = elementMappingMethod; + this.isIterableMapping = sourceType.isIterableType() && targetType.isIterableType(); + this.toConversion = toConversion; } public Type getDeclaringMapper() { @@ -51,10 +70,30 @@ public class MappingMethod { return parameterName; } + public Type getSourceType() { + return sourceType; + } + + public Type getTargetType() { + return targetType; + } + + public List getPropertyMappings() { + return propertyMappings; + } + public MappingMethod getElementMappingMethod() { return elementMappingMethod; } + public boolean isIterableMapping() { + return isIterableMapping; + } + + public String getToConversion() { + return toConversion; + } + public boolean isGenerationRequired() { return declaringMapper == null; } 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 e890ef360..ac16db7f3 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java @@ -29,49 +29,31 @@ package org.mapstruct.ap.model; public class PropertyMapping { private final String sourceReadAccessorName; - private final String sourceWriteAccessorName; private final Type sourceType; - private final String targetReadAccessorName; private final String targetWriteAccessorName; private final Type targetType; private final MappingMethod mappingMethod; - private final MappingMethod reverseMappingMethod; private final String toConversion; - private final String fromConversion; - public PropertyMapping(String sourceReadAccessorName, String sourceWriteAccessorName, Type sourceType, - String targetReadAccessorName, String targetWriteAccessorName, Type targetType, - MappingMethod mappingMethod, MappingMethod reverseMappingMethod, String toConversion, - String fromConversion) { + public PropertyMapping(String sourceReadAccessorName, Type sourceType, String targetWriteAccessorName, + Type targetType, MappingMethod mappingMethod, String toConversion) { this.sourceReadAccessorName = sourceReadAccessorName; - this.sourceWriteAccessorName = sourceWriteAccessorName; this.sourceType = sourceType; - this.targetReadAccessorName = targetReadAccessorName; this.targetWriteAccessorName = targetWriteAccessorName; this.targetType = targetType; this.mappingMethod = mappingMethod; - this.reverseMappingMethod = reverseMappingMethod; this.toConversion = toConversion; - this.fromConversion = fromConversion; } public String getSourceReadAccessorName() { return sourceReadAccessorName; } - public String getSourceWriteAccessorName() { - return sourceWriteAccessorName; - } - public Type getSourceType() { return sourceType; } - public String getTargetReadAccessorName() { - return targetReadAccessorName; - } - public String getTargetWriteAccessorName() { return targetWriteAccessorName; } @@ -84,29 +66,19 @@ public class PropertyMapping { return mappingMethod; } - public MappingMethod getReverseMappingMethod() { - return reverseMappingMethod; - } - public String getToConversion() { return toConversion; } - public String getFromConversion() { - return fromConversion; - } - @Override public String toString() { return "PropertyMapping {" + - "\n sourceName='" + sourceReadAccessorName + "/" + sourceWriteAccessorName + "\'," + + "\n sourceName='" + sourceReadAccessorName + "\'," + "\n sourceType=" + sourceType + "," + - "\n targetName='" + targetReadAccessorName + "/" + targetWriteAccessorName + "\'," + + "\n targetName='" + targetWriteAccessorName + "\'," + "\n targetType=" + targetType + "," + "\n mappingMethod=" + mappingMethod + "," + - "\n reverseMappingMethod=" + reverseMappingMethod + "," + "\n toConversion='" + toConversion + "\'," + - "\n fromConversion='" + fromConversion + "\'," + "\n}"; } } diff --git a/processor/src/main/resources/org.mapstruct.ap.model.BeanMapping.ftl b/processor/src/main/resources/org.mapstruct.ap.model.BeanMapping.ftl index 401c6e2f2..11e5dcfeb 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.BeanMapping.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.BeanMapping.ftl @@ -19,126 +19,9 @@ --> <#if mappingMethod.generationRequired == true> - <#if iterableMapping == true> - @Override - public ${targetType.name}<${targetType.elementType.name}> ${mappingMethod.name}(${sourceType.name}<${sourceType.elementType.name}> ${mappingMethod.parameterName}) { - if ( ${mappingMethod.parameterName} == null ) { - return null; - } - - <#-- Use the interface type on the left side, except it is java.lang.Iterable; use the implementation type - if present - on the right side --> - <#if targetType.name == "Iterable" && targetType.packageName == "java.lang">${targetType.iterableImplementationType.name}<#else>${targetType.name}<${targetType.elementType.name}> ${targetType.name?uncap_first} = new <#if targetType.iterableImplementationType??>${targetType.iterableImplementationType.name}<#else>${targetType.name}<${targetType.elementType.name}>(); - - for ( ${sourceType.elementType.name} ${sourceType.elementType.name?uncap_first} : ${mappingMethod.parameterName} ) { - <#if toConversion??> - ${targetType.name?uncap_first}.add( ${toConversion} ); - <#else> - ${targetType.name?uncap_first}.add( ${mappingMethod.elementMappingMethod.name}( ${sourceType.elementType.name?uncap_first} ) ); - - } - - return ${targetType.name?uncap_first}; - } - <#else> - @Override - public ${targetType.name} ${mappingMethod.name}(${sourceType.name} ${mappingMethod.parameterName}) { - if ( ${mappingMethod.parameterName} == null ) { - return null; - } - - ${targetType.name} ${targetType.name?uncap_first} = new ${targetType.name}(); - - <#list propertyMappings as propertyMapping> - <@simpleMap - sourceBeanName=mappingMethod.parameterName - sourceType=propertyMapping.sourceType - sourceAccessorName=propertyMapping.sourceReadAccessorName - targetBeanName=targetType.name?uncap_first - targetType=propertyMapping.targetType - targetAccessorName=propertyMapping.targetWriteAccessorName - conversion=propertyMapping.toConversion - mappingMethod=propertyMapping.mappingMethod - /> - - - return ${targetType.name?uncap_first}; - } - + <@includeModel object=mappingMethod/> <#if reverseMappingMethod??> - <#if reverseMappingMethod.generationRequired == true> - <#if iterableMapping == true> - - @Override - public ${sourceType.name}<${sourceType.elementType.name}> ${reverseMappingMethod.name}(${targetType.name}<${targetType.elementType.name}> ${reverseMappingMethod.parameterName}) { - if ( ${reverseMappingMethod.parameterName} == null ) { - return null; - } - - <#-- Use the interface type on the left side, except it is java.lang.Iterable; use the implementation type - if present - on the right side --> - <#if sourceType.name == "Iterable" && sourceType.packageName == "java.lang">${sourceType.iterableImplementationType.name}<#else>${sourceType.name}<${sourceType.elementType.name}> ${sourceType.name?uncap_first} = new <#if sourceType.iterableImplementationType??>${sourceType.iterableImplementationType.name}<#else>${sourceType.name}<${sourceType.elementType.name}>(); - - for ( ${targetType.elementType.name} ${targetType.elementType.name?uncap_first} : ${reverseMappingMethod.parameterName} ) { - <#if fromConversion??> - ${sourceType.name?uncap_first}.add( ${fromConversion} ); - <#else> - ${sourceType.name?uncap_first}.add( ${reverseMappingMethod.elementMappingMethod.name}( ${targetType.elementType.name?uncap_first} ) ); - - } - - return ${sourceType.name?uncap_first}; - } - <#else> - @Override - public ${sourceType.name} ${reverseMappingMethod.name}(${targetType.name} ${reverseMappingMethod.parameterName}) { - if ( ${reverseMappingMethod.parameterName} == null ) { - return null; - } - - ${sourceType.name} ${sourceType.name?uncap_first} = new ${sourceType.name}(); - - <#list propertyMappings as propertyMapping> - <@simpleMap - sourceBeanName=reverseMappingMethod.parameterName - sourceType=propertyMapping.targetType - sourceAccessorName=propertyMapping.targetReadAccessorName - targetBeanName=sourceType.name?uncap_first - targetType=propertyMapping.sourceType - targetAccessorName=propertyMapping.sourceWriteAccessorName - conversion=propertyMapping.fromConversion - mappingMethod=propertyMapping.reverseMappingMethod - /> - - - return ${sourceType.name?uncap_first}; - } - - + <@includeModel object=reverseMappingMethod/> - -<#-- Generates the mapping of one bean property --> -<#macro simpleMap sourceBeanName sourceType sourceAccessorName targetBeanName targetType targetAccessorName conversion="" mappingMethod=""> - <#-- a) invoke mapping method --> - <#if mappingMethod != ""> - ${targetBeanName}.${targetAccessorName}( <#if mappingMethod.declaringMapper??>${mappingMethod.declaringMapper.name?uncap_first}.${mappingMethod.name}( ${sourceBeanName}.${sourceAccessorName}() ) ); - <#-- b) simple conversion --> - <#elseif conversion != ""> - <#if sourceType.primitive == false> - if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { - ${targetBeanName}.${targetAccessorName}( ${conversion} ); - } - <#else> - ${targetBeanName}.${targetAccessorName}( ${conversion} ); - - <#-- c) simply set --> - <#else> - <#if targetType.collectionType == true> - if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { - ${targetBeanName}.${targetAccessorName}( new <#if targetType.collectionImplementationType??>${targetType.collectionImplementationType.name}<#else>${targetType.name}<#if targetType.elementType??><${targetType.elementType.name}>( ${sourceBeanName}.${sourceAccessorName}() ) ); - } - <#else> - ${targetBeanName}.${targetAccessorName}( ${sourceBeanName}.${sourceAccessorName}() ); - - - diff --git a/processor/src/main/resources/org.mapstruct.ap.model.MappingMethod.ftl b/processor/src/main/resources/org.mapstruct.ap.model.MappingMethod.ftl new file mode 100644 index 000000000..8be3d5781 --- /dev/null +++ b/processor/src/main/resources/org.mapstruct.ap.model.MappingMethod.ftl @@ -0,0 +1,93 @@ +<#-- + + Copyright 2012-2013 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 generationRequired == true> + <#if iterableMapping == true> + @Override + public ${targetType.name}<${targetType.elementType.name}> ${name}(${sourceType.name}<${sourceType.elementType.name}> ${parameterName}) { + if ( ${parameterName} == null ) { + return null; + } + + <#-- Use the interface type on the left side, except it is java.lang.Iterable; use the implementation type - if present - on the right side --> + <#if targetType.name == "Iterable" && targetType.packageName == "java.lang">${targetType.iterableImplementationType.name}<#else>${targetType.name}<${targetType.elementType.name}> ${targetType.name?uncap_first} = new <#if targetType.iterableImplementationType??>${targetType.iterableImplementationType.name}<#else>${targetType.name}<${targetType.elementType.name}>(); + + for ( ${sourceType.elementType.name} ${sourceType.elementType.name?uncap_first} : ${parameterName} ) { + <#if toConversion??> + ${targetType.name?uncap_first}.add( ${toConversion} ); + <#else> + ${targetType.name?uncap_first}.add( ${elementMappingMethod.name}( ${sourceType.elementType.name?uncap_first} ) ); + + } + + return ${targetType.name?uncap_first}; + } + <#else> + @Override + public ${targetType.name} ${name}(${sourceType.name} ${parameterName}) { + if ( ${parameterName} == null ) { + return null; + } + + ${targetType.name} ${targetType.name?uncap_first} = new ${targetType.name}(); + + <#list propertyMappings as propertyMapping> + <@simpleMap + sourceBeanName=parameterName + sourceType=propertyMapping.sourceType + sourceAccessorName=propertyMapping.sourceReadAccessorName + targetBeanName=targetType.name?uncap_first + targetType=propertyMapping.targetType + targetAccessorName=propertyMapping.targetWriteAccessorName + conversion=propertyMapping.toConversion + mappingMethod=propertyMapping.mappingMethod + /> + + + return ${targetType.name?uncap_first}; + } + + + +<#-- Generates the mapping of one bean property --> +<#macro simpleMap sourceBeanName sourceType sourceAccessorName targetBeanName targetType targetAccessorName conversion="" mappingMethod=""> + <#-- a) invoke mapping method --> + <#if mappingMethod != ""> + ${targetBeanName}.${targetAccessorName}( <#if mappingMethod.declaringMapper??>${mappingMethod.declaringMapper.name?uncap_first}.${mappingMethod.name}( ${sourceBeanName}.${sourceAccessorName}() ) ); + <#-- b) simple conversion --> + <#elseif conversion != ""> + <#if sourceType.primitive == false> + if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { + ${targetBeanName}.${targetAccessorName}( ${conversion} ); + } + <#else> + ${targetBeanName}.${targetAccessorName}( ${conversion} ); + + <#-- c) simply set --> + <#else> + <#if targetType.collectionType == true> + if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { + ${targetBeanName}.${targetAccessorName}( new <#if targetType.collectionImplementationType??>${targetType.collectionImplementationType.name}<#else>${targetType.name}<#if targetType.elementType??><${targetType.elementType.name}>( ${sourceBeanName}.${sourceAccessorName}() ) ); + } + <#else> + ${targetBeanName}.${targetAccessorName}( ${sourceBeanName}.${sourceAccessorName}() ); + + +