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

View File

@ -34,7 +34,11 @@ public class IterableMapping {
private final AnnotationMirror mirror;
private final AnnotationValue dateFormatAnnotationValue;
public static IterableMapping fromIterableMappingPrism(IterableMappingPrism iterableMapping) {
public static IterableMapping fromPrism(IterableMappingPrism iterableMapping) {
if ( iterableMapping == null ) {
return null;
}
return new IterableMapping(
iterableMapping.dateFormat(),
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]/>>();
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) >
${targetType.name?uncap_first}.add( <@includeModel object=conversion/> );
<#else>
@ -41,8 +43,6 @@
}
</#list>
</#if>
<#else>
${targetType.name?uncap_first}.add( <@includeModel object=elementMappingMethod input="${sourceType.typeParameters[0].name?uncap_first}"/> );
</#if>
}