From 97e184888722d6464a73238560aa9ea97fe644f0 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Sun, 7 Jul 2013 16:32:57 +0200 Subject: [PATCH] #26 Template clean-up --- .../org.mapstruct.ap.model.Mapper.ftl | 3 +- ...org.mapstruct.ap.model.PropertyMapping.ftl | 40 ++++++++----------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/processor/src/main/resources/org.mapstruct.ap.model.Mapper.ftl b/processor/src/main/resources/org.mapstruct.ap.model.Mapper.ftl index 797d74cff..f2f6c9613 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.Mapper.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.Mapper.ftl @@ -32,12 +32,13 @@ import ${importedType.fullyQualifiedName}; <@includeModel object=annotation/> public class ${implementationName} implements ${interfaceName} { - <#list referencedMappers as mapper> + <@includeModel object=mapper/> <#list mappingMethods as mappingMethod> + <@includeModel object=mappingMethod/> } 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 dafa5a6bf..7d9f7bb56 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.PropertyMapping.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.PropertyMapping.ftl @@ -25,32 +25,10 @@ <#elseif conversion??> <#if sourceType.primitive == false> if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { - <#if (conversion.exceptionTypes?size == 0) > - ${targetBeanName}.${targetAccessorName}( <@includeModel object=conversion/> ); - <#else> - try { - ${targetBeanName}.${targetAccessorName}( <@includeModel object=conversion/> ); - } - <#list conversion.exceptionTypes as exceptionType> - catch( ${exceptionType.name} e ) { - throw new RuntimeException( e ); - } - - + <@applyConversion targetBeanName=targetBeanName targetAccessorName=targetAccessorName conversion=conversion/> } <#else> - <#if (conversion.exceptionTypes?size == 0) > - ${targetBeanName}.${targetAccessorName}( <@includeModel object=conversion/> ); - <#else> - try { - ${targetBeanName}.${targetAccessorName}( <@includeModel object=conversion/> ); - } - <#list conversion.exceptionTypes as exceptionType> - catch( ${exceptionType.name} e ) { - throw new RuntimeException( e ); - } - - + <@applyConversion targetBeanName=targetBeanName targetAccessorName=targetAccessorName conversion=conversion/> <#-- c) simply set --> <#else> @@ -62,3 +40,17 @@ ${targetBeanName}.${targetAccessorName}( ${sourceBeanName}.${sourceAccessorName}() ); +<#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( ${exceptionType.name} e ) { + throw new RuntimeException( e ); + } + + + \ No newline at end of file