#44 Fixing some issues around iterable methods

This commit is contained in:
Gunnar Morling 2013-07-13 17:12:31 +02:00
parent 6e9abacdd6
commit 592371e562
3 changed files with 20 additions and 11 deletions

View File

@ -18,10 +18,11 @@
*/ */
package org.mapstruct.ap.model; package org.mapstruct.ap.model;
import java.util.Set;
/** /**
* A {@link MappingMethod} implemented by a {@link Mapper} class which maps one * A {@link MappingMethod} implemented by a {@link Mapper} class which maps one iterable type to another. The collection
* iterable type to another. The collection elements are mapped either by a * elements are mapped either by a {@link TypeConversion} or another mapping method.
* {@link TypeConversion} or another mapping method.
* *
* @author Gunnar Morling * @author Gunnar Morling
*/ */
@ -46,9 +47,13 @@ public class IterableMappingMethod extends MappingMethod {
} }
@Override @Override
public String toString() { public Set<Type> getImportTypes() {
return "MappingMethod {" + Set<Type> types = super.getImportTypes();
"\n elementMappingMethod=" + elementMappingMethod +
"\n}"; if ( conversion != null ) {
types.addAll( conversion.getImportTypes() );
}
return types;
} }
} }

View File

@ -34,7 +34,11 @@ public class IterableMapping {
private final AnnotationMirror mirror; private final AnnotationMirror mirror;
private final AnnotationValue dateFormatAnnotationValue; private final AnnotationValue dateFormatAnnotationValue;
public static IterableMapping fromIterableMappingPrism(IterableMappingPrism iterableMapping) { public static IterableMapping fromPrism(IterableMappingPrism iterableMapping) {
if ( iterableMapping == null ) {
return null;
}
return new IterableMapping( return new IterableMapping(
iterableMapping.dateFormat(), iterableMapping.dateFormat(),
iterableMapping.mirror, iterableMapping.mirror,

View File

@ -28,7 +28,9 @@
<#if targetType.name == "Iterable" && targetType.packageName == "java.lang">${targetType.iterableImplementationType.name}<#else>${targetType.name}</#if><<@includeModel object=targetType.typeParameters[0]/>> ${targetType.name?uncap_first} = new <#if targetType.iterableImplementationType??>${targetType.iterableImplementationType.name}<#else>${targetType.name}</#if><<@includeModel object=targetType.typeParameters[0]/>>(); <#if targetType.name == "Iterable" && targetType.packageName == "java.lang">${targetType.iterableImplementationType.name}<#else>${targetType.name}</#if><<@includeModel object=targetType.typeParameters[0]/>> ${targetType.name?uncap_first} = new <#if targetType.iterableImplementationType??>${targetType.iterableImplementationType.name}<#else>${targetType.name}</#if><<@includeModel object=targetType.typeParameters[0]/>>();
for ( <@includeModel object=sourceType.typeParameters[0]/> ${sourceType.typeParameters[0].name?uncap_first} : ${parameterName} ) { for ( <@includeModel object=sourceType.typeParameters[0]/> ${sourceType.typeParameters[0].name?uncap_first} : ${parameterName} ) {
<#if conversion??> <#if elementMappingMethod??>
${targetType.name?uncap_first}.add( <@includeModel object=elementMappingMethod input="${sourceType.typeParameters[0].name?uncap_first}"/> );
<#else>
<#if (conversion.exceptionTypes?size == 0) > <#if (conversion.exceptionTypes?size == 0) >
${targetType.name?uncap_first}.add( <@includeModel object=conversion/> ); ${targetType.name?uncap_first}.add( <@includeModel object=conversion/> );
<#else> <#else>
@ -41,8 +43,6 @@
} }
</#list> </#list>
</#if> </#if>
<#else>
${targetType.name?uncap_first}.add( <@includeModel object=elementMappingMethod input="${sourceType.typeParameters[0].name?uncap_first}"/> );
</#if> </#if>
} }