diff --git a/processor/src/main/java/org/mapstruct/ap/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/model/common/Type.java index 6419df1e4..cfa8c505b 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/model/common/Type.java @@ -21,6 +21,7 @@ package org.mapstruct.ap.model.common; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -234,15 +235,23 @@ public class Type extends ModelElement implements Comparable { @Override public Set getImportTypes() { + Set result = new HashSet(); + + result.add( this ); + if ( implementationType != null ) { - return Collections.singleton( implementationType ); + result.addAll( implementationType.getImportTypes() ); } - else if ( componentType != null ) { - return Collections.singleton( componentType ); + + if ( componentType != null ) { + result.addAll( componentType.getImportTypes() ); } - else { - return Collections.emptySet(); + + for ( Type parameter : typeParameters ) { + result.addAll( parameter.getImportTypes() ); } + + return result; } /** @@ -495,7 +504,8 @@ public class Type extends ModelElement implements Comparable { List result = new ArrayList(); List setterMethods = getSetters(); - List getterMethods = new ArrayList( getPropertyReadAccessors().values() ); + List getterMethods = + new ArrayList( getPropertyReadAccessors().values() ); // there could be a getter method for a list/map that is not present as setter. // a getter could substitute the setter in that case and act as setter. diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java index a69e3b2e3..9b82ef783 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java @@ -18,9 +18,6 @@ */ package org.mapstruct.ap.test.collection.map; -import static org.fest.assertions.Assertions.assertThat; -import static org.fest.assertions.MapAssert.entry; - import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; @@ -28,16 +25,21 @@ import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; +import org.mapstruct.ap.test.collection.map.other.ImportedType; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.fest.assertions.Assertions.assertThat; + +import static org.fest.assertions.MapAssert.entry; + /** * Test for implementation of {@code Map} mapping methods. * * @author Gunnar Morling */ -@WithClasses({ SourceTargetMapper.class, CustomNumberMapper.class, Source.class, Target.class }) +@WithClasses({ SourceTargetMapper.class, CustomNumberMapper.class, Source.class, Target.class, ImportedType.class }) @IssueKey("44") @RunWith(AnnotationProcessorTestRunner.class) public class MapMappingTest { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/Source.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/Source.java index 2e38bebbe..e8ff64b3c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/Source.java @@ -19,11 +19,15 @@ package org.mapstruct.ap.test.collection.map; import java.util.Date; +import java.util.LinkedHashMap; import java.util.Map; +import org.mapstruct.ap.test.collection.map.other.ImportedType; + public class Source { private Map values; + private LinkedHashMap stringEnumMap; public Map getValues() { return values; @@ -32,4 +36,12 @@ public class Source { public void setValues(Map values) { this.values = values; } + + public LinkedHashMap getStringEnumMap() { + return stringEnumMap; + } + + public void setStringEnumMap(LinkedHashMap stringEnumMap) { + this.stringEnumMap = stringEnumMap; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/Target.java index 2c669e811..01b92d922 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/Target.java @@ -18,11 +18,15 @@ */ package org.mapstruct.ap.test.collection.map; +import java.util.LinkedHashMap; import java.util.Map; +import org.mapstruct.ap.test.collection.map.other.ImportedType; + public class Target { private Map values; + private LinkedHashMap stringEnumMap; public Map getValues() { return values; @@ -31,4 +35,12 @@ public class Target { public void setValues(Map values) { this.values = values; } + + public LinkedHashMap getStringEnumMap() { + return stringEnumMap; + } + + public void setStringEnumMap(LinkedHashMap stringEnumMap) { + this.stringEnumMap = stringEnumMap; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/other/ImportedType.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/other/ImportedType.java new file mode 100644 index 000000000..cc21ccef2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/other/ImportedType.java @@ -0,0 +1,28 @@ +/** + * Copyright 2012-2015 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. + */ +package org.mapstruct.ap.test.collection.map.other; + +/** + * A type that needs to be imported by the mapper implementation + * + * @author Andreas Gudian + */ +public enum ImportedType { + A, B, C; +}