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 2cbe4f2af..1d43483d9 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java @@ -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 getImportTypes() { + Set types = super.getImportTypes(); + + if ( conversion != null ) { + types.addAll( conversion.getImportTypes() ); + } + + return types; } } diff --git a/processor/src/main/java/org/mapstruct/ap/model/source/IterableMapping.java b/processor/src/main/java/org/mapstruct/ap/model/source/IterableMapping.java index e2cdcb460..c17e97357 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/source/IterableMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/model/source/IterableMapping.java @@ -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, diff --git a/processor/src/main/resources/org.mapstruct.ap.model.IterableMappingMethod.ftl b/processor/src/main/resources/org.mapstruct.ap.model.IterableMappingMethod.ftl index 062c0dbcb..0916185e1 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.IterableMappingMethod.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.IterableMappingMethod.ftl @@ -28,7 +28,9 @@ <#if targetType.name == "Iterable" && targetType.packageName == "java.lang">${targetType.iterableImplementationType.name}<#else>${targetType.name}<<@includeModel object=targetType.typeParameters[0]/>> ${targetType.name?uncap_first} = new <#if targetType.iterableImplementationType??>${targetType.iterableImplementationType.name}<#else>${targetType.name}<<@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 @@ } - <#else> - ${targetType.name?uncap_first}.add( <@includeModel object=elementMappingMethod input="${sourceType.typeParameters[0].name?uncap_first}"/> ); }